heavyai / rbc

Remote Backend Compiler
https://rbc.readthedocs.io
BSD 3-Clause "New" or "Revised" License
29 stars 10 forks source link

Table function query fails when cursor is present #319

Open guilhermeleobas opened 3 years ago

guilhermeleobas commented 3 years ago

OmniSciDB diff

diff --git a/QueryEngine/TableFunctions/TableFunctionsTesting.hpp b/QueryEngine/TableFunctions/TableFunctionsTesting.hpp
index 018cca730..f0dacdcdd 100644
--- a/QueryEngine/TableFunctions/TableFunctionsTesting.hpp
+++ b/QueryEngine/TableFunctions/TableFunctionsTesting.hpp
@@ -268,3 +268,24 @@ EXTENSION_NOINLINE int32_t ct_binding_udtf3__cpu_25(const Column<int32_t>& input
   out[0] = 1000 + 169;
   return 1;
 }
+
+// clang-format off
+/*
+  UDTF: foo__cpu_1(Cursor<int32_t>, int32, RowMultiplier) -> Column<int32_t>
+  UDTF: foo__cpu_2(Cursor<int32_t>, Cursor<int32_t>, RowMultiplier) -> Column<int32_t>
+*/
+// clang-format on
+EXTENSION_NOINLINE int32_t foo__cpu_1(const Column<int32_t>& input1,
+                                      const int32_t x,
+                                      const int32_t multiplier,
+                                      Column<int32_t>& out) {
+  out[0] = 1;
+  return 1;
+}
+EXTENSION_NOINLINE int32_t foo__cpu_2(const Column<int32_t>& input1,
+                                      const Column<int32_t>& input2,
+                                      const int32_t multiplier,
+                                      Column<int32_t>& out) {
+  out[0] = 2;
+  return 1;
+}

RBC diff

diff --git a/rbc/tests/test_omnisci_column_default.py b/rbc/tests/test_omnisci_column_default.py
index 8a0a55b..423f4fc 100644
--- a/rbc/tests/test_omnisci_column_default.py
+++ b/rbc/tests/test_omnisci_column_default.py
@@ -94,3 +94,17 @@ def test_default_sizer(omnisci, suffix, kind, expected):
     result = list(result)

     assert result == [(expected,)], (result, query, kind)
+
+
+queries = (
+    'select * from table({fn}(cursor(select i4 from {table}), cursor(select i4 from {table}), 1));',
+    'select * from table({fn}(cursor(select i4, i4 from {table}), 3, 1));')
+@pytest.mark.parametrize("query", queries)
+def test_foo(omnisci, query):
+
+    fn = 'foo'
+    table = omnisci.table_name
+    q = query.format(fn=fn, table=table)
+
+    _, result = omnisci.sql_execute(q)
+    print(list(result))
diff --git a/setup.cfg b/setup.cfg
index 5fe77de..1fba8b2 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -21,4 +21,6 @@ max-line-length = 99
 filterwarnings =
     ignore::DeprecationWarning
 markers =
-    slow: mark test as slow.
\ No newline at end of file
+    slow: mark test as slow.
+addopts =
+    -rs -sv --disable-warnings --tb=short

Steps to reproduce

Apply both diffs and run the following in RBC

Run:

~/git/rbc:tests_default_sizer (rbc-dev) guilhermel@qgpu3 $ pytest rbc/tests/test_omnisci_column_default.py -k foo
========================================================================================================== test session starts ==========================================================================================================
platform linux -- Python 3.8.6, pytest-6.2.2, py-1.10.0, pluggy-0.13.1 -- /home/guilhermel/.conda/envs/rbc-dev/bin/python
cachedir: .pytest_cache
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('/home/guilhermel/git/rbc/.hypothesis/examples')
rootdir: /home/guilhermel/git/rbc, configfile: setup.cfg
plugins: hypothesis-6.4.0
collected 36 items / 34 deselected / 2 selected

rbc/tests/test_omnisci_column_default.py::test_foo[select * from table({fn}(cursor(select i4 from {table}), cursor(select i4 from {table}), 1));]  OmnisciDB version (5, 7, 0, 'dev-20210408-4da3d83b20')
[(2,)]
PASSED
rbc/tests/test_omnisci_column_default.py::test_foo[select * from table({fn}(cursor(select i4, i4 from {table}), 3, 1));] FAILED

=============================================================================================================== FAILURES ================================================================================================================
____________________________________________________________________________ test_foo[select * from table({fn}(cursor(select i4, i4 from {table}), 3, 1));] _____________________________________________________________________________
rbc/omniscidb.py:333: in thrift_call
    return client(Omnisci={name: args})['Omnisci'][name]
rbc/thrift/client.py:199: in __call__
    r = mth(*query_args)
../../.conda/envs/rbc-dev/lib/python3.8/site-packages/thriftpy2/thrift.py:219: in _req
    return self._recv(_api)
../../.conda/envs/rbc-dev/lib/python3.8/site-packages/thriftpy2/thrift.py:251: in _recv
    raise v
E   rpc-client-r68rjm1p.TMapDException: TMapDException(error_msg="Exception: SQL Error: From line 2, column 12 to line 3, column 43: Cannot apply 'foo' to arguments of type 'foo(<CURSOR>, <INTEGER>, <INTEGER>)'. Supported form(s): 'foo(<CURSOR>, <CURSOR>, <NUMERIC>)'")

During handling of the above exception, another exception occurred:
rbc/tests/test_omnisci_column_default.py:109: in test_foo
    _, result = omnisci.sql_execute(q)
rbc/omniscidb.py:581: in sql_execute
    result = self.thrift_call(
rbc/omniscidb.py:343: in thrift_call
    raise OmnisciServerError(f'{m.group(1)}')
E   rbc.errors.OmnisciServerError: SQL Error: From line 2, column 12 to line 3, column 43: Cannot apply 'foo' to arguments of type 'foo(<CURSOR>, <INTEGER>, <INTEGER>)'. Supported form(s): 'foo(<CURSOR>, <CURSOR>, <NUMERIC>)'
============================================================================================== 1 failed, 1 passed, 34 deselected in 1.07s ===============================================================================================

Expected output

Both queries should work

guilhermeleobas commented 1 year ago

Updated UDTF and query:

// clang-format off
/*
  UDTF: foo__cpu_1(Cursor<int32_t>, int32, RowMultiplier) -> Column<int32_t>
  UDTF: foo__cpu_2(Cursor<int32_t>, Cursor<int32_t>, RowMultiplier) -> Column<int32_t>
*/
// clang-format on
EXTENSION_NOINLINE int32_t foo__cpu_1(const Column<int32_t>& input1,
                                      const int32_t x,
                                      const int32_t multiplier,
                                      Column<int32_t>& out) {
  out[0] = 1;
  return 1;
}

EXTENSION_NOINLINE int32_t foo__cpu_2(const Column<int32_t>& input1,
                                      const Column<int32_t>& input2,
                                      const int32_t multiplier,
                                      Column<int32_t>& out) {
  out[0] = 2;
  return 1;
}
drop table if exists test;
create table test (x INT);
insert into test values (123);

select * from table(foo(
    cursor(select x from test),
    1,
    1
));

select * from table(foo(
    cursor(select x from test),
    cursor(select x from test)
));

Second query fails with:

2022-12-14 22:26:57 ERROR CalciteServerHandler:process:246 - SQL Error: java.lang.NullPointerException
2022-12-14T22:26:57.607682 E 105371 18 5 DBHandler.cpp:1636 query failed from broken view or other schema related issue