Skip to content

Commit 63a66d6

Browse files
Merge pull request #25 from OpenStatSpec/cleanup/remove-dead-ddl-branches
cleanup: remove unreachable view execution branch
2 parents 37658e4 + 360df9e commit 63a66d6

1 file changed

Lines changed: 41 additions & 65 deletions

File tree

‎src/openstatspec/sql/workflow.py‎

Lines changed: 41 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -2053,72 +2053,48 @@ def execute_transformation(
20532053
preflight(profile, variables)
20542054
row_count = 0
20552055
phase = "staging"
2056-
if output_mode == "materialized":
2057-
relation = Table(
2058-
staging_name, MetaData(),
2059-
Column("__row_ordinal", BigInteger, primary_key=True, nullable=False),
2060-
*(Column(
2061-
item["physical_name"],
2062-
binary64_type() if item["storage_kind"] == "numeric" else Text(),
2063-
nullable=item["is_nullable"],
2064-
) for item in schema),
2065-
)
2066-
relation.create(connection)
2067-
with _sqlite_read_authorizer(connection, parent_reads):
2068-
query_result = connection.exec_driver_sql(
2069-
full_query, values,
2070-
execution_options={"stream_results": True},
2071-
)
2072-
while True:
2073-
chunk = query_result.fetchmany(1000)
2074-
if not chunk:
2075-
break
2076-
rows = []
2077-
for raw in chunk:
2078-
row_count += 1
2079-
output = {"__row_ordinal": row_count}
2080-
for item, value in zip(schema, tuple(raw)):
2081-
if value is not None:
2082-
value = float(value) if item["storage_kind"] == "numeric" else str(value)
2083-
output[item["physical_name"]] = value
2084-
rows.append(output)
2085-
connection.execute(insert(relation), rows)
2086-
relation_query = (
2087-
f"SELECT {', '.join(quote(item['physical_name']) for item in schema)} "
2088-
f"FROM {quote(staging_name)}"
2089-
)
2090-
_validate_order_key(
2091-
connection, relation_query, order_descriptors, {}, {("main", staging_name)}
2092-
)
2093-
connection.exec_driver_sql(
2094-
f"ALTER TABLE {quote(staging_name)} RENAME TO {quote(relation_name)}"
2095-
)
2096-
_create_derived_triggers(
2097-
connection, derived_id, relation_name
2098-
)
2099-
else:
2100-
projected = ", ".join(
2101-
f"q.{quote(item['name'])} AS {quote(item['physical_name'])}"
2102-
for item in schema
2103-
)
2104-
window_order = ", ".join(
2105-
(
2106-
f"q.{quote(item['expression'])}"
2107-
+ (f" COLLATE {item['collation']}" if item["collation"] else "")
2108-
+ f" {item['direction'].upper()} NULLS {item['nulls'].upper()}"
2109-
)
2110-
for item in order_descriptors
2111-
)
2112-
view_sql = (
2113-
f"CREATE VIEW {quote(relation_name)} AS "
2114-
f"SELECT ROW_NUMBER() OVER (ORDER BY {window_order}) "
2115-
f"AS {quote('__row_ordinal')}, {projected} "
2116-
f"FROM ({full_query}) q"
2056+
relation = Table(
2057+
staging_name, MetaData(),
2058+
Column("__row_ordinal", BigInteger, primary_key=True, nullable=False),
2059+
*(Column(
2060+
item["physical_name"],
2061+
binary64_type() if item["storage_kind"] == "numeric" else Text(),
2062+
nullable=item["is_nullable"],
2063+
) for item in schema),
2064+
)
2065+
relation.create(connection)
2066+
with _sqlite_read_authorizer(connection, parent_reads):
2067+
query_result = connection.exec_driver_sql(
2068+
full_query, values,
2069+
execution_options={"stream_results": True},
21172070
)
2118-
connection.exec_driver_sql(view_sql)
2119-
row_count = int(connection.execute(
2120-
text(f"SELECT COUNT(*) FROM {quote(relation_name)}")
2121-
).scalar_one())
2071+
while True:
2072+
chunk = query_result.fetchmany(1000)
2073+
if not chunk:
2074+
break
2075+
rows = []
2076+
for raw in chunk:
2077+
row_count += 1
2078+
output = {"__row_ordinal": row_count}
2079+
for item, value in zip(schema, tuple(raw)):
2080+
if value is not None:
2081+
value = float(value) if item["storage_kind"] == "numeric" else str(value)
2082+
output[item["physical_name"]] = value
2083+
rows.append(output)
2084+
connection.execute(insert(relation), rows)
2085+
relation_query = (
2086+
f"SELECT {', '.join(quote(item['physical_name']) for item in schema)} "
2087+
f"FROM {quote(staging_name)}"
2088+
)
2089+
_validate_order_key(
2090+
connection, relation_query, order_descriptors, {}, {("main", staging_name)}
2091+
)
2092+
connection.exec_driver_sql(
2093+
f"ALTER TABLE {quote(staging_name)} RENAME TO {quote(relation_name)}"
2094+
)
2095+
_create_derived_triggers(
2096+
connection, derived_id, relation_name
2097+
)
21222098
phase = "publication_validation"
21232099
content_hash = _relation_snapshot_hash(
21242100
connection, relation_schema=None, relation_name=relation_name,

0 commit comments

Comments
 (0)