summaryrefslogtreecommitdiffstats
path: root/sqlglot/dialects/tableau.py
diff options
context:
space:
mode:
Diffstat (limited to 'sqlglot/dialects/tableau.py')
-rw-r--r--sqlglot/dialects/tableau.py39
1 files changed, 18 insertions, 21 deletions
diff --git a/sqlglot/dialects/tableau.py b/sqlglot/dialects/tableau.py
index 51e685b..d5fba17 100644
--- a/sqlglot/dialects/tableau.py
+++ b/sqlglot/dialects/tableau.py
@@ -4,41 +4,38 @@ from sqlglot import exp, generator, parser, transforms
from sqlglot.dialects.dialect import Dialect
-def _if_sql(self, expression):
- return f"IF {self.sql(expression, 'this')} THEN {self.sql(expression, 'true')} ELSE {self.sql(expression, 'false')} END"
-
-
-def _coalesce_sql(self, expression):
- return f"IFNULL({self.sql(expression, 'this')}, {self.expressions(expression)})"
-
-
-def _count_sql(self, expression):
- this = expression.this
- if isinstance(this, exp.Distinct):
- return f"COUNTD({self.expressions(this, flat=True)})"
- return f"COUNT({self.sql(expression, 'this')})"
-
-
class Tableau(Dialect):
class Generator(generator.Generator):
JOIN_HINTS = False
TABLE_HINTS = False
TRANSFORMS = {
- **generator.Generator.TRANSFORMS, # type: ignore
- exp.If: _if_sql,
- exp.Coalesce: _coalesce_sql,
- exp.Count: _count_sql,
+ **generator.Generator.TRANSFORMS,
exp.Select: transforms.preprocess([transforms.eliminate_distinct_on]),
}
PROPERTIES_LOCATION = {
- **generator.Generator.PROPERTIES_LOCATION, # type: ignore
+ **generator.Generator.PROPERTIES_LOCATION,
exp.VolatileProperty: exp.Properties.Location.UNSUPPORTED,
}
+ def if_sql(self, expression: exp.If) -> str:
+ this = self.sql(expression, "this")
+ true = self.sql(expression, "true")
+ false = self.sql(expression, "false")
+ return f"IF {this} THEN {true} ELSE {false} END"
+
+ def coalesce_sql(self, expression: exp.Coalesce) -> str:
+ return f"IFNULL({self.sql(expression, 'this')}, {self.expressions(expression)})"
+
+ def count_sql(self, expression: exp.Count) -> str:
+ this = expression.this
+ if isinstance(this, exp.Distinct):
+ return f"COUNTD({self.expressions(this, flat=True)})"
+ return f"COUNT({self.sql(expression, 'this')})"
+
class Parser(parser.Parser):
FUNCTIONS = {
- **parser.Parser.FUNCTIONS, # type: ignore
+ **parser.Parser.FUNCTIONS,
"COUNTD": lambda args: exp.Count(this=exp.Distinct(expressions=args)),
}