Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent compacting on passthrough tables #31

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading