GCSSrc
class GCSSrc(
paths: SrcPathsSpec,
format: SrcFileFormat = SrcFileFormat.AUTO,
format_cfg: SrcFormatCfgSpec | None = None,
initial_last_modified: datetime | None = None,
src_cfg: SrcCfgSpec | None = None,
purge: bool = False,
include_compressed: bool = False,
)
Bases: Src
Categories: source
GCS source for @publisher -- one output slot per path.
Every table this source publishes automatically carries a
@td.file.path metadata column: the gs:// object URI the row was read
from. A path that globs several files reports the specific file
each row came from, and a worksheet read from a workbook keeps its
#<n> fragment, so the value can be pasted straight back into
paths. Setting the src_cfg key tabsdata.src_metadata.drop to
True leaves the column off.
Examples
Read a single object, selecting the CSV format explicitly:
@publisher(
source=GCSSrc(paths=["export.csv"], format=SrcFileFormat.CSV),
output_tables=["rows"],
)
def ingest(rows: TableFramesSpec) -> TableFrameSpec:
return rows[0] if rows else None
Incremental read: only objects modified at or after the cutoff are imported, and the cutoff advances each run:
@publisher(
source=GCSSrc(
paths=["parquet/orders.parquet"],
initial_last_modified=datetime(2024, 1, 1, tzinfo=timezone.utc),
),
output_tables=["orders"],
)
def ingest_new(orders: TableFramesSpec) -> TableFrameSpec:
return orders[0] if orders else None
Parameters
Source paths relative to the connection's base_path,
one output slot per entry. Each path is relative (no
leading /), must not end with /, and must not contain
empty segments (//). A path may use a * glob in its
final segment only; backslashes, NUL and ${...} tokens
are not allowed. An .xlsx path may end with #<n> to name
the worksheet -- 1-based over every sheet the workbook
declares, hidden ones included. Two paths may name different
sheets of one workbook, giving a slot each.
formatSrcFileFormatFile format, by extension:
AUTO(the default): taken from each file's extension, the one before a compression or archive extension if it ends in one (a.json.gzanda.json.zipareJSON). Every file a source takes must resolve to the same format, and a file whose extension names none (a.b.zip) fails the run. Any other format reads every file as that format, whatever its name.AVRO:.avro.CSV:.csv.EXCEL:.xlsx; one worksheet, named by the path's#<n>fragment.JSON:.json,.jsonl,.ndjson; one JSON object per line.LOG:.log; one row per line.PARQUET:.parquet,.pq.
format_cfgSrcFormatCfgSpec | None (dict[SrcFileFormat, dict[Literal['separator', 'quote_char', 'eol_char', 'encoding', 'null_values', 'missing_is_null', 'truncate_ragged_lines', 'comment_prefix', 'try_parse_dates', 'decimal_comma', 'has_header', 'skip_lines', 'skip_rows', 'skip_rows_after_header', 'raise_if_empty', 'ignore_errors'], Any] | dict[ExcelSrcKey, Any] | dict[EbcdicSrcKey, Any] | dict] | None)Optional per-format reader options (source-side
keys only), keyed by the SrcFileFormat. EXCEL takes
has_header (default True); with False the first row is
data and the columns are named column_1, column_2, ...
initial_last_modifieddatetime | NoneOptional cutoff for incremental ingestion. The first run imports only files modified at or after this timestamp; the cutoff then advances each run so only newer files are re-imported.
src_cfgSrcCfgSpec | None (Mapping[Literal['tabsdata.file.chunk_size', 'tabsdata.src_metadata.drop'], Any] | None)Optional connector config; supported keys are
tabsdata.file.chunk_size and
tabsdata.src_metadata.drop.
purgeboolDelete each source file that is older than the incremental
initial_last_modified cursor. Files
older than the original initial_last_modified timestamp set at
registration time are never deleted -- they
were never read. Only valid when initial_last_modified is set; the default
is False.
include_compressedboolAlso take compressed files and archives. A
path takes a file whose name matches it plus one compression or
archive extension (data/*.json takes a.json.gz, not
a.json.csv), and a file whose name ends in one only when this
is True; a path that itself ends in one requires it. The
extension alone names the codec or the archive, and the name
before it the format:
.br: Brotli..bz2: bzip2..gz: gzip..lz4: LZ4 frame..tar: a tar archive holding exactly one file..xz: XZ..zip: a zip archive holding exactly one file..zlib: zlib..zst,.zstd: Zstandard.
A file has at most one of these extensions: an archive inside a
compressed file (a.csv.tar.gz) is not read. Defaults to
False.
Methods
validatedef validate()
Cross-field validation of format, paths and format_cfg
(source side).
Called by the framework; raises GCSValidateException on
failure.