summaryrefslogtreecommitdiffstats
path: root/tests/test_schema.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-06-02 23:59:40 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-06-02 23:59:46 +0000
commit20739a12c39121a9e7ad3c9a2469ec5a6876199d (patch)
treec000de91c59fd29b2d9beecf9f93b84e69727f37 /tests/test_schema.py
parentReleasing debian version 12.2.0-1. (diff)
downloadsqlglot-20739a12c39121a9e7ad3c9a2469ec5a6876199d.tar.xz
sqlglot-20739a12c39121a9e7ad3c9a2469ec5a6876199d.zip
Merging upstream version 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"))