Search in sources :

Example 26 with SqlOperatorFixture

use of org.apache.calcite.sql.test.SqlOperatorFixture in project calcite by apache.

the class SqlOperatorTest method testConcatFunc.

@Test
void testConcatFunc() {
    final SqlOperatorFixture f = fixture();
    checkConcatFunc(f.withLibrary(SqlLibrary.MYSQL));
    checkConcatFunc(f.withLibrary(SqlLibrary.POSTGRESQL));
    checkConcat2Func(f.withLibrary(SqlLibrary.ORACLE));
}
Also used : SqlOperatorFixture(org.apache.calcite.sql.test.SqlOperatorFixture) Test(org.junit.jupiter.api.Test)

Example 27 with SqlOperatorFixture

use of org.apache.calcite.sql.test.SqlOperatorFixture in project calcite by apache.

the class SqlOperatorTest method testNotSubMultisetOfOperator.

@Test
void testNotSubMultisetOfOperator() {
    final SqlOperatorFixture f = fixture();
    f.setFor(SqlStdOperatorTable.NOT_SUBMULTISET_OF, VM_FENNEL, VM_JAVA);
    f.checkBoolean("multiset[2] not submultiset of multiset[1]", true);
    f.checkBoolean("multiset[1] not submultiset of multiset[1]", false);
    f.checkBoolean("multiset[1, 2] not submultiset of multiset[1]", true);
    f.checkBoolean("multiset[1] not submultiset of multiset[1, 2]", false);
    f.checkBoolean("multiset[1, 2] not submultiset of multiset[1, 2]", false);
    f.checkBoolean("multiset['a', 'b'] not submultiset of " + "multiset['c', 'd', 's', 'a']", true);
    f.checkBoolean("multiset['a', 'd'] not submultiset of " + "multiset['c', 's', 'a', 'w', 'd']", false);
    f.checkBoolean("multiset['q', 'a'] not submultiset of " + "multiset['a', 'q']", false);
}
Also used : SqlOperatorFixture(org.apache.calcite.sql.test.SqlOperatorFixture) Test(org.junit.jupiter.api.Test)

Example 28 with SqlOperatorFixture

use of org.apache.calcite.sql.test.SqlOperatorFixture in project calcite by apache.

the class SqlOperatorTest method testPercentRankFunc.

@Test
void testPercentRankFunc() {
    final SqlOperatorFixture f = fixture();
    f.setFor(SqlStdOperatorTable.PERCENT_RANK, VM_FENNEL, VM_JAVA);
}
Also used : SqlOperatorFixture(org.apache.calcite.sql.test.SqlOperatorFixture) Test(org.junit.jupiter.api.Test)

Example 29 with SqlOperatorFixture

use of org.apache.calcite.sql.test.SqlOperatorFixture in project calcite by apache.

the class SqlOperatorTest method testHour.

@Test
void testHour() {
    final SqlOperatorFixture f = fixture();
    f.setFor(SqlStdOperatorTable.HOUR, VM_FENNEL, VM_JAVA);
    f.checkScalar("hour(timestamp '2008-1-23 12:34:56')", "12", "BIGINT NOT NULL");
    f.checkNull("hour(cast(null as timestamp))");
}
Also used : SqlOperatorFixture(org.apache.calcite.sql.test.SqlOperatorFixture) Test(org.junit.jupiter.api.Test)

Example 30 with SqlOperatorFixture

use of org.apache.calcite.sql.test.SqlOperatorFixture in project calcite by apache.

the class SqlOperatorTest method testCastToString.

