Skip to content

Commit e0bdddf

Browse files
Rename Bytes -> TextEncodingNone
1 parent 511dfb8 commit e0bdddf

11 files changed

+109
-133
lines changed

doc/omnisci/bytes.rst

-42
This file was deleted.

rbc/heavyai/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from .array import * # noqa: F401, F403
22
from .column import * # noqa: F401, F403
3-
from .bytes import * # noqa: F401, F403
43
from .metatype import * # noqa: F401, F403
5-
from .text_encoding import * # noqa: F401, F403
64
from .pipeline import * # noqa: F401, F403
75
from .column_list import * # noqa: F401, F403
86
from .table_function_manager import * # noqa: F401, F403
7+
from .text_encoding_dict import * # noqa: F401, F403
8+
from .text_encoding_none import * # noqa: F401, F403
99

1010
from . import mathimpl as math # noqa: F401
1111
from . import npyimpl as np # noqa: F401

rbc/heavyai/bytes.py

-53
This file was deleted.

rbc/heavyai/pipeline.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def define_pipelines(self):
158158
# namely the "nopython" pipeline
159159
pm = DefaultPassBuilder.define_nopython_pipeline(self.state)
160160
# Add the new pass to run after IRProcessing
161-
pm.add_pass_after(AutoFreeBuffers, IRProcessing)
161+
# pm.add_pass_after(AutoFreeBuffers, IRProcessing)
162162
pm.add_pass_after(CheckRaiseStmts, IRProcessing)
163163
pm.add_pass_after(DTypeComparison, ReconstructSSA)
164164
# finalize

