Skip to content

Commit 63c20c0

Browse files
committed
feat(exasol): implement approx_nunique, std, var
1 parent d182e9e commit 63c20c0

File tree

3 files changed

+16
-40
lines changed

3 files changed

+16
-40
lines changed

ibis/backends/sql/compilers/exasol.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import ibis.common.exceptions as com
77
import ibis.expr.datatypes as dt
88
import ibis.expr.operations as ops
9-
from ibis.backends.sql.compilers.base import NULL, SQLGlotCompiler
9+
from ibis.backends.sql.compilers.base import NULL, STAR, SQLGlotCompiler
1010
from ibis.backends.sql.datatypes import ExasolType
1111
from ibis.backends.sql.dialects import Exasol
1212
from ibis.backends.sql.rewrites import (
@@ -63,7 +63,6 @@ class ExasolCompiler(SQLGlotCompiler):
6363
ops.RegexSearch,
6464
ops.RegexSplit,
6565
ops.RowID,
66-
ops.StandardDev,
6766
ops.Strftime,
6867
ops.StringJoin,
6968
ops.StringSplit,
@@ -77,7 +76,6 @@ class ExasolCompiler(SQLGlotCompiler):
7776
ops.TimestampSub,
7877
ops.TypeOf,
7978
ops.Unnest,
80-
ops.Variance,
8179
)
8280

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

181+
def visit_CountDistinct(self, op, *, arg, where):
182+
if where is not None:
183+
arg = self.if_(where, arg, NULL)
184+
return self.f.count(sge.Distinct(expressions=[arg]))
185+
186+
def visit_CountStar(self, op, *, arg, where):
187+
if where is not None:
188+
return self.f.sum(self.cast(where, op.dtype))
189+
return self.f.count(STAR)
190+
183191
def visit_CountDistinctStar(self, op, *, arg, where):
184192
raise com.UnsupportedOperationError(
185193
"COUNT(DISTINCT *) is not supported in Exasol"

ibis/backends/sql/dialects.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class Generator(Postgres.Generator):
7676
TRANSFORMS = Postgres.Generator.TRANSFORMS.copy() | {
7777
sge.Interval: _interval,
7878
sge.GroupConcat: _group_concat,
79+
sge.ApproxDistinct: rename_func("approximate_count_distinct"),
7980
}
8081
TYPE_MAPPING = Postgres.Generator.TYPE_MAPPING.copy() | {
8182
sge.DataType.Type.TIMESTAMPTZ: "TIMESTAMP WITH LOCAL TIME ZONE",

ibis/backends/tests/test_aggregation.py

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from ibis import literal as L
1414
from ibis.backends.tests.errors import (
1515
ClickHouseDatabaseError,
16-
ExaQueryError,
1716
GoogleBadRequest,
1817
ImpalaHiveServer2Error,
1918
MySQLNotSupportedError,
@@ -298,7 +297,6 @@ def mean_and_std(v):
298297
raises=AttributeError,
299298
reason="'IntegerColumn' object has no attribute 'notany'",
300299
),
301-
pytest.mark.notimpl(["exasol"], raises=ExaQueryError),
302300
],
303301
),
304302
param(
@@ -311,7 +309,6 @@ def mean_and_std(v):
311309
raises=AttributeError,
312310
reason="'IntegerColumn' object has no attribute 'any'",
313311
),
314-
pytest.mark.notimpl(["exasol"], raises=ExaQueryError),
315312
],
316313
),
317314
param(
@@ -336,7 +333,6 @@ def mean_and_std(v):
336333
raises=AttributeError,
337334
reason="'IntegerColumn' object has no attribute 'notall'",
338335
),
339-
pytest.mark.notimpl(["exasol"], raises=ExaQueryError),
340336
],
341337
),
342338
param(
@@ -349,7 +345,6 @@ def mean_and_std(v):
349345
raises=AttributeError,
350346
reason="'IntegerColumn' object has no attribute 'all'",
351347
),
352-
pytest.mark.notimpl(["exasol"], raises=ExaQueryError),
353348
],
354349
),
355350
param(
@@ -485,7 +480,7 @@ def mean_and_std(v):
485480
id="bit_and",
486481
marks=[
487482
pytest.mark.notimpl(
488-
["polars", "mssql"],
483+
["polars", "mssql", "exasol"],
489484
raises=com.OperationNotDefinedError,
490485
),
491486
pytest.mark.notimpl(["druid"], strict=False, raises=AssertionError),
@@ -500,7 +495,7 @@ def mean_and_std(v):
500495
id="bit_or",
501496
marks=[
502497
pytest.mark.notimpl(
503-
["polars", "mssql"],
498+
["polars", "mssql", "exasol"],
504499
raises=com.OperationNotDefinedError,
505500
),
506501
pytest.mark.notyet(
@@ -514,7 +509,7 @@ def mean_and_std(v):
514509
id="bit_xor",
515510
marks=[
516511
pytest.mark.notimpl(
517-
["polars", "mssql"],
512+
["polars", "mssql", "exasol"],
518513
raises=com.OperationNotDefinedError,
519514
),
520515
pytest.mark.notyet(
@@ -532,40 +527,12 @@ def mean_and_std(v):
532527
@pytest.mark.parametrize(
533528
("ibis_cond", "pandas_cond"),
534529
[
535-
param(
536-
lambda _: None,
537-
lambda _: slice(None),
538-
marks=pytest.mark.notimpl(
539-
["exasol"],
540-
raises=(com.OperationNotDefinedError, ExaQueryError),
541-
strict=False,
542-
),
543-
id="no_cond",
544-
),
530+
param(lambda _: None, lambda _: slice(None), id="no_cond"),
545531
param(
546532
lambda t: t.string_col.isin(["1", "7"]),
547533
lambda t: t.string_col.isin(["1", "7"]),
548-
marks=[
549-
pytest.mark.notimpl(
550-
["exasol"],
551-
raises=(com.OperationNotDefinedError, ExaQueryError),
552-
strict=False,
553-
),
554-
],
555534
id="is_in",
556535
),
557-
param(
558-
lambda _: ibis._.string_col.isin(["1", "7"]),
559-
lambda t: t.string_col.isin(["1", "7"]),
560-
marks=[
561-
pytest.mark.notimpl(
562-
["exasol"],
563-
raises=(com.OperationNotDefinedError, ExaQueryError),
564-
strict=False,
565-
),
566-
],
567-
id="is_in_deferred",
568-
),
569536
],
570537
)
571538
def test_reduction_ops(

0 commit comments

Comments
 (0)