Skip to content

Commit 40520f7

Browse files
authored
Merge pull request #674 from splitgraph/bugfix/fix-socrata-data-source
Fix Socrata previews returning null
2 parents d1e74d6 + a5f4e47 commit 40520f7

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

splitgraph/hooks/data_source/fdw.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,10 @@ def _preview_table(self, schema: str, table: str, limit: int = 10) -> List[Dict[
235235
result_json = cast(
236236
List[Dict[str, Any]],
237237
self.engine.run_sql(
238-
SQL("SELECT row_to_json(t.*) FROM {}.{} t LIMIT %s").format(
239-
Identifier(schema), Identifier(table)
240-
),
238+
SQL(
239+
"WITH p AS MATERIALIZED(SELECT * FROM {}.{} LIMIT %s) "
240+
"SELECT row_to_json(p.*) FROM p"
241+
).format(Identifier(schema), Identifier(table)),
241242
(limit,),
242243
return_shape=ResultShape.MANY_ONE,
243244
),

test/splitgraph/ingestion/test_socrata.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,3 +423,7 @@ def test_socrata_data_source_introspection_smoke(local_engine_empty):
423423
schema, params = result["some_table"]
424424
assert len(schema) > 1
425425
assert params == {"socrata_id": "8wbx-tsch"}
426+
427+
preview_result = data_source.preview(tables=result)
428+
assert len(preview_result["some_table"]) == 10
429+
assert preview_result["some_table"][0][":id"] is not None

0 commit comments

Comments
 (0)