Skip to content

Commit

Permalink
rename ignore_array_dimensionality -> enforce_array_dimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdemeo committed Dec 30, 2023
1 parent 2cc2753 commit 1c97a1e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
14 changes: 7 additions & 7 deletions recap/converters/postgresql.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
class PostgresqlConverter(DbapiConverter):
def __init__(
self,
ignore_array_dimensionality: bool = True,
enforce_array_dimensions: bool = False,
namespace: str = DEFAULT_NAMESPACE,
):
# since array dimensionality is not enforced by PG schemas:
# if `ignore_array_dimensionality = True` then read arrays irrespective of how many dimensions they have
# if `ignore_array_dimensionality = False` then read arrays as nested lists
self.ignore_array_dimensionality = ignore_array_dimensionality
# if `enforce_array_dimensions = False` then read arrays irrespective of how many dimensions they have
# if `enforce_array_dimensions = True` then read arrays as nested lists
self.enforce_array_dimensions = enforce_array_dimensions
self.namespace = namespace
self.registry = RecapTypeRegistry()

Expand Down Expand Up @@ -115,7 +115,9 @@ def _parse_type(self, column_props: dict[str, Any]) -> RecapType:
"ATTNDIMS": 0,
}
)
if self.ignore_array_dimensionality:
if self.enforce_array_dimensions:
base_type = self._create_n_dimension_list(value_type, ndims)
else:
column_name_without_periods = column_name.replace(".", "_")
base_type_alias = f"{self.namespace}.{column_name_without_periods}"
# Construct a self-referencing list comprised of the array's value
Expand All @@ -136,8 +138,6 @@ def _parse_type(self, column_props: dict[str, Any]) -> RecapType:
),
)
self.registry.register_alias(base_type)
else:
base_type = self._create_n_dimension_list(value_type, ndims)
else:
raise ValueError(f"Unknown data type: {data_type}")

Expand Down
8 changes: 4 additions & 4 deletions tests/integration/clients/test_postgresql.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ def teardown_class(cls):
# Close the connection
cls.connection.close()

def test_struct_method_arrays_ignore_dimensionality(self):
client = PostgresqlClient(self.connection, PostgresqlConverter(True))
def test_struct_method_arrays_no_enforce_dimensions(self):
client = PostgresqlClient(self.connection, PostgresqlConverter(False))
test_types_struct = client.schema("testdb", "public", "test_types")

expected_fields = [
Expand Down Expand Up @@ -269,8 +269,8 @@ def test_struct_method_arrays_ignore_dimensionality(self):
]
validate_results(test_types_struct, expected_fields)

def test_struct_method_arrays_with_dimensionality(self):
client = PostgresqlClient(self.connection, PostgresqlConverter(False)) # type: ignore
def test_struct_method_arrays_enforce_dimensions(self):
client = PostgresqlClient(self.connection, PostgresqlConverter(True)) # type: ignore
test_types_struct = client.schema("testdb", "public", "test_types")

expected_fields = [
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/converters/test_postgresql.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ def test_postgresql_converter(column_props, expected):
assert result == expected


def test_postgresql_converter_array_with_dimensionality():
converter = PostgresqlConverter(False)
def test_postgresql_converter_array_enforce_dimensions():
converter = PostgresqlConverter(True)
column_props = {
"COLUMN_NAME": "test_column",
"DATA_TYPE": "array",
Expand All @@ -270,8 +270,8 @@ def test_postgresql_converter_array_with_dimensionality():
assert result == expected


def test_postgresql_converter_array_ignore_dimensionality():
converter = PostgresqlConverter(True)
def test_postgresql_converter_array_no_enforce_dimensions():
converter = PostgresqlConverter(False)
column_props = {
"COLUMN_NAME": "test_column",
"DATA_TYPE": "array",
Expand Down

0 comments on commit 1c97a1e

Please sign in to comment.