From bdf5cc7bdd5ec93dc928d81e286f7b1e678ba19d Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 13 Sep 2023 11:17:40 +0200 Subject: Merging upstream version 18.4.1. Signed-off-by: Daniel Baumann --- tests/dialects/test_clickhouse.py | 65 +++++++++++++++++++++++---------------- 1 file changed, 39 insertions(+), 26 deletions(-) (limited to 'tests/dialects/test_clickhouse.py') diff --git a/tests/dialects/test_clickhouse.py b/tests/dialects/test_clickhouse.py index ab2379d..2cda0dc 100644 --- a/tests/dialects/test_clickhouse.py +++ b/tests/dialects/test_clickhouse.py @@ -6,30 +6,19 @@ class TestClickhouse(Validator): dialect = "clickhouse" def test_clickhouse(self): - self.validate_all( - "DATE_ADD('day', 1, x)", - read={ - "clickhouse": "dateAdd(day, 1, x)", - "presto": "DATE_ADD('day', 1, x)", - }, - write={ - "clickhouse": "DATE_ADD('day', 1, x)", - "presto": "DATE_ADD('day', 1, x)", - "": "DATE_ADD(x, 1, 'day')", - }, - ) - self.validate_all( - "DATE_DIFF('day', a, b)", - read={ - "clickhouse": "dateDiff('day', a, b)", - "presto": "DATE_DIFF('day', a, b)", - }, - write={ - "clickhouse": "DATE_DIFF('day', a, b)", - "presto": "DATE_DIFF('day', a, b)", - "": "DATEDIFF(b, a, day)", - }, - ) + string_types = [ + "BLOB", + "LONGBLOB", + "LONGTEXT", + "MEDIUMBLOB", + "MEDIUMTEXT", + "TINYBLOB", + "TINYTEXT", + "VARCHAR(255)", + ] + + for string_type in string_types: + self.validate_identity(f"CAST(x AS {string_type})", "CAST(x AS String)") expr = parse_one("count(x)") self.assertEqual(expr.sql(dialect="clickhouse"), "COUNT(x)") @@ -72,8 +61,8 @@ class TestClickhouse(Validator): self.validate_identity("position(haystack, needle)") self.validate_identity("position(haystack, needle, position)") self.validate_identity("CAST(x AS DATETIME)") - self.validate_identity("CAST(x AS VARCHAR(255))", "CAST(x AS String)") - self.validate_identity("CAST(x AS BLOB)", "CAST(x AS String)") + self.validate_identity("CAST(x as MEDIUMINT)", "CAST(x AS Int32)") + self.validate_identity( 'SELECT CAST(tuple(1 AS "a", 2 AS "b", 3.0 AS "c").2 AS Nullable(String))' ) @@ -93,6 +82,30 @@ class TestClickhouse(Validator): "CREATE MATERIALIZED VIEW test_view (id UInt8) TO db.table1 AS SELECT * FROM test_data" ) + self.validate_all( + "DATE_ADD('day', 1, x)", + read={ + "clickhouse": "dateAdd(day, 1, x)", + "presto": "DATE_ADD('day', 1, x)", + }, + write={ + "clickhouse": "DATE_ADD('day', 1, x)", + "presto": "DATE_ADD('day', 1, x)", + "": "DATE_ADD(x, 1, 'day')", + }, + ) + self.validate_all( + "DATE_DIFF('day', a, b)", + read={ + "clickhouse": "dateDiff('day', a, b)", + "presto": "DATE_DIFF('day', a, b)", + }, + write={ + "clickhouse": "DATE_DIFF('day', a, b)", + "presto": "DATE_DIFF('day', a, b)", + "": "DATEDIFF(b, a, day)", + }, + ) self.validate_all( "SELECT xor(1, 0)", read={ -- cgit v1.2.3