summaryrefslogtreecommitdiffstats
path: root/tests/test_schema.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-06-02 23:59:11 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-06-02 23:59:11 +0000
commitcaea5267cb8e1fea3702adbdf6f68fd37d13b3b7 (patch)
treef06f1da1ab3b6906beca1c3c7222d28ff00766ac /tests/test_schema.py
parentAdding upstream version 12.2.0. (diff)
downloadsqlglot-caea5267cb8e1fea3702adbdf6f68fd37d13b3b7.tar.xz
sqlglot-caea5267cb8e1fea3702adbdf6f68fd37d13b3b7.zip
Adding upstream version 15.0.0.upstream/15.0.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/test_schema.py')
-rw-r--r--tests/test_schema.py16
1 files changed, 12 insertions, 4 deletions
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"))