Skip to content

Commit

Permalink
Prevent compacting on passthrough tables (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
msg555 authored Oct 11, 2024
1 parent 70255b6 commit 11d6dd6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# v0.4.3

- Fix issue where passthrough table columns could be marked for compaction

# v0.4.2

- Refactored temporary table creation to use sqlalchemy constructs
Expand Down
2 changes: 1 addition & 1 deletion subsetter/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.4.2"
__version__ = "0.4.3"
9 changes: 9 additions & 0 deletions subsetter/sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,7 @@ def __init__(self, source: DatabaseConfig, config: SamplerConfig) -> None:
self.source_engine = source.database_engine(env_prefix="SUBSET_SOURCE_")
self.compact_columns: Dict[Tuple[str, str], Set[str]] = {}
self.temp_tables = TempTableCreator()
self.passthrough_tables: Set[str] = set()

def sample(
self,
Expand All @@ -699,6 +700,7 @@ def sample(
truncate: bool = False,
create: bool = False,
) -> None:
self.passthrough_tables = set(plan.passthrough)
meta, _ = DatabaseMetadata.from_engine(self.source_engine, list(plan.queries))
if self.config.infer_foreign_keys != "none":
meta.infer_missing_foreign_keys(
Expand Down Expand Up @@ -740,6 +742,11 @@ def _get_compact_columns(
"Table %s has columns configured for compaction but is not found",
table,
)
elif table in self.passthrough_tables:
LOGGER.warning(
"Cannot compact columns on passthrough table %s",
table,
)
else:
compact_columns[table_key] = set(cols)

Expand All @@ -752,6 +759,8 @@ def _get_compact_columns(
for table_key, table_meta in meta.tables.items():
if len(table_meta.primary_key) != 1:
continue
if f"{table_key[0]}.{table_key[1]}" in self.passthrough_tables:
continue

col = table_meta.table_obj.columns[table_meta.primary_key[0]]
if not issubclass(col.type.python_type, int): # type: ignore
Expand Down

0 comments on commit 11d6dd6

Please sign in to comment.