@Test public void testArthimeticOperators() { checkExp("1-2+3*4/5/6-7", "(((1 - 2) + (((3 * 4) / 5) / 6)) - 7)"); checkExp("power(2,3)", "POWER(2, 3)"); checkExp("aBs(-2.3e-2)", "ABS(-2.3E-2)"); checkExp("MOD(5 ,\t\f\r\n2)", "MOD(5, 2)"); checkExp("ln(5.43 )", "LN(5.43)"); checkExp("log10(- -.2 )", "LOG10((- -0.2))"); }
@Test public void testIdentifier() { checkExp("ab", "`AB`"); checkExp(" \"a \"\" b!c\"", "`a \" b!c`"); checkExpFails(" ^`^a \" b!c`", "(?s).*Encountered.*"); checkExp("\"x`y`z\"", "`x``y``z`"); checkExpFails("^`^x`y`z`", "(?s).*Encountered.*"); checkExp("myMap[field] + myArray[1 + 2]", "(`MYMAP`[`FIELD`] + `MYARRAY`[(1 + 2)])"); }
@Test public void testSubstring() { checkExp("substring('a' \n FROM \t 1)", "SUBSTRING('a' FROM 1)"); checkExp("substring('a' FROM 1 FOR 3)", "SUBSTRING('a' FROM 1 FOR 3)"); checkExp( "substring('a' FROM 'reg' FOR '\\')", "SUBSTRING('a' FROM 'reg' FOR '\\')"); checkExp( "substring('a', 'reg', '\\')", "SUBSTRING('a' FROM 'reg' FOR '\\')"); checkExp("substring('a', 1, 2)", "SUBSTRING('a' FROM 1 FOR 2)"); checkExp("substring('a' , 1)", "SUBSTRING('a' FROM 1)"); }
@Test public void testWindowReference() { checkExp("sum(sal) over (w)", "(SUM(`SAL`) OVER (`W`))"); // Only 1 window reference allowed checkExpFails( "sum(sal) over (w ^w1^ partition by deptno)", "(?s)Encountered \"w1\" at.*"); }
@Test public void testArthimeticOperators() { checkExp("1-2+3*4/5/6-7", "(((1 - 2) + (((3 * 4) / 5) / 6)) - 7)"); checkExp("power(2,3)", "POWER(2, 3)"); checkExp("aBs(-2.3e-2)", "ABS(-2.3E-2)"); checkExp("MOD(5 ,\t\f\r\n2)", "MOD(5, 2)"); checkExp("ln(5.43 )", "LN(5.43)"); checkExp("log10(- -.2 )", "LOG10((- -0.2))"); }
@Test public void testNullIf() { checkExp( "nullif(v1,v2)", "NULLIF(`V1`, `V2`)"); checkExpFails( "1 ^+^ nullif + 3", "(?s)Encountered \"\\+ nullif \\+\" at line 1, column 3.*"); }
@Test public void testArrayValueConstructor() { checkExp("array[1, 2]", "(ARRAY[1, 2])"); checkExp("array [1, 2]", "(ARRAY[1, 2])"); // with space // parser allows empty array; validator will reject it checkExp("array[]", "(ARRAY[])"); checkExp( "array[(1, 'a'), (2, 'b')]", "(ARRAY[(ROW(1, 'a')), (ROW(2, 'b'))])"); }
@Test public void testMultisetMixed() { checkExp( "multiset[1] MULTISET union b", "((MULTISET [1]) MULTISET UNION `B`)"); checkExp( "a MULTISET union b multiset intersect c multiset except d multiset union e", "(((`A` MULTISET UNION (`B` MULTISET INTERSECT `C`)) MULTISET EXCEPT `D`) MULTISET UNION `E`)"); }
@Test public void testEmbeddedTimestamp() { checkExp( "{ts '1998-10-22 16:22:34'}", "TIMESTAMP '1998-10-22 16:22:34'"); }
@Test public void testFunction() { check( "select substring('Eggs and ham', 1, 3 + 2) || ' benedict' from emp", "SELECT (SUBSTRING('Eggs and ham' FROM 1 FOR (3 + 2)) || ' benedict')\n" + "FROM `EMP`"); checkExp( "log10(1)\r\n+power(2, mod(\r\n3\n\t\t\f\n,ln(4))*log10(5)-6*log10(7/abs(8)+9))*power(10,11)", "(LOG10(1) + (POWER(2, ((MOD(3, LN(4)) * LOG10(5)) - (6 * LOG10(((7 / ABS(8)) + 9))))) * POWER(10, 11)))"); }