Repository: ibis-project/ibis

Issue:
BUG: OmniSciDB/MapD aggregate with where param doesn't work
Similar error reported https://github.com/ibis-project/ibis/issues/1620

Solution:

Add `ops.NullLiteral: lambda *args: 'CAST(NULL AS FLOAT)'`


Discussion:

Resolving patch:
diff --git a/ibis/mapd/operations.py b/ibis/mapd/operations.py
--- a/ibis/mapd/operations.py
+++ b/ibis/mapd/operations.py
@@ -825,6 +825,7 @@ def formatter(translator, expr):
 # GENERAL
 _general_ops = {
     ops.Literal: literal,
+    ops.NullLiteral: lambda *args: 'NULL',
     ops.ValueList: _value_list,
     ops.Cast: _cast,
     ops.Where: _where,
@@ -867,7 +868,6 @@ def formatter(translator, expr):
     ops.GroupConcat,
     ops.NullIf,
     ops.NullIfZero,
-    ops.NullLiteral,
     ops.IsInf,
     ops.IsNan,
     ops.IfNull,


Test patch:
diff --git a/ibis/mapd/tests/test_operations.py b/ibis/mapd/tests/test_operations.py
--- a/ibis/mapd/tests/test_operations.py
+++ b/ibis/mapd/tests/test_operations.py
@@ -151,3 +151,14 @@ def test_agg_with_bool(alltypes, ibis_op, sql_op):
     ).format(sql_op, ibis_op)
 
     assert regex.sub('', expr.compile()) == regex.sub('', sql_check)
+
+
+@pytest.mark.parametrize(
+    'expr_fn',
+    [
+        lambda t: t.float_col.mean(where=t.date_string_col == '11/01/10'),
+        lambda t: t.float_col.bucket([0, 1, 3]).name('bucket'),
+    ],
+)
+def test_expr_with_null_literal(alltypes, expr_fn):
+    expr_fn(alltypes).execute()
diff --git a/ibis/tests/all/test_aggregation.py b/ibis/tests/all/test_aggregation.py
--- a/ibis/tests/all/test_aggregation.py
+++ b/ibis/tests/all/test_aggregation.py
@@ -2,7 +2,7 @@
 import pytest
 from pytest import param
 
-from ibis.tests.backends import Clickhouse, MySQL, SQLite
+from ibis.tests.backends import Clickhouse, MapD, MySQL, SQLite
 
 
 @pytest.mark.parametrize(
@@ -12,6 +12,7 @@
             lambda t, where: t.bool_col.count(where=where),
             lambda t, where: len(t.bool_col[where].dropna()),
             id='count',
+            marks=pytest.mark.skip_backends((MapD,)),  # OmniSciDB issue #375
         ),
         param(
             lambda t, where: t.bool_col.any(),
diff --git a/ibis/tests/all/test_generic.py b/ibis/tests/all/test_generic.py
--- a/ibis/tests/all/test_generic.py
+++ b/ibis/tests/all/test_generic.py
@@ -44,6 +44,7 @@ def test_fillna_nullif(backend, con, expr, expected):
     ],
 )
 @pytest.mark.xfail_unsupported
+@pytest.mark.skip_backends((MapD,))  # OmniSciDB issue #375
 def test_coalesce(backend, con, expr, expected):
     result = con.execute(expr)
 
@@ -57,7 +58,6 @@ def test_coalesce(backend, con, expr, expected):
 
 
 @pytest.mark.xfail_unsupported
-@pytest.mark.skip_backends([MapD])
 def test_identical_to(backend, sorted_alltypes, con, sorted_df):
     df = sorted_df
     dt = df[['tinyint_col', 'double_col']]
@@ -88,7 +88,6 @@ def test_identical_to(backend, sorted_alltypes, con, sorted_df):
     ],
 )
 @pytest.mark.xfail_unsupported
-@pytest.mark.skip_backends([MapD])
 def test_isin(backend, sorted_alltypes, sorted_df, column, elements):
     expr = sorted_alltypes[
         'id', sorted_alltypes[column].isin(elements).name('tmp')
@@ -112,7 +111,6 @@ def test_isin(backend, sorted_alltypes, sorted_df, column, elements):
     ],
 )
 @pytest.mark.xfail_unsupported
-@pytest.mark.skip_backends([MapD])
 def test_notin(backend, sorted_alltypes, sorted_df, column, elements):
     expr = sorted_alltypes[
         'id', sorted_alltypes[column].notin(elements).name('tmp')