Skip to content

Commit

Permalink
cfr: Use underscore table names and cluster name as the schema
Browse files Browse the repository at this point in the history
  • Loading branch information
seut committed May 31, 2024
1 parent ee923ca commit 68d179b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 27 deletions.
9 changes: 7 additions & 2 deletions cratedb_toolkit/cfr/systable.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class ExportSettings:
DATA_PATH = "data"

# The filename prefix when storing tables to disk.
TABLE_FILENAME_PREFIX = "sys-"
TABLE_FILENAME_PREFIX = "sys_"


class SystemTableInspector:
Expand Down Expand Up @@ -143,7 +143,12 @@ def save(self) -> Path:

# Write schema file.
with open(path_table_schema, "w") as fh_schema:
print(self.inspector.ddl(tablename_in=tablename, tablename_out=tablename_out), file=fh_schema)
print(
self.inspector.ddl(
tablename_in=tablename, tablename_out=tablename_out, out_schema=self.info.cluster_name
),
file=fh_schema,
)

# Write data file.
df = self.read_table(tablename=tablename)
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CREATE TABLE IF NOT EXISTS "sys-operations" (
CREATE TABLE IF NOT EXISTS "crate"."sys_operations" (
id STRING,
job_id STRING,
name STRING,
Expand Down
48 changes: 24 additions & 24 deletions tests/cfr/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,32 +56,32 @@ def test_cfr_cli_import(cratedb, tmp_path, caplog):

# Blank database canvas.
imported_system_tables = [
"sys-allocations",
"sys-checks",
"sys-cluster",
"sys-health",
"sys-jobs",
"sys-jobs_log",
"sys-jobs_metrics",
"sys-node_checks",
"sys-nodes",
"sys-operations",
"sys-operations_log",
"sys-privileges",
"sys-repositories",
"sys-roles",
"sys-segments",
"sys-shards",
"sys-snapshot_restore",
"sys-snapshots",
"sys-users",
"sys_allocations",
"sys_checks",
"sys_cluster",
"sys_health",
"sys_jobs",
"sys_jobs_log",
"sys_jobs_metrics",
"sys_node_checks",
"sys_nodes",
"sys_operations",
"sys_operations_log",
"sys_privileges",
"sys_repositories",
"sys_roles",
"sys_segments",
"sys_shards",
"sys_snapshot_restore",
"sys_snapshots",
"sys_users",
]
cratedb.reset(imported_system_tables)

# Provision filesystem to look like a fake `sys-export` trace.
assets_path = files(tests.cfr) / "assets"
sys_operations_schema = assets_path / "sys-operations.sql"
sys_operations_data = assets_path / "sys-operations.jsonl"
sys_operations_schema = assets_path / "sys_operations.sql"
sys_operations_data = assets_path / "sys_operations.jsonl"
schema_path = tmp_path / "schema"
data_path = tmp_path / "data"
schema_path.mkdir()
Expand All @@ -104,7 +104,7 @@ def test_cfr_cli_import(cratedb, tmp_path, caplog):

# Verify outcome.
results = cratedb.database.run_sql("SHOW TABLES", records=True)
assert results == [{"table_name": "sys-operations"}]
assert results == [{"table_name": "sys_operations"}]

cratedb.database.run_sql('REFRESH TABLE "sys-operations"')
assert cratedb.database.count_records("sys-operations") == 1
cratedb.database.run_sql('REFRESH TABLE "sys_operations"')
assert cratedb.database.count_records("sys_operations") == 1

0 comments on commit 68d179b

Please sign in to comment.