Skip to content

Commit

Permalink
feat(exasol): implement approx_nunique, std, var
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrist committed Aug 19, 2024
1 parent d182e9e commit 63c20c0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 40 deletions.
14 changes: 11 additions & 3 deletions ibis/backends/sql/compilers/exasol.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import ibis.common.exceptions as com
import ibis.expr.datatypes as dt
import ibis.expr.operations as ops
from ibis.backends.sql.compilers.base import NULL, SQLGlotCompiler
from ibis.backends.sql.compilers.base import NULL, STAR, SQLGlotCompiler
from ibis.backends.sql.datatypes import ExasolType
from ibis.backends.sql.dialects import Exasol
from ibis.backends.sql.rewrites import (
Expand Down Expand Up @@ -63,7 +63,6 @@ class ExasolCompiler(SQLGlotCompiler):
ops.RegexSearch,
ops.RegexSplit,
ops.RowID,
ops.StandardDev,
ops.Strftime,
ops.StringJoin,
ops.StringSplit,
Expand All @@ -77,7 +76,6 @@ class ExasolCompiler(SQLGlotCompiler):
ops.TimestampSub,
ops.TypeOf,
ops.Unnest,
ops.Variance,
)

SIMPLE_OPS = {
Expand Down Expand Up @@ -180,6 +178,16 @@ def visit_StringConcat(self, op, *, arg):
any_args_null = (a.is_(NULL) for a in arg)
return self.if_(sg.or_(*any_args_null), NULL, self.f.concat(*arg))

def visit_CountDistinct(self, op, *, arg, where):
if where is not None:
arg = self.if_(where, arg, NULL)
return self.f.count(sge.Distinct(expressions=[arg]))

def visit_CountStar(self, op, *, arg, where):
if where is not None:
return self.f.sum(self.cast(where, op.dtype))
return self.f.count(STAR)

def visit_CountDistinctStar(self, op, *, arg, where):
raise com.UnsupportedOperationError(
"COUNT(DISTINCT *) is not supported in Exasol"
Expand Down
1 change: 1 addition & 0 deletions ibis/backends/sql/dialects.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class Generator(Postgres.Generator):
TRANSFORMS = Postgres.Generator.TRANSFORMS.copy() | {
sge.Interval: _interval,
sge.GroupConcat: _group_concat,
sge.ApproxDistinct: rename_func("approximate_count_distinct"),
}
TYPE_MAPPING = Postgres.Generator.TYPE_MAPPING.copy() | {
sge.DataType.Type.TIMESTAMPTZ: "TIMESTAMP WITH LOCAL TIME ZONE",
Expand Down
41 changes: 4 additions & 37 deletions ibis/backends/tests/test_aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from ibis import literal as L
from ibis.backends.tests.errors import (
ClickHouseDatabaseError,
ExaQueryError,
GoogleBadRequest,
ImpalaHiveServer2Error,
MySQLNotSupportedError,
Expand Down Expand Up @@ -298,7 +297,6 @@ def mean_and_std(v):
raises=AttributeError,
reason="'IntegerColumn' object has no attribute 'notany'",
),
pytest.mark.notimpl(["exasol"], raises=ExaQueryError),
],
),
param(
Expand All @@ -311,7 +309,6 @@ def mean_and_std(v):
raises=AttributeError,
reason="'IntegerColumn' object has no attribute 'any'",
),
pytest.mark.notimpl(["exasol"], raises=ExaQueryError),
],
),
param(
Expand All @@ -336,7 +333,6 @@ def mean_and_std(v):
raises=AttributeError,
reason="'IntegerColumn' object has no attribute 'notall'",
),
pytest.mark.notimpl(["exasol"], raises=ExaQueryError),
],
),
param(
Expand All @@ -349,7 +345,6 @@ def mean_and_std(v):
raises=AttributeError,
reason="'IntegerColumn' object has no attribute 'all'",
),
pytest.mark.notimpl(["exasol"], raises=ExaQueryError),
],
),
param(
Expand Down Expand Up @@ -485,7 +480,7 @@ def mean_and_std(v):
id="bit_and",
marks=[
pytest.mark.notimpl(
["polars", "mssql"],
["polars", "mssql", "exasol"],
raises=com.OperationNotDefinedError,
),
pytest.mark.notimpl(["druid"], strict=False, raises=AssertionError),
Expand All @@ -500,7 +495,7 @@ def mean_and_std(v):
id="bit_or",
marks=[
pytest.mark.notimpl(
["polars", "mssql"],
["polars", "mssql", "exasol"],
raises=com.OperationNotDefinedError,
),
pytest.mark.notyet(
Expand All @@ -514,7 +509,7 @@ def mean_and_std(v):
id="bit_xor",
marks=[
pytest.mark.notimpl(
["polars", "mssql"],
["polars", "mssql", "exasol"],
raises=com.OperationNotDefinedError,
),
pytest.mark.notyet(
Expand All @@ -532,40 +527,12 @@ def mean_and_std(v):
@pytest.mark.parametrize(
("ibis_cond", "pandas_cond"),
[
param(
lambda _: None,
lambda _: slice(None),
marks=pytest.mark.notimpl(
["exasol"],
raises=(com.OperationNotDefinedError, ExaQueryError),
strict=False,
),
id="no_cond",
),
param(lambda _: None, lambda _: slice(None), id="no_cond"),
param(
lambda t: t.string_col.isin(["1", "7"]),
lambda t: t.string_col.isin(["1", "7"]),
marks=[
pytest.mark.notimpl(
["exasol"],
raises=(com.OperationNotDefinedError, ExaQueryError),
strict=False,
),
],
id="is_in",
),
param(
lambda _: ibis._.string_col.isin(["1", "7"]),
lambda t: t.string_col.isin(["1", "7"]),
marks=[
pytest.mark.notimpl(
["exasol"],
raises=(com.OperationNotDefinedError, ExaQueryError),
strict=False,
),
],
id="is_in_deferred",
),
],
)
def test_reduction_ops(
Expand Down

0 comments on commit 63c20c0

Please sign in to comment.