@Test public void testNullHandling() throws TajoException { testSimpleEval("select null_test()", new String[]{NullDatum.get().toString()}); }
@Test public void testPow() throws TajoException { testSimpleEval("select pow(9,3) as col1 ", new String[]{String.valueOf(Math.pow(9, 3))}); testSimpleEval("select pow(1.0,3) as col1 ", new String[]{String.valueOf(Math.pow(1.0, 3))}); testSimpleEval("select pow(20.1,3.1) as col1 ", new String[]{String.valueOf(Math.pow(20.1, 3.1))}); testSimpleEval("select pow(null,3.1) as col1 ", new String[]{NullDatum.get().toString()}); testSimpleEval("select pow(20.1,null) as col1 ", new String[]{NullDatum.get().toString()}); Schema schema = SchemaBuilder.builder() .add("col1", FLOAT4) .add("col2", FLOAT8) .add("col3", INT4) .add("col4", INT8) .build(); testEval(schema, "table1", "0.4,2.7,3,2", "select pow(col1, col2), pow(col3, col4) from table1", new String[]{ String.valueOf(Math.pow((float) 0.4, 2.7)), String.valueOf(Math.pow(3, 2)) }); }
@Test public void testJsonArrayGet() throws TajoException { testSimpleEval("select json_array_get('" + JSON_ARRAY + "', 0)", new String[]{"100"}); testSimpleEval("select json_array_get('" + JSON_ARRAY + "', 2)", new String[]{"300"}); testSimpleEval("select json_array_get('" + JSON_ARRAY + "', -1)", new String[]{"500"}); testSimpleEval("select json_array_get('" + JSON_ARRAY + "', -2)", new String[]{"400"}); testSimpleEval("select json_array_get('" + JSON_ARRAY + "', 10)", new String[]{NullDatum.get().toString()}); testSimpleEval("select json_array_get('" + JSON_ARRAY + "', -10)", new String[]{NullDatum.get().toString()}); testSimpleEval("select json_array_get('" + JSON_EMPTY_ARRAY + "', 0)", new String[]{NullDatum.get().toString()}); }
@Test public void testRegexReplace() throws TajoException { testSimpleEval("select regexp_replace('abcdef','bc','--') as col1 ", new String[]{"a--def"}); // null test testSimpleEval("select regexp_replace(null, 'bc', '--') as col1 ", new String[]{NullDatum.get().toString()}); testSimpleEval("select regexp_replace('abcdef', null, '--') as col1 ", new String[]{NullDatum.get().toString()}); testSimpleEval("select regexp_replace('abcdef','bc', null) as col1 ", new String[]{NullDatum.get().toString()}); Schema schema = SchemaBuilder.builder() .add("col1", TEXT) .add("col2", TEXT) .add("col3", TEXT) .build(); // find matches and replace from column values testEval(schema, "table1", "------,(^--|--$),ab", "select regexp_replace(col1, col2, col3) as str from table1", new String[]{"ab--ab"}); // null test from a table testEval(schema, "table1", "\\NULL,(^--|--$),ab", "select regexp_replace(col1, col2, col3) as str from table1", new String[]{NullDatum.get().toString()}); testEval(schema, "table1", "------,(^--|--$),\\NULL", "select regexp_replace(col1, col2, col3) as str from table1", new String[]{NullDatum.get().toString()}); }
@Test public void testNullHandling2() throws TajoException { Schema schema = SchemaBuilder.builder() .add("col1", BOOLEAN) .build(); testEval(schema, "table1", "", "select null_test() from table1", new String[]{NullDatum.get().toString()}); } }
@Test public void testCaseWhensWithNullReturn() throws TajoException { Schema schema = SchemaBuilder.builder() .add("col1", TajoDataTypes.Type.TEXT) .add("col2", TajoDataTypes.Type.TEXT) .build(); testEval(schema, "table1", "str1,str2", "SELECT CASE WHEN col1 IS NOT NULL THEN col2 ELSE NULL END FROM table1", new String[]{"str2"}); testEval(schema, "table1", "\\NULL,str2", "SELECT CASE WHEN col1 IS NOT NULL THEN col2 ELSE NULL END FROM table1", new String[]{NullDatum.get().toString()}); }
@Test public void testDigest() throws TajoException { testSimpleEval("select digest('tajo', 'md2') as col1 ", new String[]{"bf523bce8241982f6bea9af0f7fd37ff"}); testSimpleEval("select digest('tajo', 'md5') as col1 ", new String[]{"742721b3a79f71a9491681b8e8a7ce85"}); testSimpleEval("select digest('tajo', 'sha1') as col1 ", new String[]{"02b0e20540b89f0b735092bbac8093eb2e3804cf"}); testSimpleEval("select digest('tajo', 'sha256') as col1 ", new String[]{"6440083be076869a9f9d0271a4bf298d98c8aa3ecb49df841895fbcddbb04a70"}); testSimpleEval("select digest('tajo', 'sha384') as col1 ", new String[]{"59ff99b0e274eb3d8e10f221b6b949bfc1244d2a1226c5c720062fb03d82272be633e4a0f2babccffbfdff7cc1cb06fb"}); testSimpleEval("select digest('tajo', 'sha512') as col1 ", new String[]{"ee8ba254d331ddfb1bca9aaf0c4b8c58aea5331928cbd20168c87828afb853b0c096af71ec69a23b669217a1dddd2934edaac33b1296fe526b22abd28a15c4b3"}); testSimpleEval("select digest('tajo', 'not') as col1 ", new String[]{NullDatum.get().toString()}); }
@Test public void testCaseWhensWithCommonExpressionAndNull() throws TajoException { Schema schema = SchemaBuilder.builder() .add("col1", TajoDataTypes.Type.INT4) .add("col2", TajoDataTypes.Type.INT4) .add("col3", TajoDataTypes.Type.INT4) .build(); testEval(schema, "table1", "1,2,3", "SELECT CASE col1 WHEN 1 THEN NULL WHEN 2 THEN 2 ELSE 3 END FROM table1", new String [] {NullDatum.get().toString()}); testEval(schema, "table1", "1,2,3", "SELECT CASE col2 WHEN 1 THEN NULL WHEN 2 THEN 2 ELSE 3 END FROM table1", new String [] {"2"}); testEval(schema, "table1", "1,2,3", "SELECT CASE col3 WHEN 1 THEN NULL WHEN 2 THEN 2 ELSE 3 END FROM table1", new String [] {"3"}); testEval(schema, "table1", "1,2,3", "SELECT CASE col1 WHEN 1 THEN 1 WHEN 2 THEN 2 ELSE NULL END FROM table1", new String [] {"1"}); testEval(schema, "table1", "1,2,3", "SELECT CASE col2 WHEN 1 THEN NULL WHEN 2 THEN 2 ELSE NULL END FROM table1", new String [] {"2"}); testEval(schema, "table1", "1,2,3", "SELECT CASE col3 WHEN 1 THEN NULL WHEN 2 THEN 2 ELSE NULL END FROM table1", new String [] {NullDatum.get().toString()}); }
testSimpleEval("select (1::int8 > null) is null", new String[] {"t"}); testSimpleEval("select 1 = null;", new String [] {NullDatum.get().toString()}); testSimpleEval("select 1 <> null;", new String [] {NullDatum.get().toString()}); testSimpleEval("select 1 > null;", new String [] {NullDatum.get().toString()}); testSimpleEval("select 1 >= null;", new String [] {NullDatum.get().toString()}); testSimpleEval("select 1 < null;", new String [] {NullDatum.get().toString()}); testSimpleEval("select 1 <= null;", new String [] {NullDatum.get().toString()});
@Test public void testCoalesceText() throws Exception { testSimpleEval("select coalesce('value1', 'value2');", new String[]{"value1"}); testSimpleEval("select coalesce(null, 'value2');", new String[]{"value2"}); testSimpleEval("select coalesce(null, null, 'value3');", new String[]{"value3"}); testSimpleEval("select coalesce('value1', null, 'value3');", new String[]{"value1"}); testSimpleEval("select coalesce(null, 'value2', 'value3');", new String[]{"value2"}); testSimpleEval("select coalesce('value1');", new String[]{"value1"}); testSimpleEval("select coalesce(null);", new String[]{NullDatum.get().toString()}); //no matched function try { testSimpleEval("select coalesce(null, 2, 'value3');", new String[]{"2"}); fail("coalesce(NULL, INT, TEXT) not defined. So should throw exception."); } catch (UndefinedFunctionException e) { //success } }
@Test public void testCoalesceLong() throws Exception { testSimpleEval("select coalesce(1, 2);", new String[]{"1"}); testSimpleEval("select coalesce(null, 2);", new String[]{"2"}); testSimpleEval("select coalesce(null, null, 3);", new String[]{"3"}); testSimpleEval("select coalesce(1, null, 3);", new String[]{"1"}); testSimpleEval("select coalesce(null, 2, 3);", new String[]{"2"}); testSimpleEval("select coalesce(1);", new String[]{"1"}); testSimpleEval("select coalesce(null);", new String[]{NullDatum.get().toString()}); //no matched function try { testSimpleEval("select coalesce(null, 'value2', 3);", new String[]{"2"}); fail("coalesce(NULL, TEXT, INT) not defined. So should throw exception."); } catch (UndefinedFunctionException e) { //success } }
@Test public void testLike() throws TajoException { Schema schema = SchemaBuilder.builder() .add("col1", TEXT) .build(); // test for null values testEval(schema, "table1", "\\NULL,", "select col1 like 'a%' from table1", new String[]{NullDatum.get().toString()}); testSimpleEval("select null like 'a%'", new String[]{NullDatum.get().toString()}); testEval(schema, "table1", "abc", "select col1 like '%c' from table1", new String[]{"t"}); testEval(schema, "table1", "abc", "select col1 like 'a%' from table1", new String[]{"t"}); testEval(schema, "table1", "abc", "select col1 like '_bc' from table1", new String[]{"t"}); testEval(schema, "table1", "abc", "select col1 like 'ab_' from table1", new String[]{"t"}); testEval(schema, "table1", "abc", "select col1 like '_b_' from table1", new String[]{"t"}); testEval(schema, "table1", "abc", "select col1 like '%b%' from table1", new String[]{"t"}); // test for escaping regular expressions testEval(schema, "table1", "abc", "select col1 not like '.bc' from table1", new String[]{"t"}); testEval(schema, "table1", "abc", "select col1 not like '.*bc' from table1", new String[]{"t"}); testEval(schema, "table1", "abc", "select col1 not like '.bc' from table1", new String[]{"t"}); testEval(schema, "table1", "abc", "select col1 not like '*bc' from table1", new String[]{"t"}); // test for case sensitive testEval(schema, "table1", "abc", "select col1 not like '%C' from table1", new String[]{"t"}); testEval(schema, "table1", "abc", "select col1 not like 'A%' from table1", new String[]{"t"}); testEval(schema, "table1", "abc", "select col1 not like '_BC' from table1", new String[]{"t"}); testEval(schema, "table1", "abc", "select col1 not like '_C_' from table1", new String[]{"t"}); }
@Test public void testCoalesceDouble() throws Exception { testSimpleEval("select coalesce(1.0, 2.0);", new String[]{"1.0"}); testSimpleEval("select coalesce(null, 2.0);", new String[]{"2.0"}); testSimpleEval("select coalesce(null, null, 3.0);", new String[]{"3.0"}); testSimpleEval("select coalesce(1.0, null, 3.0);", new String[]{"1.0"}); testSimpleEval("select coalesce(null, 2.0, 3.0);", new String[]{"2.0"}); testSimpleEval("select coalesce(1.0);", new String[]{"1.0"}); testSimpleEval("select coalesce(null);", new String[]{NullDatum.get().toString()}); //no matched function try { testSimpleEval("select coalesce('value1', null, 3.0);", new String[]{"1.0"}); fail("coalesce(TEXT, NULL, FLOAT8) not defined. So should throw exception."); } catch (UndefinedFunctionException e) { // success } try { testSimpleEval("select coalesce(null, 'value2', 3.0);", new String[]{"2.0"}); fail("coalesce(NULL, TEXT, FLOAT8) not defined. So should throw exception."); } catch (UndefinedFunctionException e) { //success } }
.build(); testEval(schema, "table1", ",", "select round(col1, col2) from table1", new String[]{NullDatum.get().toString()});