Esempio n. 1
0
 def test_return_two_str_literals(self):
     @udf(StringVal(FunctionContext, IntVal))
     def fn(context, a):
         if a > 5:
             return "foo"
         else:
             return "bar"
Esempio n. 2
0
 def test_string_array(self):
     @udf(StringVal(FunctionContext, StringVal))
     def fn(context, a):
         b = "foo"
         c = "bar"
         d = [b, c]
         return d[1]
Esempio n. 3
0
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'
Esempio n. 4
0
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'
Esempio n. 5
0
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'
Esempio n. 6
0
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'
Esempio n. 7
0
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] == ''
Esempio n. 8
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'
Esempio n. 9
0
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'
Esempio n. 10
0
 def test_string_split(self):
     @udf(StringVal(FunctionContext, StringVal))
     def fn(context, a):
         return string.split(a, ",")[0]
Esempio n. 11
0
 def test_string_indexing(self):
     @udf(StringVal(FunctionContext, StringVal, IntVal))
     def fn(context, a, b):
         return a[b]
Esempio n. 12
0
 def test_string_index_concat(self):
     @udf(StringVal(FunctionContext, StringVal))
     def fn(context, a):
         return a[0] + a[3]
Esempio n. 13
0
 def test_string_concat(self):
     @udf(StringVal(FunctionContext, StringVal, StringVal))
     def fn(context, a, b):
         return a + b
Esempio n. 14
0
 def test_return_empty_string(self):
     @udf(StringVal(FunctionContext, StringVal))
     def fn(context, a):
         return ""
Esempio n. 15
0
 def test_return_string_literal(self):
     @udf(StringVal(FunctionContext, StringVal))
     def fn(context, a):
         return "foo"