rbc/heavyai/text_encoding.py rbc/heavyai/text_encoding_dict.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
'''Omnisci Bytes type that corresponds to Omnisci type TEXT ENCODED NONE.
1+
'''Omnisci TextEncodingDict type that corresponds to Omnisci type TEXT ENCODED DICT.
22
'''
33

44
__all__ = ['OmnisciTextEncodingDictType', 'TextEncodingDict']

rbc/heavyai/text_encoding_none.py

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
'''Omnisci TextEncodingNone type that corresponds to Omnisci type TEXT ENCODED NONE.
2+
'''
3+
4+
__all__ = ['TextEncodingNonePointer', 'TextEncodingNone', 'OmnisciTextEncodingNoneType']
5+
6+
from rbc import typesystem
7+
from .buffer import (
8+
BufferPointer, Buffer, OmnisciBufferType,
9+
omnisci_buffer_constructor)
10+
from numba.core import types, extending
11+
12+
13+
class OmnisciTextEncodingNoneType(OmnisciBufferType):
14+
"""Omnisci TextEncodingNone type for RBC typesystem.
15+
"""
16+
17+
@classmethod
18+
def preprocess_args(cls, args):
19+
element_type = typesystem.Type.fromstring('char8')
20+
return ((element_type,),)
21+
22+
@property
23+
def buffer_extra_members(self):
24+
return ('bool is_null',)
25+
26+
def match(self, other):
27+
if type(self) is type(other):
28+
return self[0] == other[0]
29+
if other.is_pointer and other[0].is_char and other[0].bits == 8:
30+
return 1
31+
if other.is_string:
32+
return 2
33+
34+
35+
TextEncodingNonePointer = BufferPointer
36+
37+
38+
class TextEncodingNone(Buffer):
39+
'''Omnisci TextEncodingNone type that corresponds to Omnisci type TEXT ENCODED NONE.
40+
41+
Omnisci TextEncodingNone represents the following structure:
42+
43+
struct TextEncodingNone {
44+
char* ptr;
45+
size_t sz; // when non-negative, TextEncodingNone has fixed width.
46+
}
47+
48+
49+
.. code-block:: python
50+
51+
from rbc.omnisci_backend import TextEncodingNone
52+
53+
@omnisci('TextEncodingNone(int32, int32)')
54+
def make_abc(first, n):
55+
r = TextEncodingNone(n)
56+
for i in range(n):
57+
r[i] = first + i
58+
return r
59+
'''
60+
pass
61+
62+
63+
@extending.lower_builtin(TextEncodingNone, types.Integer)
64+
def omnisci_text_encoding_none_constructor(context, builder, sig, args):
65+
return omnisci_buffer_constructor(context, builder, sig, args)
66+
67+
68+
@extending.type_callable(TextEncodingNone)
69+
def type_omnisci_text_encoding_none(context):
70+
def typer(size):
71+
return typesystem.Type.fromobject('TextEncodingNone').tonumba()
72+
return typer

rbc/heavydb.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from .thrift import Client as ThriftClient
1515
from . import heavyai
1616
from .heavyai import (
17-
OmnisciArrayType, OmnisciBytesType, OmnisciTextEncodingDictType,
17+
OmnisciArrayType, OmnisciTextEncodingNoneType, OmnisciTextEncodingDictType,
1818
OmnisciOutputColumnType, OmnisciColumnType,
1919
OmnisciCompilerPipeline, OmnisciCursorType,
2020
BufferMeta, OmnisciColumnListType, OmnisciTableFunctionManagerType)
@@ -389,7 +389,6 @@ def add(a, b):
389389
typesystem_aliases = dict(
390390
bool='bool8',
391391
Array='OmnisciArrayType',
392-
Bytes='OmnisciBytesType<char8>',
393392
Cursor='OmnisciCursorType',
394393
Column='OmnisciColumnType',
395394
OutputColumn='OmnisciOutputColumnType',
@@ -399,6 +398,7 @@ def add(a, b):
399398
Constant='int32|sizer=Constant',
400399
PreFlight='int32|sizer=PreFlight',
401400
ColumnList='OmnisciColumnListType',
401+
TextEncodingNone='OmnisciTextEncodingNoneType',
402402
TextEncodingDict='OmnisciTextEncodingDictType',
403403
TableFunctionManager='OmnisciTableFunctionManagerType<>',
404404
UDTF='int32|kind=UDTF'
@@ -849,7 +849,7 @@ def _get_ext_arguments_map(self):
849849
'GeoPolygon': typemap['TExtArgumentType'].get('GeoPolygon'),
850850
'GeoMultiPolygon': typemap['TExtArgumentType'].get(
851851
'GeoMultiPolygon'),
852-
'Bytes': typemap['TExtArgumentType'].get('TextEncodingNone'),
852+
'TextEncodingNone': typemap['TExtArgumentType'].get('TextEncodingNone'),
853853
'TextEncodingDict': typemap['TExtArgumentType'].get('TextEncodingDict'),
854854
'ColumnList<bool>': typemap['TExtArgumentType'].get('ColumnListBool'),
855855
'ColumnList<int8_t>': typemap['TExtArgumentType'].get('ColumnListInt8'),
@@ -894,7 +894,8 @@ def _get_ext_arguments_map(self):
894894
ext_arguments_map['OmnisciOutputColumnListType<%s>' % ptr_type] \
895895
= ext_arguments_map.get('ColumnList<%s>' % T)
896896

897-
ext_arguments_map['OmnisciBytesType<char8>'] = ext_arguments_map.get('Bytes')
897+
ext_arguments_map['OmnisciTextEncodingNoneType<char8>'] = \
898+
ext_arguments_map.get('TextEncodingNone')
898899

899900
values = list(ext_arguments_map.values())
900901
for v, n in thrift.TExtArgumentType._VALUES_TO_NAMES.items():
@@ -1397,8 +1398,8 @@ def format_type(self, typ: typesystem.Type):
13971398
elif isinstance(typ, OmnisciCursorType):
13981399
p = tuple(map(self.format_type, typ[0]))
13991400
typ = typesystem.Type(('Cursor',) + p, **typ._params)
1400-
elif isinstance(typ, OmnisciBytesType):
1401-
typ = typ.copy().params(typename='Bytes')
1401+
elif isinstance(typ, OmnisciTextEncodingNoneType):
1402+
typ = typ.copy().params(typename='TextEncodingNone')
14021403
use_typename = True
14031404
elif isinstance(typ, OmnisciTextEncodingDictType):
14041405
typ = typ.copy().params(typename='TextEncodingDict')
@@ -1443,7 +1444,7 @@ def remote_call(self, func, ftype: typesystem.Type, arguments: tuple, hold=False
14431444

14441445
if isinstance(atype, (OmnisciColumnType, OmnisciColumnListType)):
14451446
args.append(f'CURSOR({a})')
1446-
elif isinstance(atype, OmnisciBytesType):
1447+
elif isinstance(atype, OmnisciTextEncodingNoneType):
14471448
if isinstance(a, bytes):
14481449
a = repr(a.decode())
14491450
elif isinstance(a, str):

rbc/tests/heavyai/test_caller.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import numpy as np
22
import pytest
33
from rbc.externals.heavydb import set_output_row_size
4-
from rbc.heavyai import Bytes
4+
from rbc.heavyai import TextEncodingNone
55
from rbc.tests import heavydb_fixture, assert_equal
66

77

@@ -37,9 +37,9 @@ def aincr(x, dx, y):
3737
y[i] = x[i] + dx
3838
return size
3939

40-
@heavydb('Bytes(Bytes)')
40+
@heavydb('TextEncodingNone(TextEncodingNone)')
4141
def myupper(s):
42-
r = Bytes(len(s))
42+
r = TextEncodingNone(len(s))
4343
for i in range(len(s)):
4444
c = s[i]
4545
if c >= 97 and c <= 122:
@@ -112,9 +112,9 @@ def test_remote_float64_evaluation(heavydb):
112112
assert_equal(arange(3, np.float64(1))['x'], np.arange(3, dtype=np.float64) + 1)
113113

114114

115-
def test_remote_bytes_evaluation(heavydb):
115+
def test_remote_TextEncodingNone_evaluation(heavydb):
116116
myupper = heavydb.get_caller('myupper')
117-
assert str(myupper) == "myupper['Bytes(Bytes)']"
117+
assert str(myupper) == "myupper['TextEncodingNone(TextEncodingNone)']"
118118
assert str(myupper("abc")) == "SELECT myupper('abc')"
119119
assert str(myupper("abc").execute()) == 'ABC'
120120
assert str(myupper(b"abc")) == "SELECT myupper('abc')"

rbc/tests/heavyai/test_heavyai.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -774,9 +774,9 @@ def test(s, caller=False):
774774
assert test('Column<int32> z') == 'Column<int32> z'
775775
assert test('Column<int32> | name=z') == 'Column<int32> z'
776776
assert test('Column<int32> x | name=z') == 'Column<int32> x | name=z'
777-
assert test('Column<Bytes>') == 'Column<Bytes>'
777+
assert test('Column<TextEncodingNone>') == 'Column<TextEncodingNone>'
778778
assert test('Column<Array<int32>>') == 'Column<Array<int32>>'
779-
assert test('Column<Array<Bytes>>') == 'Column<Array<Bytes>>'
779+
assert test('Column<Array<TextEncodingNone>>') == 'Column<Array<TextEncodingNone>>'
780780

781781
assert test('OutputColumn<int32>') == 'OutputColumn<int32>'
782782
assert test('ColumnList<int32>') == 'ColumnList<int32>'
@@ -796,18 +796,18 @@ def test(s, caller=False):
796796
assert test('UDTF(Cursor<int32, float64>)') == 'UDTF(Cursor<Column<int32>, Column<float64>>)'
797797
assert test('UDTF(Cursor<int32 x>)') == 'UDTF(Cursor<Column<int32> x>)'
798798
assert test('UDTF(Cursor<int32 | name=x>)') == 'UDTF(Cursor<Column<int32> x>)'
799-
assert test('UDTF(Cursor<Bytes x>)') == 'UDTF(Cursor<Column<Bytes> x>)'
799+
assert test('UDTF(Cursor<TextEncodingNone x>)') == 'UDTF(Cursor<Column<TextEncodingNone> x>)'
800800

801801
assert test('int32(int32)') == '(int32) -> int32'
802802
assert test('int32(int32 x)') == '(int32 x) -> int32'
803803
assert test('int32(Array<int32>)') == '(Array<int32>) -> int32'
804804
assert test('int32(int32[])') == '(Array<int32>) -> int32'
805805
assert test('int32(Array<int32> x)') == '(Array<int32> x) -> int32'
806-
assert test('int32(Bytes)') == '(Bytes) -> int32'
807-
assert test('int32(Bytes x)') == '(Bytes x) -> int32'
806+
assert test('int32(TextEncodingNone)') == '(TextEncodingNone) -> int32'
807+
assert test('int32(TextEncodingNone x)') == '(TextEncodingNone x) -> int32'
808808
assert test('int32(TextEncodingDict)') == '(TextEncodingDict) -> int32'
809809
assert test('int32(TextEncodingDict x)') == '(TextEncodingDict x) -> int32'
810-
assert test('int32(Array<Bytes> x)') == '(Array<Bytes> x) -> int32'
810+
assert test('int32(Array<TextEncodingNone> x)') == '(Array<TextEncodingNone> x) -> int32'
811811

812812
def test2(s):
813813
return test(s, caller=True)
@@ -822,8 +822,8 @@ def test2(s):
822822
assert test2('UDTF(Constant, OutputColumn<int32>)') == '(void) -> (Column<int32>)'
823823
assert test2('UDTF(PreFlight, OutputColumn<int32>)') == '(void) -> (Column<int32>)'
824824
assert test2('UDTF(TableFunctionManager, OutputColumn<int32>)') == '(void) -> (Column<int32>)'
825-
assert (test2('UDTF(RowMultiplier, OutputColumn<Array<Bytes>>)')
826-
== '(RowMultiplier) -> (Column<Array<Bytes>>)')
825+
assert (test2('UDTF(RowMultiplier, OutputColumn<Array<TextEncodingNone>>)')
826+
== '(RowMultiplier) -> (Column<Array<TextEncodingNone>>)')
827827

828828
assert test2('UDTF(Cursor<int32>)') == '(Cursor<Column<int32>>) -> void'
829829
assert test2('UDTF(Cursor<int32 x>)') == '(Cursor<Column<int32> x>) -> void'

0 commit comments

Comments
 (0)