Re:Show HN: Hashquery, a Python library for defining reusabl...
by tomrod on Tuesday April 23, 2024 @01:00PM
(#40134202)
How aware is the library regarding existing structure, e.g foreign key relationships?
[ Parent
| on HN ]
Re:Show HN: Hashquery, a Python library for defining reusabl...
by cpimhoff on Tuesday April 23, 2024 @02:35PM
(#40135486)
The library itself provides tools for declaring data tables, columns, metrics, and relationships, then performing transformations (eg. queries) on top of them.
Reflecting an existing database isn't part of the library, but with the magic of "it's just Python" it's pretty easy to write a function that does so yourself:
import hashquery as hq
def reflect_db(url: str) -> list[hq.Model]:
"""
Given a connection string,
returns a list of Hashquery models
for all the physical tables in
the database.
"""
models: list[hq.Model] = []
reflection = some_reflection_lib.reflect_db(url)
for table in reflection.tables:
models.append(
hq.Model()
.with_source(url, table.name, table.schema)
.with_attributes(*table.column_names)
)
# ...more logic for importing foreign keys or whatever else
return models
Re:Show HN: Hashquery, a Python library for defining reusabl...
by vndrewlee on Tuesday April 23, 2024 @02:38PM
(#40135540)
Joining logic is defined in our data modeling layer, either from Hashboard (our BI tool) or can also be defined in Hashquery as well instead of replying on your database schema for fk relationships. We went this route since a lot of people are using dbt generated tables.