Skip to content

Commit

Permalink
refactor: remove base implementation for quantile
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrist committed Aug 16, 2024
1 parent 3cfc344 commit 3c49c6a
Show file tree
Hide file tree
Showing 11 changed files with 13 additions and 31 deletions.
13 changes: 0 additions & 13 deletions ibis/backends/sql/compilers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1054,19 +1054,6 @@ def visit_Max(self, op, *, arg, where):

### Stats

def visit_Quantile(self, op, *, arg, quantile, where):
suffix = "cont" if op.arg.dtype.is_numeric() else "disc"
funcname = f"percentile_{suffix}"
expr = sge.WithinGroup(
this=self.f[funcname](quantile),
expression=sge.Order(expressions=[sge.Ordered(this=arg)]),
)
if where is not None:
expr = sge.Filter(this=expr, expression=sge.Where(this=where))
return expr

visit_MultiQuantile = visit_Quantile

def visit_VarianceStandardDevCovariance(self, op, *, how, where, **kw):
hows = {"sample": "samp", "pop": "pop"}
funcs = {
Expand Down
2 changes: 0 additions & 2 deletions ibis/backends/sql/compilers/bigquery/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ class BigQueryCompiler(SQLGlotCompiler):
ops.ExtractUserInfo,
ops.FindInSet,
ops.Median,
ops.Quantile,
ops.MultiQuantile,
ops.RegexSplit,
ops.RowID,
ops.TimestampDiff,
Expand Down
2 changes: 0 additions & 2 deletions ibis/backends/sql/compilers/datafusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ class DataFusionCompiler(SQLGlotCompiler):
ops.Greatest,
ops.IntervalFromInteger,
ops.Least,
ops.MultiQuantile,
ops.Quantile,
ops.RowID,
ops.Strftime,
ops.TimeDelta,
Expand Down
2 changes: 0 additions & 2 deletions ibis/backends/sql/compilers/druid.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ class DruidCompiler(SQLGlotCompiler):
ops.IsInf,
ops.Levenshtein,
ops.Median,
ops.MultiQuantile,
ops.Quantile,
ops.RandomUUID,
ops.RegexReplace,
ops.RegexSplit,
Expand Down
2 changes: 0 additions & 2 deletions ibis/backends/sql/compilers/flink.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ class FlinkCompiler(SQLGlotCompiler):
ops.IsNan,
ops.Levenshtein,
ops.Median,
ops.MultiQuantile,
ops.NthValue,
ops.Quantile,
ops.ReductionVectorizedUDF,
ops.RegexSplit,
ops.RowID,
Expand Down
2 changes: 0 additions & 2 deletions ibis/backends/sql/compilers/impala.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ class ImpalaCompiler(SQLGlotCompiler):
ops.Levenshtein,
ops.Map,
ops.Median,
ops.MultiQuantile,
ops.NthValue,
ops.Quantile,
ops.RegexSplit,
ops.RowID,
ops.StringSplit,
Expand Down
2 changes: 0 additions & 2 deletions ibis/backends/sql/compilers/mssql.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,7 @@ class MSSQLCompiler(SQLGlotCompiler):
ops.Map,
ops.Median,
ops.Mode,
ops.MultiQuantile,
ops.NthValue,
ops.Quantile,
ops.RegexExtract,
ops.RegexReplace,
ops.RegexSearch,
Expand Down
2 changes: 0 additions & 2 deletions ibis/backends/sql/compilers/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ def POS_INF(self):
ops.Levenshtein,
ops.Median,
ops.Mode,
ops.MultiQuantile,
ops.Quantile,
ops.RegexReplace,
ops.RegexSplit,
ops.RowID,
Expand Down
13 changes: 13 additions & 0 deletions ibis/backends/sql/compilers/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,19 @@ def visit_CountDistinctStar(self, op, *, where, arg):
)
return self.agg.count(sge.Distinct(expressions=[row]), where=where)

def visit_Quantile(self, op, *, arg, quantile, where):
suffix = "cont" if op.arg.dtype.is_numeric() else "disc"
funcname = f"percentile_{suffix}"
expr = sge.WithinGroup(
this=self.f[funcname](quantile),
expression=sge.Order(expressions=[sge.Ordered(this=arg)]),
)
if where is not None:
expr = sge.Filter(this=expr, expression=sge.Where(this=where))
return expr

visit_MultiQuantile = visit_Quantile

def visit_Correlation(self, op, *, left, right, how, where):
if how == "sample":
raise com.UnsupportedOperationError(
Expand Down
2 changes: 0 additions & 2 deletions ibis/backends/sql/compilers/sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ class SQLiteCompiler(SQLGlotCompiler):
ops.IsInf,
ops.Covariance,
ops.Correlation,
ops.Quantile,
ops.MultiQuantile,
ops.Median,
ops.ApproxMedian,
ops.Array,
Expand Down
2 changes: 0 additions & 2 deletions ibis/backends/sql/compilers/trino.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ class TrinoCompiler(SQLGlotCompiler):
NEG_INF = -POS_INF

UNSUPPORTED_OPS = (
ops.Quantile,
ops.MultiQuantile,
ops.Median,
ops.RowID,
ops.TimestampBucket,
Expand Down

0 comments on commit 3c49c6a

Please sign in to comment.