Skip to content

Commit 10f8a59

Browse files
aarthy-dkclaude
andcommitted
refactor(catalog): tighten object_type typing and mssql sampleable set
Address review feedback on MR !547: - Narrow mssql sampleable_object_types to {TABLE} — SQL Server has no materialized views, so the MATERIALIZED_VIEW entry never matched. - Annotate object_type as ObjectType (not str) on ColumnChars and the DataTable model/overview, per the StrEnum-everywhere convention. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 4f0134b commit 10f8a59

4 files changed

Lines changed: 15 additions & 10 deletions

File tree

testgen/common/database/column_chars.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class ColumnChars:
2020
column_type: str | None = None
2121
db_data_type: str | None = None
2222
is_decimal: bool = False
23-
object_type: str | None = None # ObjectType values
23+
object_type: ObjectType | None = None
2424
approx_record_ct: int | None = None
2525
# This should not default to 0 since we don't always retrieve actual row counts
2626
# UI relies on the null value to know that the approx_record_ct should be displayed instead

testgen/common/database/flavor/mssql_flavor_service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ class MssqlFlavorService(FlavorService):
1111
escaped_underscore = "[_]"
1212
row_limiting_clause = "top"
1313
url_scheme = "mssql+pyodbc"
14-
# TABLESAMPLE applies only to tables and materialized views
15-
sampleable_object_types = frozenset({ObjectType.TABLE, ObjectType.MATERIALIZED_VIEW})
14+
# TABLESAMPLE is rejected on views; SQL Server has no materialized views, so only base tables.
15+
sampleable_object_types = frozenset({ObjectType.TABLE})
1616

1717
def get_connection_string_from_fields(self, params: ResolvedConnectionParams) -> str:
1818
connection_url = URL.create(

testgen/common/models/data_table.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
)
1818
from sqlalchemy.dialects import postgresql
1919

20+
from testgen.common.database.column_chars import ObjectType
2021
from testgen.common.models import get_current_session
2122
from testgen.common.models.data_column import DataColumnChars
2223
from testgen.common.models.entity import Entity
@@ -42,7 +43,7 @@ class TableProfilingOverview:
4243
table_groups_id: UUID
4344
schema_name: str | None
4445
table_name: str
45-
object_type: str | None
46+
object_type: ObjectType | None
4647
record_ct: int | None
4748
column_ct: int | None
4849
dq_score_profiling: float | None
@@ -62,7 +63,7 @@ class DataTable(Entity):
6263
table_groups_id: UUID = Column(postgresql.UUID(as_uuid=True), ForeignKey("table_groups.id"))
6364
schema_name: str | None = Column(String)
6465
table_name: str = Column(String)
65-
object_type: str | None = Column(String)
66+
object_type: ObjectType | None = Column(String)
6667
column_ct: int | None = Column(BigInteger)
6768
record_ct: int | None = Column(BigInteger)
6869
approx_record_ct: int | None = Column(BigInteger)

tests/unit/common/test_flavor_sampling.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,15 @@
1212
pytestmark = pytest.mark.unit
1313

1414

15-
@pytest.mark.parametrize("flavor", ["mssql", "postgresql"])
16-
def test_sampleable_restricted_to_physical_where_clause_rejects_views(flavor):
17-
# Verified live: TABLESAMPLE errors on a view for these flavors, so only physical
18-
# relations are sampleable; views/external/other are profiled in full.
19-
assert get_flavor_service(flavor).sampleable_object_types == {
15+
# Verified live: TABLESAMPLE errors on a view for these flavors, so only physical relations
16+
# are sampleable; views/external/other are profiled in full.
17+
def test_mssql_samples_only_base_tables():
18+
# SQL Server has no materialized views, so the sampleable set is just base tables.
19+
assert get_flavor_service("mssql").sampleable_object_types == {ObjectType.TABLE}
20+
21+
22+
def test_postgresql_samples_tables_and_materialized_views():
23+
assert get_flavor_service("postgresql").sampleable_object_types == {
2024
ObjectType.TABLE,
2125
ObjectType.MATERIALIZED_VIEW,
2226
}

0 commit comments

Comments
 (0)