String Dictionary Proxy#

The string dictionary proxy provides a convenient way for retrieving encoded strings within the database. It works by maintaining a lookup table that maps string values to unique integer identifiers.

Retrieving the dictionary proxy#

From RowFunctionManager#

from test_udf_text of rbc/tests/heavydb/test_howtos.py#
 1# Requires HeavyDB server v6.3 or newer
 2from rbc.heavydb import StringDictionaryProxy
 3
 4@heavydb('TextEncodingDict(RowFunctionManager, TextEncodingDict)')
 5def test_string_proxy(mgr, t):
 6    db_id: int = mgr.get_dict_db_id('test_string_proxy', 0)
 7    dict_id: int = mgr.get_dict_id('test_string_proxy', 0)
 8    proxy: StringDictionaryProxy = mgr.get_string_dictionary_proxy(db_id, dict_id)
 9    s: str = proxy.get_string(t)
10    return mgr.get_or_add_transient(
11        mgr.TRANSIENT_DICT_DB_ID,
12        mgr.TRANSIENT_DICT_ID,
13        s)

From TableFunctionManager#

from test_udf_text of rbc/tests/heavydb/test_howtos.py#
 1@heavydb('int32(TableFunctionManager, Column<T>, OutputColumn<T> | input_id=args<0>)',
 2         T=['TextEncodingDict'])
 3def test_string_proxy(mgr, inp, out):
 4    size = len(inp)
 5    mgr.set_output_row_size(size)
 6    for i in range(size):
 7        s = inp.string_dict_proxy.get_string(inp[i])
 8        id = out.string_dict_proxy.get_or_add_transient(s.title())
 9        out[i] = id
10    return size

Check the API reference page for a full list of table methods