Skip to content

Commit 91a3fb7

Browse files
luis-dkclaude
andcommitted
fix(profiling): tolerate NULL max_query_chars in row-count chunking
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 4ba412a commit 91a3fb7

3 files changed

Lines changed: 21 additions & 2 deletions

File tree

testgen/commands/queries/refresh_data_chars_query.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from testgen.common import read_template_sql_file
66
from testgen.common.database.column_chars import ColumnChars
77
from testgen.common.database.database_service import get_flavor_service, replace_params
8-
from testgen.common.models.connection import Connection
8+
from testgen.common.models.connection import DEFAULT_MAX_QUERY_CHARS, Connection
99
from testgen.common.models.table_group import TableGroup
1010
from testgen.utils import chunk_queries, to_sql_timestamp
1111

@@ -133,7 +133,8 @@ def get_row_counts(self, table_names: Iterable[str]) -> list[tuple[str, None]]:
133133
f"SELECT '{table}' AS table_name, COUNT(*) AS row_count FROM {self.flavor_service.get_table_ref(schema, table)}"
134134
for table in table_names
135135
]
136-
chunked_queries = chunk_queries(count_queries, " UNION ALL ", self.connection.max_query_chars)
136+
max_query_chars = self.connection.max_query_chars or DEFAULT_MAX_QUERY_CHARS
137+
chunked_queries = chunk_queries(count_queries, " UNION ALL ", max_query_chars)
137138
return [ (query, None) for query in chunked_queries ]
138139

139140
def verify_access(self, table_name: str) -> tuple[str, None]:

testgen/common/models/connection.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828

2929
SQLFlavorCode = Literal["redshift", "redshift_spectrum", "snowflake", "mssql", "azure_mssql", "synapse_mssql", "postgresql", "databricks", "bigquery", "oracle", "sap_hana", "salesforce_data360"]
3030

31+
# Fallback when a connection row has a NULL max_query_chars (no DB default; older
32+
# rows / non-UI insert paths may not seed it). Matches the UI's non-Salesforce
33+
# default and the 0160 migration.
34+
DEFAULT_MAX_QUERY_CHARS = 20000
35+
3136

3237
@dataclass
3338
class ConnectionMinimal(EntityMinimal):

tests/unit/commands/queries/test_refresh_data_chars_query.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,3 +217,16 @@ def test_filter_schema_columns_no_filters_returns_all():
217217
filtered = sql_generator.filter_schema_columns(columns)
218218

219219
assert {c.table_name for c in filtered} == {"users", "orders"}
220+
221+
222+
def test_get_row_counts_handles_null_max_query_chars():
223+
"""A connection with NULL max_query_chars must not crash chunking — it falls
224+
back to DEFAULT_MAX_QUERY_CHARS so the UNION ALL count queries still build."""
225+
connection = Connection(sql_flavor="postgresql", max_query_chars=None)
226+
table_group = TableGroup(table_group_schema="test_schema")
227+
sql_generator = RefreshDataCharsSQL(connection, table_group)
228+
229+
result = sql_generator.get_row_counts(["orders", "customers"])
230+
231+
assert result
232+
assert all(isinstance(query, str) and query for query, _ in result)

0 commit comments

Comments
 (0)