From 20739a12c39121a9e7ad3c9a2469ec5a6876199d Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 3 Jun 2023 01:59:40 +0200 Subject: Merging upstream version 15.0.0. Signed-off-by: Daniel Baumann --- tests/test_schema.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'tests/test_schema.py') diff --git a/tests/test_schema.py b/tests/test_schema.py index 92cf04a..b03e7e7 100644 --- a/tests/test_schema.py +++ b/tests/test_schema.py @@ -210,14 +210,22 @@ class TestSchema(unittest.TestCase): self.assertEqual(schema.column_names(table_z), ["a", "B"]) self.assertEqual(schema.column_names(table_w), ["c"]) - # Clickhouse supports both `` and "" for identifier quotes; sqlglot uses "" when generating sql schema = MappingSchema(schema={"x": {"`y`": "INT"}}, dialect="clickhouse") self.assertEqual(schema.column_names(exp.Table(this="x")), ["y"]) - # Check that add_table normalizes both the table and the column names to be added/updated + # Check that add_table normalizes both the table and the column names to be added / updated schema = MappingSchema() schema.add_table("Foo", {"SomeColumn": "INT", '"SomeColumn"': "DOUBLE"}) + self.assertEqual(schema.column_names(exp.Table(this="fOO")), ["somecolumn", "SomeColumn"]) - table_foo = exp.Table(this="fOO") + # Check that names are normalized to uppercase for Snowflake + schema = MappingSchema(schema={"x": {"foo": "int", '"bLa"': "int"}}, dialect="snowflake") + self.assertEqual(schema.column_names(exp.Table(this="x")), ["FOO", "bLa"]) - self.assertEqual(schema.column_names(table_foo), ["somecolumn", "SomeColumn"]) + # Check that switching off the normalization logic works as expected + schema = MappingSchema(schema={"x": {"foo": "int"}}, normalize=False, dialect="snowflake") + self.assertEqual(schema.column_names(exp.Table(this="x")), ["foo"]) + + # Check that the correct dialect is used when calling schema methods + schema = MappingSchema(schema={"[Fo]": {"x": "int"}}, dialect="tsql") + self.assertEqual(schema.column_names("[Fo]"), schema.column_names("`Fo`", dialect="spark")) -- cgit v1.2.3