Skip to content

Commit

Permalink
Enableudf(bool) (#578)
Browse files Browse the repository at this point in the history
* Fix RBC issue 575

* test requires HeavyDB with literal array support
  • Loading branch information
guilhermeleobas committed Aug 3, 2023
1 parent ee8b93e commit cdc00b7
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
1 change: 1 addition & 0 deletions rbc/heavydb/remoteheavydb.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ def type_to_type_name(typ: typesystem.Type):
"""
styp = typ.tostring(use_annotation=False, use_name=False)
type_name = dict(
bool8='BOOLEAN',
int8='TINYINT',
int16='SMALLINT',
int32='INT',
Expand Down
6 changes: 3 additions & 3 deletions rbc/remotejit.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,9 @@ def __call__(self, *arguments, device=UNSPECIFIED, hold=UNSPECIFIED):
if device is not UNSPECIFIED and device != device_:
continue
with target_info:
atypes = self.remotejit.get_types(*arguments)
for caller_id, caller in enumerate(self.callers):
with Type.alias(**self.remotejit.typesystem_aliases):
with Type.alias(**self.remotejit.typesystem_aliases):
atypes = self.remotejit.get_types(*arguments)
for caller_id, caller in enumerate(self.callers):
ftype, penalty = caller.signature.best_match(caller.func, atypes)
if ftype is None:
continue
Expand Down
27 changes: 27 additions & 0 deletions rbc/tests/heavydb/test_caller.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import numpy as np
import pytest
from numpy.testing import assert_array_equal
from rbc.externals.heavydb import set_output_row_size
from rbc.heavydb import TextEncodingNone
from rbc.tests import heavydb_fixture, assert_equal
Expand Down Expand Up @@ -241,3 +242,29 @@ def incr_ol(x, dx): # noqa: F811

assert incr_ol(1).execute() == 2
assert incr_ol(1, 2).execute() == 3


def test_remote_call_bool(heavydb):
# RBC issue 575
if heavydb.version[:2] < (7, 0):
pytest.skip('Test requires HeavyDB 7.0 or newer')

@heavydb('bool(bool)')
def inverse_bool(b):
return False if b else True

assert inverse_bool(True).execute() == False # noqa: E712
assert inverse_bool(False).execute() == True # noqa: E712

from rbc.stdlib import array_api

@heavydb('bool[](bool[])')
def inv_bool_arr(arr):
sz = len(arr)
r = array_api.zeros_like(arr)
for i in range(sz):
r[i] = False if arr[i] else True
return r

assert_array_equal(inv_bool_arr([False, True]).execute(), [True, False])
assert_array_equal(inv_bool_arr([True, True]).execute(), [False, False])
2 changes: 1 addition & 1 deletion rbc/typesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def topython(self):

# python_imap values must be processed with Type.fromstring
_python_imap = {int: 'int64', float: 'float64', complex: 'complex128',
str: 'string', bytes: 'char*'}
str: 'string', bytes: 'char*', bool: 'bool'}

# Data for the mangling algorithm, see mangle/demangle methods.
#
Expand Down

0 comments on commit cdc00b7

Please sign in to comment.