vgi.table_filter_pushdown
Module overview
Filter pushdown AST classes for table functions.
This module provides:
- Filter AST classes for representing pushdown filter predicates
ColumnBoundsfor extracting numeric bounds from filtersPushdownFilterscontainer with evaluation and helper methods- Deserialization from Arrow IPC format
Filter types
ConstantFilter: Comparison with a constant value (=, !=, >, >=, <, <=)
IsNullFilter: IS NULL check
IsNotNullFilter: IS NOT NULL check
InFilter: Set membership (IN clause)
AndFilter: Conjunction of child filters
OrFilter: Disjunction of child filters
StructFilter: Nested struct field filter
class AndFilter
Section titled “class AndFilter”Bases: Filter
Description
Conjunction of child filters.
All child filters must pass for a row to pass.
Attributes
attribute children
Section titled “attribute children”tuple[Filter, …]
The child filters that are ANDed together.
Methods
method evaluate
Section titled “method evaluate”evaluate(batch: pa.RecordBatch) -> pa.BooleanArrayEvaluate AND of all child filters.
class ColumnBounds
Section titled “class ColumnBounds”Description
Numeric/comparable bounds for a column extracted from filters.
Use case: Partition pruning, index range scans, bounded data fetches.
Attributes
attribute min_value
Section titled “attribute min_value”Minimum bound value, or None if unbounded below.
attribute min_inclusive
Section titled “attribute min_inclusive”bool
True if min_value is inclusive (>=), False if exclusive (>).
attribute max_value
Section titled “attribute max_value”Maximum bound value, or None if unbounded above.
attribute max_inclusive
Section titled “attribute max_inclusive”bool
True if max_value is inclusive (<=), False if exclusive (<).
Methods
method contains
Section titled “method contains”contains(value: Any) -> boolCheck if a value satisfies these bounds.
class ColumnRefNode
Section titled “class ColumnRefNode”Bases: ExpressionNode
Description
Column reference node.
Note: In v1, all column refs in an expression filter refer to the same column (the filter column). The index is stored for future multi-column support but to_sql() always uses the filter’s column_name.
Attributes
attribute index
Section titled “attribute index”int
Column position; reserved for future multi-column support.
Methods
method to_sql
Section titled “method to_sql”to_sql(column_name: str) -> strReturn quoted column name with double-quote escaping.
Inherited members (1)
expr_typeattribute · from ExpressionNode
class ComparisonNode
Section titled “class ComparisonNode”Bases: ExpressionNode
Description
Comparison node (left op right).
Attributes
Methods
method to_sql
Section titled “method to_sql”to_sql(column_name: str) -> strFormat as (left op right).
Inherited members (1)
expr_typeattribute · from ExpressionNode
class ComparisonOp
Section titled “class ComparisonOp”Bases: Enum
Description
Comparison operators for constant filters.
Attributes
class ConjunctionNode
Section titled “class ConjunctionNode”Bases: ExpressionNode
Description
AND/OR conjunction node.
Attributes
attribute conjunction_type
Section titled “attribute conjunction_type”str
Either "and" or "or", selecting how the
children combine.
attribute children
Section titled “attribute children”tuple[ExpressionNode, …]
The child expression nodes being combined.
Methods
method to_sql
Section titled “method to_sql”to_sql(column_name: str) -> strFormat as (child1 AND/OR child2 AND/OR …).
Inherited members (1)
expr_typeattribute · from ExpressionNode
class ConstantFilter
Section titled “class ConstantFilter”Bases: Filter
Description
Comparison filter: column <op> value.
Attributes
attribute op
Section titled “attribute op”The comparison operator applied between the column and value.
Methods
method evaluate
Section titled “method evaluate”evaluate(batch: pa.RecordBatch) -> pa.BooleanArrayEvaluate comparison against batch column.
class ConstantNode
Section titled “class ConstantNode”Bases: ExpressionNode
Description
Constant value node.
Attributes
attribute field
Section titled “attribute field”Arrow field carrying extension metadata for value (if
available), used to render extension types correctly in SQL.
Methods
method to_sql
Section titled “method to_sql”to_sql(column_name: str) -> strFormat Arrow scalar as SQL literal, using field metadata for extension types.
Inherited members (1)
expr_typeattribute · from ExpressionNode
function deserialize_filters
Section titled “function deserialize_filters”deserialize_filters(
batch: pa.RecordBatch,
join_keys: list[pa.RecordBatch] | None = None,
) -> PushdownFilters
Deserialize Arrow IPC bytes to typed AST.
class ExpressionFilter
Section titled “class ExpressionFilter”Bases: Filter
Description
Expression tree filter pushed from DuckDB.
Contains a recursive expression tree that the worker evaluates
using DuckDB. Typical use: spatial predicates like geom && box.
Attributes
Methods
method evaluate
Section titled “method evaluate”evaluate(batch: pa.RecordBatch) -> pa.BooleanArrayEvaluate expression tree against batch using DuckDB.
Uses a cached per-process DuckDB connection with spatial extension
pre-loaded (if available). The engine is imported lazily via
:mod:vgi._duckdb (haybarn preferred, duckdb fallback) — workers
that don’t use expression filters don’t need either installed.
class ExpressionNode
Section titled “class ExpressionNode”Description
Base class for expression tree nodes.
Subclasses must set expr_type to match their class. This field
is used for serialization round-tripping (JSON expr_type key).
Attributes
attribute expr_type
Section titled “attribute expr_type”Discriminator identifying the concrete node kind.
Methods
method to_sql
Section titled “method to_sql”to_sql(column_name: str) -> strConvert node to SQL string. Override in subclasses.
class ExpressionNodeType
Section titled “class ExpressionNodeType”Bases: Enum
Description
Expression node type identifiers matching the JSON protocol.
Attributes
attribute COLUMN_REF
Section titled “attribute COLUMN_REF”Reference to a column in the filtered table.
class Filter
Section titled “class Filter”Description
Base class for all filter types.
Attributes
attribute column_name
Section titled “attribute column_name”str
Name of the column this filter applies to.
attribute column_index
Section titled “attribute column_index”int
Index of the column in the output schema.
Methods
method evaluate
Section titled “method evaluate”evaluate(batch: pa.RecordBatch) -> pa.BooleanArrayEvaluate filter against batch using PyArrow compute.
class FilterDeserializationError
Section titled “class FilterDeserializationError”Bases: FilterError
Description
Failed to parse filter IPC bytes.
class FilterError
Section titled “class FilterError”Bases: Exception
Description
Base exception for filter pushdown errors.
class FilterType
Section titled “class FilterType”Bases: Enum
Description
Filter type identifiers matching the JSON protocol.
Attributes
attribute CONSTANT
Section titled “attribute CONSTANT”Comparison against a constant value (=, !=, <, …).
attribute JOIN_KEYS
Section titled “attribute JOIN_KEYS”Membership against join-key values pushed as a separate batch.
attribute EXPRESSION
Section titled “attribute EXPRESSION”Arbitrary expression tree evaluated by DuckDB.
class FilterVersionError
Section titled “class FilterVersionError”Bases: FilterError
Description
Unsupported filter protocol version.
class FunctionNode
Section titled “class FunctionNode”Bases: ExpressionNode
Description
Function call node.
Attributes
attribute function_name
Section titled “attribute function_name”str
Name of the function or infix operator to invoke.
attribute children
Section titled “attribute children”tuple[ExpressionNode, …]
The argument expression nodes.
Methods
method to_sql
Section titled “method to_sql”to_sql(column_name: str) -> strFormat as function_name(args…) or infix for operators like &&.
Inherited members (1)
expr_typeattribute · from ExpressionNode
class InFilter
Section titled “class InFilter”Bases: Filter
Description
IN (v1, v2, …) set membership filter.
Attributes
attribute values
Section titled “attribute values”The candidate values as an Arrow array (the contents of the list column); a row passes if its column value is in this set.
Methods
method evaluate
Section titled “method evaluate”evaluate(batch: pa.RecordBatch) -> pa.BooleanArrayEvaluate IN membership against batch column.
class IsNotNullFilter
Section titled “class IsNotNullFilter”Bases: Filter
Description
IS NOT NULL check filter.
Methods
method evaluate
Section titled “method evaluate”evaluate(batch: pa.RecordBatch) -> pa.BooleanArrayEvaluate IS NOT NULL check against batch column.
class IsNullFilter
Section titled “class IsNullFilter”Bases: Filter
Description
IS NULL check filter.
Methods
method evaluate
Section titled “method evaluate”evaluate(batch: pa.RecordBatch) -> pa.BooleanArrayEvaluate IS NULL check against batch column.
class OrFilter
Section titled “class OrFilter”Bases: Filter
Description
Disjunction of child filters.
At least one child filter must pass for a row to pass.
Attributes
attribute children
Section titled “attribute children”tuple[Filter, …]
The child filters that are ORed together.
Methods
method evaluate
Section titled “method evaluate”evaluate(batch: pa.RecordBatch) -> pa.BooleanArrayEvaluate OR of all child filters.
class PushdownFilters
Section titled “class PushdownFilters”Description
Container for pushdown filters with evaluation and query helpers.
The top-level filters array represents a conjunction (AND). Each filter in the array must be satisfied for a row to pass. Individual filters may themselves be AND/OR compound filters for more complex expressions.
Provides:
- evaluate(batch) / apply(batch) - Apply filters using PyArrow compute
- get_column_bounds(name) - Extract numeric bounds for partition pruning
- get_column_constant(name) - Get equality constant for a column
- get_column_in_values(name) - Get IN list values
- get_column_filters(name) - Get all filters for a column
- to_sql() - Generate SQL WHERE clause
Attributes
attribute filters
Section titled “attribute filters”tuple[Filter, …]
The top-level filters, combined with AND.
attribute version
Section titled “attribute version”str
Filter protocol version the filters were deserialized from.
attribute join_keys_batches
Section titled “attribute join_keys_batches”list[pa.RecordBatch] | None
Optional single-column batches of join-key values, one per IN/join-keys filter column, or None when none were pushed.
attribute filtered_columns
Section titled “attribute filtered_columns”frozenset[str]
Set of column names that have filters applied.
Use case: Quick check of which columns are constrained.
Methods
method get_join_keys_batch
Section titled “method get_join_keys_batch”get_join_keys_batch() -> pa.RecordBatch | NoneReturn a merged join keys batch for temp table registration.
When all join key batches have the same row count (the semi-join
case), returns a single RecordBatch with all columns merged.
When batches have different row counts (independent IN filters),
they cannot be merged, so this returns None.
For individual column access, use :meth:get_join_keys_batches
or :meth:get_column_in_values.
Example:
keys = params.current_pushdown_filters.get_join_keys_batch()if keys is not None: conn.register("join_keys", keys) result = conn.sql( "SELECT d.* FROM my_data d JOIN join_keys USING (id)" )method get_join_keys_batches
Section titled “method get_join_keys_batches”get_join_keys_batches() -> list[pa.RecordBatch] | NoneReturn all join key batches (one per IN filter column).
Each batch is a single-column RecordBatch. Different batches may have
different row counts. Returns None if no join keys were pushed.
method evaluate
Section titled “method evaluate”evaluate(batch: pa.RecordBatch) -> pa.BooleanArrayEvaluate all filters, returning boolean mask.
Filters are combined with AND at the top level - a row passes only if ALL filters evaluate to true for that row.
method apply
Section titled “method apply”apply(batch: pa.RecordBatch) -> pa.RecordBatchApply all filters to batch, returning filtered batch.
method get_column_filters
Section titled “method get_column_filters”get_column_filters(column_name: str) -> list[Filter]Get all top-level filters for a specific column.
Use case: Inspect what constraints apply to a column.
method has_filter_for_column
Section titled “method has_filter_for_column”has_filter_for_column(column_name: str) -> boolCheck if any filter constrains the given column.
method get_column_constant
Section titled “method get_column_constant”get_column_constant(column_name: str) -> pa.Scalar[Any] | NoneGet constant value if column has an equality filter.
Use case: Partition key lookup, exact match optimization.
method get_column_in_values
Section titled “method get_column_in_values”get_column_in_values(column_name: str) -> pa.Array[Any] | NoneGet IN list values if column has an IN filter.
Use case: Multi-key lookup, batch fetching.
method get_column_values
Section titled “method get_column_values”get_column_values(column_name: str) -> pa.Array[Any] | NoneGet all distinct values a column could have based on filters.
Returns values from equality (=) or IN filters as an Arrow array. Useful for partition pruning when partitions are keyed by specific values.
Use case: Partition key lookup, directory-based partitioning.
method get_column_bounds
Section titled “method get_column_bounds”get_column_bounds(column_name: str) -> ColumnBounds | NoneExtract numeric bounds from comparison filters.
Analyzes gt/ge/lt/le filters to determine value range.
Use case: Range scans, partition pruning, bounded iteration.
method to_sql
Section titled “method to_sql”to_sql(
quote_identifier: Callable[[str], str] | None = None,
placeholder: str = ‘?’,
) -> tuple[str, list[Any]]Convert filters to SQL WHERE clause with parameters.
method empty
Section titled “method empty”empty() -> PushdownFiltersCreate an empty PushdownFilters instance (no filters).
class StructFilter
Section titled “class StructFilter”Bases: Filter
Description
Nested struct field filter.
Filters on a nested field within a struct column. Example: address.city = ‘Seattle’
Attributes
attribute child_index
Section titled “attribute child_index”int
Position of the nested field within the struct column.
attribute child_name
Section titled “attribute child_name”str
Name of the nested field within the struct column.
attribute child_filter
Section titled “attribute child_filter”The filter applied to the nested field’s values.
Methods
method evaluate
Section titled “method evaluate”evaluate(batch: pa.RecordBatch) -> pa.BooleanArrayEvaluate filter on nested struct field.