Skip to main content

fused.table

delete_index​

delete_index(path: str, *, base_url: str | None = None) -> pd.DataFrame

Delete the index of path. The table's own files are untouched, and fused.table.query on path fails until it is indexed again.

Parameters:

  • path (str) – The folder given to fused.table.index.
  • base_url (str | None) – Base URL for the API. If None, uses the current environment.

Returns:

  • DataFrame – A one-row DataFrame with path and deleted, the number of index files removed (0 when there was no index).

index​

index(
path: str,
*,
columns: list[str] | None = None,
bbox: str | list[str] | None = "auto",
redo: bool = False,
engine: InstanceType | Literal["realtime"] = "realtime",
base_url: str | None = None
) -> TaskRun[Any]

Index a folder of parquet files so fused.table.query can read it.

Starts a server-side run that reads the footers of the parquet files under path and records where each row group lies and what it holds, then returns as soon as the run has started; follow it with run.tail() or fused.table.index_status. The index belongs to your team and is found from path alone. Each team keeps one index per path.

Running it again is incremental: files unchanged since the last run are not read again.

Parameters:

  • path (str) – Folder of parquet files, e.g. s3://my-bucket/my-table/. Files whose name starts with _ or . are skipped.
  • columns (list[str] | None) – Columns to record value ranges for, so that filters on them can skip row groups. Defaults to none.
  • bbox (str | list[str] | None) – How to find each row's bounding box. "auto" uses the table's GeoParquet bounding-box column when it has one. Give the four column names [xmin, ymin, xmax, ymax] to use those columns, or None to index without boxes.
  • redo (bool) – Read every file again instead of reusing unchanged ones.
  • engine (InstanceType | Literal['realtime']) – "realtime", or a batch instance type such as "medium" for a large folder.
  • base_url (str | None) – Base URL for the API. If None, uses the current environment.

Returns:

  • TaskRun[Any] – The run that is building the index. run.wait().result() is a one-row DataFrame summarizing the build: path, generation, files, row_groups, rows, reused_files, index_bytes and seconds.

Example:

run = fused.table.index("s3://my-bucket/my-table/")
run.tail()
gdf = fused.table.query("s3://my-bucket/my-table/", (-122.5, 37.5, -122, 38))

index_status​

index_status(path: str, *, base_url: str | None = None) -> pd.DataFrame

Describe the index of path.

Parameters:

  • path (str) – The folder given to fused.table.index.
  • base_url (str | None) – Base URL for the API. If None, uses the current environment.

Returns:

  • DataFrame – A one-row DataFrame with path (the location the index is kept under, which can differ from the path passed: an fd:// path comes back resolved), status ("indexing" while a run is in progress, else "ready"), indexing (True while a run is in progress), job_id (the id of the run in progress; None when there is none), generation (which build of the index is live), files, row_groups and rows (what it covers), bbox_columns (the columns the boxes come from, or None), columns (the columns with recorded value ranges) and last_run_finished_at (when the live build was written). While the first run of a path is in progress, the fields describing the index are None. The DataFrame is empty, with the same columns, when there is neither an index nor a run in progress for path.

query​

query(
path: str,
bbox: Union[Tuple[float, float, float, float], Any, None] = None,
*,
filters: Optional[Iterable[Sequence[Any]]] = None,
columns: Optional[Iterable[str]] = None,
sql: Optional[str] = None,
clip: bool = False,
index: Optional[str] = None,
subpath: Optional[str] = None,
return_timings: bool = False
) -> Union[pd.DataFrame, Tuple[pd.DataFrame, dict[str, int]]]

Read the rows of a table that fall inside a bounding box and meet filters.

The table must have been indexed with fused.table.index. A row is returned when its bounding box intersects bbox, and its geometry is returned whole, even where it extends past the box. Without bbox, every row that meets filters is returned.

Parameters:

  • path (str) – URL of the table, e.g. s3://my-bucket/my-table/.
  • bbox (Union[Tuple[float, float, float, float], Any, None]) – (min_lng, min_lat, max_lng, max_lat) in EPSG:4326, or any object with bounds or total_bounds, such as a shapely geometry, a GeoSeries or a GeoDataFrame. Optional.
  • filters (Optional[Iterable[Sequence[Any]]]) – Conditions every returned row meets, as [column, op, value] lists, where op is one of ==, =, !=, <, <=, >, >=, in or not in (which take a list). A column may be a dotted path into a struct column. Filter columns need not be in columns.
  • columns (Optional[Iterable[str]]) – Read only these columns. The geometry column is returned only if listed. A dotted path returns its whole top-level column.
  • sql (Optional[str]) – A DuckDB SQL query to run over the matching rows, which are available as the table df. The geometry column is a WKB blob.
  • clip (bool) – Cut geometries that cross the box at its edge, like geopandas.clip, and drop rows left without geometry. Requires bbox and a geometry column.
  • index (Optional[str]) – Location of an index you keep yourself, such as a folder in your own bucket, to read instead of the one fused.table.index builds.
  • subpath (Optional[str]) – Read only the table's files whose path relative to path starts with this text, e.g. "2022/". It is a plain string prefix, so "2022" also matches "2022-old/...". It must be relative, not a URL or a path starting with /. A subpath that matches no file returns an empty result.
  • return_timings (bool) – Also return how long each step of the query took.

Returns:

  • Union[DataFrame, Tuple[DataFrame, dict[str, int]]] – A GeoDataFrame in EPSG:4326 when the result has a geometry column, otherwise a DataFrame. Empty when no row is inside the box. With return_timings, a tuple of that frame and a dict mapping each step to its milliseconds (cold is 0 or 1).

Examples:

gdf = fused.table.query("s3://my-bucket/my-table/", (-122.5, 37.5, -122, 38))
n = fused.table.query(
"s3://my-bucket/my-table/",
(-122.5, 37.5, -122, 38),
sql="SELECT count(*) AS n FROM df",
)