Skip to content

Commit

Permalink
in flight view work
Browse files Browse the repository at this point in the history
  • Loading branch information
bailliekova committed Jan 23, 2025
1 parent ec8cded commit 4d88065
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions gerrydb_meta/crud/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,40 @@ def render(self, db: Session, *, view: models.View) -> ViewRenderContext:
),
)

def _agg_select(col)->str:
select_str=f"""
MAX(case when col_id = {col.col_id} then {COLUMN_TYPE_TO_VALUE_COLUMN[col.type]} else null) as {col.canonical_ref.path}
"""
return select_str

def _column_sub(cols, geoids, view_at,)-> str:
COLUMN_VALUE_TABLE_NAME = "column_value"

agg_selects=[]
for col in cols:
agg_selects.append(
f"""
MAX(case when col_id = {col.col_id} then {COLUMN_TYPE_TO_VALUE_COLUMN[col.type]} else null) as {col.canonical_ref.path}
"""
)



subquery= f"""
SELECT
geoid,
{",\n".join([_agg_select(col) for col in cols])
}
FROM {COLUMN_VALUE_TABLE_NAME}
WHERE column_id in ({",".join([col.id for col in cols])})
AND valid_from <= {view_at}
AND (valid_to is NONE OR valid_to >= {view_at})
"""

return subquery

def _geo_meta(
self, db: Session, view: models.View
) -> tuple[dict[str, int], dict[int, models.ObjectMeta]]:
Expand Down

0 comments on commit 4d88065

Please sign in to comment.