def test_return_two_str_literals(self): @udf(StringVal(FunctionContext, IntVal)) def fn(context, a): if a > 5: return "foo" else: return "bar"
def test_string_array(self): @udf(StringVal(FunctionContext, StringVal)) def fn(context, a): b = "foo" c = "bar" d = [b, c] return d[1]
def test_return_string_literal(ic): @udf(StringVal(FunctionContext, StringVal)) def return_string_literal(context, a): return "bar" ship_udf(ic, return_string_literal, overwrite=True) ic._cursor.execute('SELECT %s.return_string_literal("foo")' % ic._temp_db) results = ic._cursor.fetchall() assert results[0][0] == 'bar'
def test_string_index_concat(ic): @udf(StringVal(FunctionContext, StringVal)) def string_index_concat(context, a): return a[0] + a[3] ship_udf(ic, string_index_concat, overwrite=True) ic._cursor.execute('SELECT %s.string_index_concat("money")' % ic._temp_db) results = ic._cursor.fetchall() assert results[0][0] == 'me'
def test_string_indexing(ic): @udf(StringVal(FunctionContext, StringVal, IntVal)) def string_indexing(context, a, b): return a[b] ship_udf(ic, string_indexing, overwrite=True) ic._cursor.execute('SELECT %s.string_indexing("foo", 1)' % ic._temp_db) results = ic._cursor.fetchall() assert results[0][0] == 'o'
def test_string_split_comma(ic): @udf(StringVal(FunctionContext, StringVal)) def string_split_comma(context, a): return string.split(a, ",")[1] ship_udf(ic, string_split_comma, overwrite=True) ic._cursor.execute('SELECT %s.string_split_comma("foo,bar")' % ic._temp_db) results = ic._cursor.fetchall() assert results[0][0] == 'bar'
def test_return_empty_string(ic): @udf(StringVal(FunctionContext, StringVal)) def return_empty_string(context, a): return "" ship_udf(ic, return_empty_string, overwrite=True) ic._cursor.execute('SELECT %s.return_empty_string("blah")' % ic._temp_db) results = ic._cursor.fetchall() assert results[0][0] == ''
def test_string_concat(ic): @udf(StringVal(FunctionContext, StringVal, StringVal)) def string_concat(context, a, b): return a + b ship_udf(ic, string_concat, overwrite=True) ic._cursor.execute('SELECT %s.string_concat("howdy ", "doody")' % ic._temp_db) results = ic._cursor.fetchall() assert results[0][0] == 'howdy doody'
def test_return_two_str_literals(ic): @udf(StringVal(FunctionContext, IntVal)) def return_two_str_literals(context, a): if a > 5: return "foo" else: return "bar" ship_udf(ic, return_two_str_literals, overwrite=True) ic._cursor.execute('SELECT %s.return_two_str_literals(2)' % ic._temp_db) results = ic._cursor.fetchall() assert results[0][0] == 'bar' ic._cursor.execute('SELECT %s.return_two_str_literals(20)' % ic._temp_db) results = ic._cursor.fetchall() assert results[0][0] == 'foo'
def test_string_split(self): @udf(StringVal(FunctionContext, StringVal)) def fn(context, a): return string.split(a, ",")[0]
def test_string_indexing(self): @udf(StringVal(FunctionContext, StringVal, IntVal)) def fn(context, a, b): return a[b]
def test_string_index_concat(self): @udf(StringVal(FunctionContext, StringVal)) def fn(context, a): return a[0] + a[3]
def test_string_concat(self): @udf(StringVal(FunctionContext, StringVal, StringVal)) def fn(context, a, b): return a + b
def test_return_empty_string(self): @udf(StringVal(FunctionContext, StringVal)) def fn(context, a): return ""
def test_return_string_literal(self): @udf(StringVal(FunctionContext, StringVal)) def fn(context, a): return "foo"