Skip to content

Commit

Permalink
fix(udf): replace xwasm with wasm
Browse files Browse the repository at this point in the history
Since 5.3 we use `wasm` instead `xwasm`. And `xwasm` script type does
not work anymore.

Replace all `xwasm` occurrences with `wasm`.
  • Loading branch information
soyacz committed May 10, 2023
1 parent b328cfa commit 9bf27a1
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 39 deletions.
8 changes: 4 additions & 4 deletions data_dir/c-s_uda_udf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ queries:
lua_var_length_counter:
cql: "SELECT ks.lua_var_length_counter(c7_text) AS result FROM ks.uda_udf LIMIT 10"
fields: samerow
xwasm_plus:
cql: "SELECT ks.xwasm_plus(c2_int, c3_int) AS result FROM ks.uda_udf LIMIT 10"
wasm_plus:
cql: "SELECT ks.wasm_plus(c2_int, c3_int) AS result FROM ks.uda_udf LIMIT 10"
fields: samerow
xwasm_div:
cql: "SELECT ks.xwasm_div(c2_int, c3_int) AS result FROM ks.uda_udf LIMIT 10"
wasm_div:
cql: "SELECT ks.wasm_div(c2_int, c3_int) AS result FROM ks.uda_udf LIMIT 10"
fields: samerow
2 changes: 1 addition & 1 deletion sdcm/utils/udf.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class UDF(BaseModel):
args: str
called_on_null_input_returns: str
return_type: str
language: Literal["lua", "xwasm"]
language: Literal["lua", "wasm"]
script: str

def get_create_query(self, ks: str, create_or_replace: bool = True) -> str:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# UDF script: divides two integers

