Skip to content

Commit

Permalink
updated set_schema_2 in metadata to create nested ordered dict
Browse files Browse the repository at this point in the history
  • Loading branch information
Vedant P Iyer committed Nov 15, 2024
1 parent 61adf5b commit d9cd059
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion dsi/plugins/file_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def add_rows(self) -> None:
if self.db_name is not None:
self.csv_data[self.db_name] = table_data
else:
self.csv_data["CSV"] = table_data
self.csv_data = table_data

self.set_schema_2(self.csv_data)

Expand Down
8 changes: 7 additions & 1 deletion dsi/plugins/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,13 @@ def set_schema(self, table_data: list, validation_model=None) -> None:
self.strict_mode_lock = True

def set_schema_2(self, collection, validation_model=None) -> None:
self.output_collector = collection
# Finds file_reader class that called set_schema and assigns that as table_name for this data
if not isinstance(collection[next(iter(collection))], OrderedDict):
caller_frame = inspect.stack()[1]
tableName = caller_frame.frame.f_locals.get('self', None).__class__.__name__
self.output_collector[tableName] = collection
else:
self.output_collector = collection
self.table_cnt = len(collection.keys())
self.validation_model = validation_model

Expand Down
4 changes: 2 additions & 2 deletions dsi/plugins/tests/test_file_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def test_csv_plugin_leaves_active_metadata_wellformed():

def test_yaml_reader():
a=Terminal()
a.load_module('plugin', 'YAML', 'reader', filenames=["examples/data/student_test1.yml", "examples/data/student_test2.yml"], target_table_prefix = "student")
a.load_module('plugin', 'YAML1', 'reader', filenames=["examples/data/student_test1.yml", "examples/data/student_test2.yml"], target_table_prefix = "student")
a.transload()

assert len(a.active_metadata.keys()) == 4 # 4 tables - math, address, physics, dsi_units
Expand All @@ -110,7 +110,7 @@ def test_yaml_reader():

def test_toml_reader():
a=Terminal()
a.load_module('plugin', 'TOML', 'reader', filenames="examples/data/results.toml", target_table_prefix = "results")
a.load_module('plugin', 'TOML1', 'reader', filenames="examples/data/results.toml", target_table_prefix = "results")
a.transload()

assert len(a.active_metadata.keys()) == 2 # 2 tables - people and dsi_units
Expand Down
4 changes: 2 additions & 2 deletions dsi/plugins/tests/test_file_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ def test_csv_plugin_type():
def test_export_db_erd():
a=Terminal(debug_flag=False)
a.load_module('plugin', 'Schema', 'reader', filename="examples/data/example_schema.json" , target_table_prefix = "student")
a.load_module('plugin', 'YAML', 'reader', filenames=["examples/data/student_test1.yml", "examples/data/student_test2.yml"], target_table_prefix = "student")
a.load_module('plugin', 'TOML', 'reader', filenames=["examples/data/results.toml"], target_table_prefix = "results")
a.load_module('plugin', 'YAML1', 'reader', filenames=["examples/data/student_test1.yml", "examples/data/student_test2.yml"], target_table_prefix = "student")
a.load_module('plugin', 'TOML1', 'reader', filenames=["examples/data/results.toml"], target_table_prefix = "results")
a.load_module('plugin', 'ER_Diagram', 'writer', filename = 'erd_test_output.png')
a.transload()

Expand Down

0 comments on commit d9cd059

Please sign in to comment.