Skip to content

Commit

Permalink
Adapt is_overlay_view to LQ schema mounting in DDN
Browse files Browse the repository at this point in the history
  • Loading branch information
gruuya committed Apr 20, 2022
1 parent 8e20f22 commit 93b6dea
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
8 changes: 8 additions & 0 deletions splitgraph/core/fragment_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,14 @@ def record_overlay_table_as_patch(
)

if rows_inserted != 0 or rows_deleted != 0:
logging.debug(
"Persisting %s/%s inserted/deleted rows with hash %s/%s for overlay table %s.",
rows_inserted,
rows_deleted,
insertion_hash.hex(),
deletion_hash.hex(),
old_table.table_name,
)
content_hash = (insertion_hash - deletion_hash).hex()

object_id = "o" + sha256((content_hash + schema_hash).encode("ascii")).hexdigest()[:-2]
Expand Down
27 changes: 16 additions & 11 deletions splitgraph/core/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ def _commit(
# changed and tracked tables in a proper manner.
# See `init_write_overlay` for more details.

if self.is_overlay_view(table):
if self.is_overlay_view(table, schema=schema):
# Add the overlay view to the list of tables to process.
tables.append(table)
# Add the overlay view to the tracked tables list.
Expand All @@ -524,6 +524,10 @@ def _commit(
if table_not_empty:
# There are pending writes.
changed_tables.append(table)
logging.debug(
f"Found overlay table %s with{'' if table_not_empty else 'out'} pending changes.",
table,
)
elif self.object_engine.get_table_type(schema, table) == "VIEW":
logging.warning(
"Table %s.%s is a view. Splitgraph currently doesn't "
Expand All @@ -542,7 +546,7 @@ def _commit(
except TableNotFoundError:
table_info = None

if self.is_overlay_view(table):
if self.is_overlay_view(table, schema=schema):
# Altering the schema is not allowed in the case of overlay views.
assert table_info is not None
new_schema = table_info.table_schema
Expand Down Expand Up @@ -570,7 +574,7 @@ def _commit(
)
elif table in changed_tables:
# Else, if the table has changed, look at the audit log/upper overlay table and store it as a delta.
if not self.is_overlay_view(table):
if not self.is_overlay_view(table, schema=schema):
self.objects.record_table_as_patch(
table_info,
schema,
Expand Down Expand Up @@ -1136,22 +1140,23 @@ def diff(
# TODO we can aggregate chunks in a similar way that LQ does it.
return slow_diff(self, table_name, _hash(image_1), _hash(image_2), aggregate)

def is_overlay_view(self, table_name: str) -> bool:
def is_overlay_view(self, table_name: str, schema: Optional[str] = None) -> bool:
"""
Check whether the provided table is actually realized through the write
overlay mechanism.
"""
schema = schema or self.to_schema()

return (
# CLI LQ checkout overlay components
self.object_engine.get_table_type(self.to_schema(), table_name) == "VIEW"
and self.object_engine.table_exists(self.to_schema(), WRITE_LOWER_PREFIX + table_name)
and self.object_engine.table_exists(self.to_schema(), WRITE_UPPER_PREFIX + table_name)
self.object_engine.get_table_type(schema, table_name) == "VIEW"
and self.object_engine.table_exists(schema, WRITE_LOWER_PREFIX + table_name)
and self.object_engine.table_exists(schema, WRITE_UPPER_PREFIX + table_name)
) or (
# DDN LQ checkout overlay components
self.object_engine.get_table_type(self.to_schema(), table_name)
in ("FOREIGN TABLE", "FOREIGN")
and self.object_engine.table_exists(self.to_schema(), WRITE_UPPER_PREFIX + table_name)
and self.object_engine.table_exists(self.to_schema(), WRITE_MERGED_PREFIX + table_name)
self.object_engine.get_table_type(schema, table_name) in ("FOREIGN TABLE", "FOREIGN")
and self.object_engine.table_exists(schema, WRITE_UPPER_PREFIX + table_name)
and self.object_engine.table_exists(schema, WRITE_MERGED_PREFIX + table_name)
)


Expand Down

0 comments on commit 93b6dea

Please sign in to comment.