Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,9 @@ def validate(self, config: RepoConfig):

def get_table_query_string(self) -> str:
"""Returns a string that can directly be used to reference this table in SQL"""
return self.table or self.query
if self.table:
return self.table
return f"({self.query})"

@staticmethod
def source_datatype_to_feast_value_type() -> Callable[[str], ValueType]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,40 @@ def test_trino_read_node_generates_sql(self):
assert "TIMESTAMP '2025-01-02 00:00:00.000000'" in sql
assert "FROM iceberg.feast.driver_stats" in sql

def test_trino_read_node_with_query_source_generates_parenthesized_sql(self):
from feast.infra.offline_stores.contrib.trino_offline_store.trino_source import (
TrinoSource,
)

source = TrinoSource(
name="user_source",
query="SELECT user_id, event_timestamp, val FROM catalog.schema.table",
timestamp_field="event_timestamp",
)

col_info = ColumnInfo(
join_keys=["user_id"],
feature_cols=["val"],
ts_col="event_timestamp",
created_ts_col=None,
)

node = TrinoReadNode(
name="test_query_read",
source=source,
column_info=col_info,
client=MagicMock(),
)

val = node.execute(MagicMock())
plan: TrinoQueryPlan = val.data
sql = plan.to_sql()

assert (
"FROM (SELECT user_id, event_timestamp, val FROM catalog.schema.table)"
in sql
)

def test_trino_filter_node_generates_sql(self):
plan = TrinoQueryPlan(
ctes=[("_source", 'SELECT * FROM "iceberg"."feast"."driver_stats"')],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from feast.infra.offline_stores.contrib.trino_offline_store.trino_source import (
TrinoSource,
)


def test_trino_source_get_table_query_string_with_table():
source = TrinoSource(
table="my_catalog.my_schema.my_table",
timestamp_field="event_timestamp",
)
assert source.get_table_query_string() == "my_catalog.my_schema.my_table"


def test_trino_source_get_table_query_string_with_query():
query = "SELECT user_id, event_timestamp, val FROM catalog.schema.table"
source = TrinoSource(
name="user_source",
query=query,
timestamp_field="event_timestamp",
)
assert source.get_table_query_string() == f"({query})"


def test_trino_source_proto_roundtrip_query():
query = "SELECT user_id, event_timestamp, val FROM catalog.schema.table"
source = TrinoSource(
name="user_source",
query=query,
timestamp_field="event_timestamp",
)
proto = source.to_proto()
deserialized = TrinoSource.from_proto(proto)

assert deserialized.name == source.name
assert deserialized.query == source.query
assert deserialized.get_table_query_string() == f"({query})"


def test_trino_source_proto_roundtrip_table():
source = TrinoSource(
table="my_catalog.my_schema.my_table",
timestamp_field="event_timestamp",
)
proto = source.to_proto()
deserialized = TrinoSource.from_proto(proto)

assert deserialized.name == source.name
assert deserialized.table == source.table
assert deserialized.get_table_query_string() == "my_catalog.my_schema.my_table"
Loading