diff --git a/recap/converters/postgresql.py b/recap/converters/postgresql.py index 607a73b..e5f11f5 100644 --- a/recap/converters/postgresql.py +++ b/recap/converters/postgresql.py @@ -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() @@ -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 @@ -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}") diff --git a/tests/integration/clients/test_postgresql.py b/tests/integration/clients/test_postgresql.py index e22d181..27c70e0 100644 --- a/tests/integration/clients/test_postgresql.py +++ b/tests/integration/clients/test_postgresql.py @@ -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 = [ @@ -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 = [ diff --git a/tests/unit/converters/test_postgresql.py b/tests/unit/converters/test_postgresql.py index fc234ab..4970cf8 100644 --- a/tests/unit/converters/test_postgresql.py +++ b/tests/unit/converters/test_postgresql.py @@ -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", @@ -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",