Skip to content

Commit

Permalink
Fixed style issues
Browse files Browse the repository at this point in the history
  • Loading branch information
cgivre committed Nov 15, 2022
1 parent 4cfa7ce commit 69f2873
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
25 changes: 13 additions & 12 deletions sqlglot/dialects/drill.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from __future__ import annotations

from sqlglot import exp, parser, tokens, generator
from sqlglot import exp, generator, parser, tokens
from sqlglot.dialects.dialect import (
Dialect,
create_with_partitions_sql,
format_time_lambda,
rename_func, str_position_sql,
no_trycast_sql, no_pivot_sql
no_pivot_sql,
no_trycast_sql,
rename_func,
str_position_sql,
)
from sqlglot.dialects.postgres import _lateral_sql
from sqlglot.tokens import TokenType
Expand All @@ -18,6 +20,7 @@ def _to_timestamp(args):
return exp.UnixToTime.from_arg_list(args)
return format_time_lambda(exp.StrToTime, "drill")(args)


def _str_to_time_sql(self, expression):
return f"STRPTIME({self.sql(expression, 'this')}, {self.format_time(expression)})"

Expand All @@ -38,6 +41,7 @@ def func(self, expression):

return func


def if_sql(self, expression):
"""
Drill requires backticks around certain SQL reserved words, IF being one of them, This function
Expand All @@ -62,6 +66,7 @@ def _str_to_date(self, expression):
return f"CAST({this} AS DATE)"
return f"TO_DATE({this}, {time_format})"


class Drill(Dialect):
normalize_functions = None
null_ordering = "nulls_are_last"
Expand Down Expand Up @@ -98,18 +103,16 @@ class Drill(Dialect):
"EE": "%a",
"EEE": "%a",
"EEEE": "%A",
"''T''": "T"
"''T''": "T",
}

class Tokenizer(tokens.Tokenizer):
QUOTES = ["'"]
IDENTIFIERS = ["`"]
ESCAPES = ["\\"]
ENCODE = "utf-8"

KEYWORDS = {
**tokens.Tokenizer.KEYWORDS,
"VARBINARY": TokenType.BINARY
}
KEYWORDS = {**tokens.Tokenizer.KEYWORDS, "VARBINARY": TokenType.BINARY}

normalize_functions = None

Expand All @@ -133,12 +136,10 @@ class Generator(generator.Generator):
exp.DataType.Type.NCHAR: "VARCHAR",
exp.DataType.Type.TIMESTAMPLTZ: "TIMESTAMP",
exp.DataType.Type.TIMESTAMPTZ: "TIMESTAMP",
exp.DataType.Type.DATETIME: "TIMESTAMP"
exp.DataType.Type.DATETIME: "TIMESTAMP",
}

ROOT_PROPERTIES = {
exp.PartitionedByProperty
}
ROOT_PROPERTIES = {exp.PartitionedByProperty}

TRANSFORMS = {
**generator.Generator.TRANSFORMS,
Expand Down
2 changes: 1 addition & 1 deletion tests/dialects/test_dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def test_cast(self):
},
write={
"duckdb": "TRY_CAST(a AS DOUBLE)",
"drill" : "CAST(a AS DOUBLE)",
"drill": "CAST(a AS DOUBLE)",
"postgres": "CAST(a AS DOUBLE PRECISION)",
"redshift": "CAST(a AS DOUBLE PRECISION)",
},
Expand Down
4 changes: 2 additions & 2 deletions tests/dialects/test_drill.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_quotes(self):
"presto": "'\"x\"'",
"hive": "'\"x\"'",
"spark": "'\"x\"'",
}
},
)
self.validate_all(
"'\\\\a'",
Expand All @@ -50,4 +50,4 @@ def test_table_function(self):
write={
"drill": "SELECT * FROM table( dfs.`test_data.xlsx` (type => 'excel', sheetName => 'secondSheet'))",
},
)
)

0 comments on commit 69f2873

Please sign in to comment.