Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions airtabledb/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@
from pyairtable import Table
from shillelagh.adapters.base import Adapter
from shillelagh.fields import Field, ISODate, ISODateTime, Order, String
from shillelagh.filters import Equal, Filter, IsNotNull, IsNull, NotEqual, Range
from shillelagh.filters import (
Equal,
Filter,
IsNotNull,
IsNull,
NotEqual,
Operator,
Range,
)
from shillelagh.typing import RequestedOrder

from .fields import MaybeList, MaybeListString
Expand All @@ -33,7 +41,7 @@ class FieldKwargs(TypedDict, total=False):

FIELD_KWARGS: FieldKwargs = {
"order": Order.ANY,
"filters": [IsNull, IsNotNull, Range, Equal, NotEqual],
"filters": [IsNull, IsNotNull, Equal, NotEqual, Range],
"exact": True,
}

Expand Down Expand Up @@ -179,3 +187,22 @@ def get_data(
id=result["id"],
createdTime=result["createdTime"],
)

def get_cost(
self,
filtered_columns: List[Tuple[str, Operator]],
order: List[Tuple[str, RequestedOrder]],
) -> int:
# Most of the cost here will come from network fetching / overhead

if ("id", Operator.EQ) in filtered_columns:
# We assume if it's = id, then there will be 0/1 result
return 100
elif any(operator is Operator.EQ for field_name, operator in filtered_columns):
# We assume if it's = something else, it might be 0/1 or it might be more
return 110
elif len(filtered_columns) > 0:
# Give some benefit for reduced data to fetch
return 150
else:
return 200