Skip to content

Commit

Permalink
chore(trino): use generic summary ops
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud committed Aug 8, 2024
1 parent e81eca5 commit 6a8fb76
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ibis/backends/sql/compilers/sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ def visit_DayOfWeekName(self, op, *, arg):
)

def visit_Xor(self, op, *, left, right):
return (left.or_(right)).and_(sg.not_(left.and_(right)))
return left.or_(right).and_(sg.not_(left.and_(right)))

def visit_NonNullLiteral(self, op, *, value, dtype):
if dtype.is_binary():
Expand Down
8 changes: 8 additions & 0 deletions ibis/backends/sql/compilers/trino.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,5 +659,13 @@ def visit_ArraySum(self, op, *, arg):
def visit_ArrayMean(self, op, *, arg):
return self.visit_ArraySumAgg(op, arg=arg, output=operator.truediv)

def visit_Info(self, op, *, parent):
# unnest cannot contain aggregates
return self.visit_GenericInfo(op, parent=parent)

def visit_Describe(self, op, *, parent, quantile):
# unnest cannot contain aggregates
return self.visit_GenericDescribe(op, parent=parent, quantile=quantile)


compiler = TrinoCompiler()
17 changes: 16 additions & 1 deletion ibis/backends/sql/dialects.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
Trino,
)
from sqlglot.dialects.dialect import rename_func
from sqlglot.helper import find_new_name, seq_get
from sqlglot.helper import find_new_name, flatten, seq_get

ClickHouse.Generator.TRANSFORMS |= {
sge.ArraySize: rename_func("length"),
Expand Down Expand Up @@ -440,7 +440,22 @@ class Generator(Postgres.Generator):
sge.Levenshtein: rename_func("editdistance"),
}


# return lambda self, expression: self.func(name, *flatten(expression.args.values()))
SQLite.Generator.TYPE_MAPPING |= {sge.DataType.Type.BOOLEAN: "BOOLEAN"}
SQLite.Generator.TRANSFORMS |= {
sge.Stddev: lambda self, e: self.func(
"sqrt", self.func("_ibis_var_sample", *flatten(e.args.values()))
),
sge.StddevSamp: lambda self, e: self.func(
"sqrt", self.func("_ibis_var_sample", *flatten(e.args.values()))
),
sge.StddevPop: lambda self, e: self.func(
"sqrt", self.func("_ibis_var_pop", *flatten(e.args.values()))
),
sge.Variance: rename_func("_ibis_var_samp"),
sge.VariancePop: rename_func("_ibis_var_pop"),
}


# TODO(cpcloud): remove this hack once
Expand Down

0 comments on commit 6a8fb76

Please sign in to comment.