summaryrefslogtreecommitdiffstats
path: root/tests/dialects/test_drill.py
blob: e41bd3460085a55fc3fb4f77349176cd374c1769 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from tests.dialects.test_dialect import Validator


class TestDrill(Validator):
    dialect = "drill"

    def test_string_literals(self):
        self.validate_all(
            "SELECT '2021-01-01' + INTERVAL 1 MONTH",
            write={
                "mysql": "SELECT '2021-01-01' + INTERVAL 1 MONTH",
            },
        )

    def test_quotes(self):
        self.validate_all(
            "'\\''",
            write={
                "duckdb": "''''",
                "presto": "''''",
                "hive": "'\\''",
                "spark": "'\\''",
            },
        )
        self.validate_all(
            "'\"x\"'",
            write={
                "duckdb": "'\"x\"'",
                "presto": "'\"x\"'",
                "hive": "'\"x\"'",
                "spark": "'\"x\"'",
            },
        )
        self.validate_all(
            "'\\\\a'",
            read={
                "presto": "'\\\\a'",
            },
            write={
                "duckdb": "'\\\\a'",
                "presto": "'\\\\a'",
                "hive": "'\\\\a'",
                "spark": "'\\\\a'",
            },
        )

    def test_table_function(self):
        self.validate_all(
            "SELECT * FROM table( dfs.`test_data.xlsx` (type => 'excel', sheetName => 'secondSheet'))",
            write={
                "drill": "SELECT * FROM table(dfs.`test_data.xlsx`(type => 'excel', sheetName => 'secondSheet'))",
            },
        )

    def test_validate_pivot(self):
        self.validate_all(
            "SELECT * FROM (SELECT education_level, salary, marital_status, "
            "EXTRACT(year FROM age(birth_date)) age FROM cp.`employee.json`) PIVOT (avg(salary) AS "
            "avg_salary, avg(age) AS avg_age FOR marital_status IN ('M' married, 'S' single))",
            write={
                "drill": "SELECT * FROM (SELECT education_level, salary, marital_status, "
                "EXTRACT(year FROM age(birth_date)) AS age FROM cp.`employee.json`) "
                "PIVOT(AVG(salary) AS avg_salary, AVG(age) AS avg_age FOR marital_status "
                "IN ('M' AS married, 'S' AS single))"
            },
        )