Skip to content

Commit

Permalink
feat: use .get() instead of table_property()
Browse files Browse the repository at this point in the history
  • Loading branch information
LauJohansson committed Apr 5, 2024
1 parent cf4be18 commit aeed8a9
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 19 deletions.
5 changes: 4 additions & 1 deletion src/spetlr/configurator/configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,9 @@ def define(self, **kwargs) -> str:
key = json_hash(kwargs)
return self.register(key, kwargs)

@deprecated(
reason="Use .get(table_id,property_name) instead.",
)
def table_property(
self, table_id: str, property_name: str, default_value: str = None
):
Expand Down Expand Up @@ -395,7 +398,7 @@ def table_name(self, table_id: str):
:param table_id: Table id in the .json or .yaml files.
:return: str: table name
"""
return self.table_property(table_id, "name")
return self.get(table_id, "name")

@deprecated(
reason='Use .get(table_id,"path") instead.',
Expand Down
2 changes: 1 addition & 1 deletion src/spetlr/cosmos/cosmos.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def recreate_container_by_name(self, table_name: str):
def from_tc(self, table_id: str) -> CosmosHandle:
tc = Configurator()
name = tc.table_name(table_id)
rows_per_partition = tc.table_property(table_id, "rows_per_partition", "")
rows_per_partition = tc.get(table_id, "rows_per_partition", "")
rows_per_partition = int(rows_per_partition) if rows_per_partition else None

try:
Expand Down
4 changes: 2 additions & 2 deletions src/spetlr/delta/db_handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ def from_tc(cls, id: str):
tc = Configurator()
return cls(
name=tc.table_name(id),
location=tc.table_property(id, "path", ""),
data_format=tc.table_property(id, "format", "db"),
location=tc.get(id, "path", ""),
data_format=tc.get(id, "format", "db"),
)

def _validate(self):
Expand Down
12 changes: 6 additions & 6 deletions src/spetlr/delta/delta_handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ def __init__(
def from_tc(cls, id: str) -> "DeltaHandle":
tc = Configurator()
return cls(
name=tc.table_property(id, "name", ""),
location=tc.table_property(id, "path", ""),
name=tc.get(id, "name", ""),
location=tc.get(id, "path", ""),
schema=SchemaManager().get_schema(id, None),
data_format=tc.table_property(id, "format", "delta"),
ignore_changes=tc.table_property(id, "ignore_changes", "True"),
stream_start=tc.table_property(id, "stream_start", ""),
max_bytes_per_trigger=tc.table_property(id, "max_bytes_per_trigger", ""),
data_format=tc.get(id, "format", "delta"),
ignore_changes=tc.get(id, "ignore_changes", "True"),
stream_start=tc.get(id, "stream_start", ""),
max_bytes_per_trigger=tc.get(id, "max_bytes_per_trigger", ""),
)

def _validate(self):
Expand Down
8 changes: 4 additions & 4 deletions src/spetlr/eh/EventHubCapture.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ class EventHubCapture:
def from_tc(cls, id: str):
tc = Configurator()
return cls(
name=tc.table_property(id, "name"),
path=tc.table_property(id, "path"),
format=tc.table_property(id, "format"),
partitioning=tc.table_property(id, "partitioning"),
name=tc.get(id, "name"),
path=tc.get(id, "path"),
format=tc.get(id, "format"),
partitioning=tc.get(id, "partitioning"),
)

def __init__(
Expand Down
6 changes: 3 additions & 3 deletions src/spetlr/eh/EventHubCaptureExtractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ class EventHubCaptureExtractor:
@classmethod
def from_tc(cls, tbl_id: str):
tc = Configurator()
assert tc.table_property(tbl_id, "format") == "avro"
assert tc.get(tbl_id, "format") == "avro"
return cls(
path=tc.table_property(tbl_id, "path"),
partitioning=tc.table_property(tbl_id, "partitioning"),
path=tc.get(tbl_id, "path"),
partitioning=tc.get(tbl_id, "partitioning"),
)

def __init__(self, path: str, partitioning: str):
Expand Down
2 changes: 1 addition & 1 deletion src/spetlr/utils/DeleteMismatchedSchemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def get_table_ids_to_check():
c = Configurator()
table_ids_to_check = []
for key in c._raw_resource_details.keys():
if c.table_property(key, "delete_on_delta_schema_mismatch", False):
if c.get(key, "delete_on_delta_schema_mismatch", False):
table_ids_to_check.append(key)
return table_ids_to_check

Expand Down
2 changes: 1 addition & 1 deletion tests/local/configurator/test_configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def test_06_freestyle(self):
tc.add_resource_path(tables4)
details = tc.get_all_details()
self.assertTrue("MyFreeTable_eggs", details)
self.assertEqual(tc.table_property("MyFreeTable", "bacon"), "")
self.assertEqual(tc.get("MyFreeTable", "bacon"), "")

def test_07_bare_strings_and_structures(self):
tc = Configurator()
Expand Down

0 comments on commit aeed8a9

Please sign in to comment.