name: 'xwasm_div'
name: 'wasm_div'
args: '(quotient int, dividend int)'
called_on_null_input_returns: 'NULL'
return_type: 'int'
language: 'xwasm'
language: 'wasm'
script: |-
(module
(type (;0;) (func))
Expand All @@ -25,7 +25,7 @@ script: |-
(global (;6;) i32 (i32.const 1))
(export "memory" (memory 0))
(export "__wasm_call_ctors" (func $__wasm_call_ctors))
(export "xwasm_div" (func $div))
(export "wasm_div" (func $div))
(export "__dso_handle" (global 1))
(export "__data_end" (global 2))
(export "__global_base" (global 3))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# UDF script: UDF function for a final UDA function - takes state tuple and returns a float from the division of the state tuples integers

name: 'xwasm_div_fin'
name: 'wasm_div_fin'
args: '(acc tuple<int, int>)'
called_on_null_input_returns: 'NULL'
return_type: 'float'
language: 'xwasm'
language: 'wasm'
script: |-
(module
(type (;0;) (func (param i64) (result i64)))
Expand Down Expand Up @@ -102,6 +102,6 @@ script: |-
(memory (;0;) 2)
(global (;0;) i32 (i32.const 1024))
(export "memory" (memory 0))
(export "xwasm_div_fin" (func 0))
(export "wasm_div_fin" (func 0))
(export "_scylla_abi" (global 0))
(data (;0;) (i32.const 1024) "\01\00\00\00"))
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# UDF script: returns the string length of the provided text var

name: 'xwasm_plus'
name: 'wasm_plus'
args: '(input1 int, input2 int)'
called_on_null_input_returns: 'NULL'
return_type: 'int'
language: 'xwasm'
language: 'wasm'
script: |-
(module
(type (;0;) (func))
Expand All @@ -25,7 +25,7 @@ script: |-
(global (;6;) i32 (i32.const 1))
(export "memory" (memory 0))
(export "__wasm_call_ctors" (func $__wasm_call_ctors))
(export "xwasm_plus" (func $plus))
(export "wasm_plus" (func $plus))
(export "__dso_handle" (global 1))
(export "__data_end" (global 2))
(export "__global_base" (global 3))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# UDF script: returns a tuple with the accumulator incremented by arg and counter incremented by 1

name: 'xwasm_plus_acc'
name: 'wasm_plus_acc'
args: '(acc tuple<int, int>, arg int)'
called_on_null_input_returns: 'NULL'
return_type: 'tuple <int, int>'
language: 'xwasm'
language: 'wasm'
script: |-
(module
(type (;0;) (func (param i64 i64) (result i64)))
Expand Down Expand Up @@ -146,6 +146,6 @@ script: |-
(memory (;0;) 2)
(global (;0;) i32 (i32.const 1024))
(export "memory" (memory 0))
(export "xwasm_plus_acc" (func 0))
(export "wasm_plus_acc" (func 0))
(export "_scylla_abi" (global 0))
(data (;0;) (i32.const 1024) "\01\00\00\00"))
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
# with the following clang command: clang -O2 --target=wasm32 --no-standard-libraries -Wl,--export-all -Wl,--no-entry simple_return.cpp -o simple_return.wasm


name: 'xwasm_simple_return_int'
name: 'wasm_simple_return_int'
args: '(acc tuple<int, int>)'
called_on_null_input_returns: 'NULL'
return_type: 'int'
language: 'xwasm'
language: 'wasm'
script: |-
(module
(type (;0;) (func))
(type (;1;) (func (param i32) (result i32)))
(func $__wasm_call_ctors (type 0))
(func $xwasm_simple_return_int (type 1) (param i32) (result i32)
(func $wasm_simple_return_int (type 1) (param i32) (result i32)
local.get 0)
(table (;0;) 1 1 funcref)
(memory (;0;) 2)
Expand All @@ -26,7 +26,7 @@ script: |-
(global (;6;) i32 (i32.const 1))
(export "memory" (memory 0))
(export "__wasm_call_ctors" (func $__wasm_call_ctors))
(export "xwasm_simple_return_int" (func $xwasm_simple_return_int))
(export "wasm_simple_return_int" (func $wasm_simple_return_int))
(export "__dso_handle" (global 1))
(export "__data_end" (global 2))
(export "__global_base" (global 3))
Expand Down
2 changes: 1 addition & 1 deletion test-cases/features/uda_udf.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
test_duration: 90

prepare_write_cmd: "cassandra-stress user profile=/tmp/c-s_uda_udf.yaml ops'(insert=1)' cl=QUORUM duration=2m -mode native cql3 -rate threads=10"
stress_cmd: ["cassandra-stress user profile=/tmp/c-s_uda_udf.yaml ops'(my_avg=1, lua_var_length_counter=33, xwasm_plus=33, xwasm_div=32)' cl=QUORUM duration=30m -mode native cql3 -rate threads=20"]
stress_cmd: ["cassandra-stress user profile=/tmp/c-s_uda_udf.yaml ops'(my_avg=1, lua_var_length_counter=33, wasm_plus=33, wasm_div=32)' cl=QUORUM duration=30m -mode native cql3 -rate threads=20"]

n_db_nodes: 3
n_loaders: 1
Expand Down
8 changes: 4 additions & 4 deletions uda_udf_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ def _verify_udf_functions(self):
query=f"SELECT {self.KEYSPACE_NAME}.lua_var_length_counter(c7_text) AS result "
f"FROM {self.KEYSPACE_NAME}.{self.CF_NAME} LIMIT 1",
verifier_func=lambda c2, c3, c7, query_response: len(c7) == query_response.result),
UDVerification(name="xwasm_plus",
query=f"SELECT {self.KEYSPACE_NAME}.xwasm_plus(c2_int, c3_int) AS result "
UDVerification(name="wasm_plus",
query=f"SELECT {self.KEYSPACE_NAME}.wasm_plus(c2_int, c3_int) AS result "
f"FROM {self.KEYSPACE_NAME}.{self.CF_NAME} LIMIT 1",
verifier_func=lambda c2, c3, c7, query_response: c2 + c3 == query_response.result),
UDVerification(name="xwasm_div",
query=f"SELECT {self.KEYSPACE_NAME}.xwasm_div(c2_int, c3_int) AS result "
UDVerification(name="wasm_div",
query=f"SELECT {self.KEYSPACE_NAME}.wasm_div(c2_int, c3_int) AS result "
f"FROM {self.KEYSPACE_NAME}.{self.CF_NAME} LIMIT 1",
verifier_func=lambda c2, c3, c7, query_response: c2 // c3 == query_response.result)
]
Expand Down
12 changes: 6 additions & 6 deletions unit_tests/test_uda.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,19 @@ def test_get_create_query_string(self):

def test_load_uda_from_yaml(self):
expected_create_string = "CREATE AGGREGATE testing.my_uda(int) " \
"SFUNC xwasm_plus " \
"SFUNC wasm_plus " \
"STYPE int " \
"REDUCEFUNC xwasm_plus " \
"FINALFUNC xwasm_simple_return_int " \
"REDUCEFUNC wasm_plus " \
"FINALFUNC wasm_simple_return_int " \
"INITCOND (0, 0);"

data = {
"name": "my_uda",
"args": "int",
"return_type": "int",
"accumulator_udf_name": "xwasm_plus",
"reduce_udf_name": "xwasm_plus",
"final_udf_name": "xwasm_simple_return_int",
"accumulator_udf_name": "wasm_plus",
"reduce_udf_name": "wasm_plus",
"final_udf_name": "wasm_simple_return_int",
"initial_condition": "(0, 0)"
}

Expand Down
14 changes: 7 additions & 7 deletions unit_tests/test_udf.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ class TestUDF(TestCase):
"script": "return #var"
}

MOCK_XWASM_UDF_VALS = {
"name": 'xwasm_plus',
MOCK_WASM_UDF_VALS = {
"name": 'wasm_plus',
"args": '(input1 int, input2 int)',
"called_on_null_input_returns": 'NULL',
"return_type": 'int',
"language": 'xwasm',
"language": 'wasm',
"script": r"""(module
(type (;0;) (func))
(type (;1;) (func (param i32 i32) (result i32)))
Expand All @@ -52,7 +52,7 @@ class TestUDF(TestCase):
(global (;6;) i32 (i32.const 1))
(export "memory" (memory 0))
(export "__wasm_call_ctors" (func $__wasm_call_ctors))
(export "xwasm_plus" (func $plus))
(export "wasm_plus" (func $plus))
(export "__dso_handle" (global 1))
(export "__data_end" (global 2))
(export "__global_base" (global 3))
Expand Down Expand Up @@ -115,10 +115,10 @@ def test_loading_udfs_with_lua_scripts(self):
for key, value in expected_vals.items():
self.assertEqual(value, getattr(udf, key), f"Did not find expected value for {key} in the udf class.")

def test_loading_udfs_with_xwasm_scripts(self):
expected_vals = self.MOCK_XWASM_UDF_VALS.copy()
def test_loading_udfs_with_wasm_scripts(self):
expected_vals = self.MOCK_WASM_UDF_VALS.copy()

udf_yaml_filename = "./sdcm/utils/udf_scripts/xwasm_plus.yaml"
udf_yaml_filename = "./sdcm/utils/udf_scripts/wasm_plus.yaml"
udf = UDF.from_yaml(udf_yaml_filename)

self.assertIsNotNone(udf)
Expand Down

0 comments on commit 9bf27a1

Please sign in to comment.