@Test
void testCastToString() {
    final SqlOperatorFixture f = fixture();
    f.setFor(SqlStdOperatorTable.CAST, VmName.EXPAND);
    f.checkCastToString("cast(cast('abc' as char(4)) as varchar(6))", null, "abc ");
    // integer
    f.checkCastToString("123", "CHAR(3)", "123");
    f.checkCastToString("0", "CHAR", "0");
    f.checkCastToString("-123", "CHAR(4)", "-123");
    // decimal
    f.checkCastToString("123.4", "CHAR(5)", "123.4");
    f.checkCastToString("-0.0", "CHAR(2)", ".0");
    f.checkCastToString("-123.4", "CHAR(6)", "-123.4");
    f.checkString("cast(1.29 as varchar(10))", "1.29", "VARCHAR(10) NOT NULL");
    f.checkString("cast(.48 as varchar(10))", ".48", "VARCHAR(10) NOT NULL");
    if (Bug.CALCITE_2539_FIXED) {
        f.checkFails("cast(2.523 as char(2))", STRING_TRUNC_MESSAGE, true);
    }
    f.checkString("cast(-0.29 as varchar(10))", "-.29", "VARCHAR(10) NOT NULL");
    f.checkString("cast(-1.29 as varchar(10))", "-1.29", "VARCHAR(10) NOT NULL");
    // approximate
    f.checkCastToString("1.23E45", "CHAR(7)", "1.23E45");
    f.checkCastToString("CAST(0 AS DOUBLE)", "CHAR(3)", "0E0");
    f.checkCastToString("-1.20e-07", "CHAR(7)", "-1.2E-7");
    f.checkCastToString("cast(0e0 as varchar(5))", "CHAR(3)", "0E0");
    if (TODO) {
        f.checkCastToString("cast(-45e-2 as varchar(17))", "CHAR(7)", "-4.5E-1");
    }
    if (TODO) {
        f.checkCastToString("cast(4683442.3432498375e0 as varchar(20))", "CHAR(19)", "4.683442343249838E6");
    }
    if (TODO) {
        f.checkCastToString("cast(-0.1 as real)", "CHAR(5)", "-1E-1");
    }
    if (Bug.CALCITE_2539_FIXED) {
        f.checkFails("cast(1.3243232e0 as varchar(4))", STRING_TRUNC_MESSAGE, true);
        f.checkFails("cast(1.9e5 as char(4))", STRING_TRUNC_MESSAGE, true);
    }
    // string
    f.checkCastToString("'abc'", "CHAR(1)", "a");
    f.checkCastToString("'abc'", "CHAR(3)", "abc");
    f.checkCastToString("cast('abc' as varchar(6))", "CHAR(3)", "abc");
    f.checkCastToString("cast(' abc  ' as varchar(10))", null, " abc  ");
    f.checkCastToString("cast(cast('abc' as char(4)) as varchar(6))", null, "abc ");
    f.checkString("cast(cast('a' as char(2)) as varchar(3)) || 'x' ", "a x", "VARCHAR(4) NOT NULL");
    f.checkString("cast(cast('a' as char(3)) as varchar(5)) || 'x' ", "a  x", "VARCHAR(6) NOT NULL");
    f.checkString("cast('a' as char(3)) || 'x'", "a  x", "CHAR(4) NOT NULL");
    f.checkScalar("char_length(cast(' x ' as char(4)))", 4, "INTEGER NOT NULL");
    f.checkScalar("char_length(cast(' x ' as varchar(3)))", 3, "INTEGER NOT NULL");
    f.checkScalar("char_length(cast(' x ' as varchar(4)))", 3, "INTEGER NOT NULL");
    f.checkScalar("char_length(cast(cast(' x ' as char(4)) as varchar(5)))", 4, "INTEGER NOT NULL");
    f.checkScalar("char_length(cast(' x ' as varchar(3)))", 3, "INTEGER NOT NULL");
    // date & time
    f.checkCastToString("date '2008-01-01'", "CHAR(10)", "2008-01-01");
    f.checkCastToString("time '1:2:3'", "CHAR(8)", "01:02:03");
    f.checkCastToString("timestamp '2008-1-1 1:2:3'", "CHAR(19)", "2008-01-01 01:02:03");
    f.checkCastToString("timestamp '2008-1-1 1:2:3'", "VARCHAR(30)", "2008-01-01 01:02:03");
    f.checkCastToString("interval '3-2' year to month", "CHAR(5)", "+3-02");
    f.checkCastToString("interval '32' month", "CHAR(3)", "+32");
    f.checkCastToString("interval '1 2:3:4' day to second", "CHAR(11)", "+1 02:03:04");
    f.checkCastToString("interval '1234.56' second(4,2)", "CHAR(8)", "+1234.56");
    f.checkCastToString("interval '60' day", "CHAR(8)", "+60     ");
    // boolean
    f.checkCastToString("True", "CHAR(4)", "TRUE");
    f.checkCastToString("True", "CHAR(6)", "TRUE  ");
    f.checkCastToString("True", "VARCHAR(6)", "TRUE");
    f.checkCastToString("False", "CHAR(5)", "FALSE");
    if (Bug.CALCITE_2539_FIXED) {
        f.checkFails("cast(true as char(3))", INVALID_CHAR_MESSAGE, true);
        f.checkFails("cast(false as char(4))", INVALID_CHAR_MESSAGE, true);
        f.checkFails("cast(true as varchar(3))", INVALID_CHAR_MESSAGE, true);
        f.checkFails("cast(false as varchar(4))", INVALID_CHAR_MESSAGE, true);
    }
}
Also used : SqlOperatorFixture(org.apache.calcite.sql.test.SqlOperatorFixture) Test(org.junit.jupiter.api.Test)

Aggregations

SqlOperatorFixture (org.apache.calcite.sql.test.SqlOperatorFixture)297 Test (org.junit.jupiter.api.Test)292 SqlString (org.apache.calcite.sql.util.SqlString)43 TimestampString (org.apache.calcite.util.TimestampString)42 RelDataType (org.apache.calcite.rel.type.RelDataType)2 SqlLiteral (org.apache.calcite.sql.SqlLiteral)2 Disabled (org.junit.jupiter.api.Disabled)2 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Strong (org.apache.calcite.plan.Strong)1 RelDataTypeFactory (org.apache.calcite.rel.type.RelDataTypeFactory)1 Hook (org.apache.calcite.runtime.Hook)1 SqlAggFunction (org.apache.calcite.sql.SqlAggFunction)1 SqlCall (org.apache.calcite.sql.SqlCall)1 SqlCallBinding (org.apache.calcite.sql.SqlCallBinding)1 SqlJdbcFunctionCall (org.apache.calcite.sql.SqlJdbcFunctionCall)1 SqlNodeList (org.apache.calcite.sql.SqlNodeList)1 SqlOperandCountRange (org.apache.calcite.sql.SqlOperandCountRange)1