Search in sources :

Example 6 with SqlOperatorFixture

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

the class SqlOperatorTest method testCeilFunc.

@Test
void testCeilFunc() {
    final SqlOperatorFixture f = fixture();
    f.setFor(SqlStdOperatorTable.CEIL, VM_FENNEL);
    f.checkScalarApprox("ceil(10.1e0)", "DOUBLE NOT NULL", isExactly(11));
    f.checkScalarApprox("ceil(cast(-11.2e0 as real))", "REAL NOT NULL", isExactly(-11));
    f.checkScalarExact("ceil(100)", "INTEGER NOT NULL", "100");
    f.checkScalarExact("ceil(1.3)", "DECIMAL(2, 0) NOT NULL", "2");
    f.checkScalarExact("ceil(-1.7)", "DECIMAL(2, 0) NOT NULL", "-1");
    f.checkNull("ceiling(cast(null as decimal(2,0)))");
    f.checkNull("ceiling(cast(null as double))");
}
Also used : SqlOperatorFixture(org.apache.calcite.sql.test.SqlOperatorFixture) Test(org.junit.jupiter.api.Test)

Example 7 with SqlOperatorFixture

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

the class SqlOperatorTest method testVarFunc.

@Test
void testVarFunc() {
    final SqlOperatorFixture f = fixture();
    f.setFor(SqlStdOperatorTable.VARIANCE, VM_EXPAND);
    f.checkFails("variance(^*^)", "Unknown identifier '\\*'", false);
    f.enableTypeCoercion(false).checkFails("^variance(cast(null as varchar(2)))^", "(?s)Cannot apply 'VARIANCE' to arguments of type " + "'VARIANCE\\(<VARCHAR\\(2\\)>\\)'\\. Supported form\\(s\\): " + "'VARIANCE\\(<NUMERIC>\\)'.*", false);
    f.checkType("variance(cast(null as varchar(2)))", "DECIMAL(19, 9)");
    f.checkType("variance(CAST(NULL AS INTEGER))", "INTEGER");
    f.checkAggType("variance(DISTINCT 1.5)", "DECIMAL(2, 1) NOT NULL");
    final String[] values = { "0", "CAST(null AS FLOAT)", "3", "3" };
    if (!f.brokenTestsEnabled()) {
        return;
    }
    // verified on Oracle 10g
    f.checkAgg("variance(x)", values, isExactly(3d));
    // Oracle does not allow distinct
    f.checkAgg(// Oracle does not allow distinct
    "variance(DISTINCT x)", values, isWithin(4.5d, 0.0001d));
    f.checkAgg("variance(DISTINCT CASE x WHEN 0 THEN NULL ELSE -1 END)", values, isNullValue());
    // with one value
    f.checkAgg("variance(x)", new String[] { "5" }, isNullValue());
    // with zero values
    f.checkAgg("variance(x)", new String[] {}, isNullValue());
}
Also used : SqlOperatorFixture(org.apache.calcite.sql.test.SqlOperatorFixture) TimestampString(org.apache.calcite.util.TimestampString) SqlString(org.apache.calcite.sql.util.SqlString) Test(org.junit.jupiter.api.Test)

Example 8 with SqlOperatorFixture

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

the class SqlOperatorTest method testInOperator.

@Test
void testInOperator() {
    final SqlOperatorFixture f = fixture();
    f.setFor(SqlStdOperatorTable.IN, VM_EXPAND);
    f.checkBoolean("1 in (0, 1, 2)", true);
    f.checkBoolean("3 in (0, 1, 2)", false);
    f.checkBoolean("cast(null as integer) in (0, 1, 2)", null);
    f.checkBoolean("cast(null as integer) in (0, cast(null as integer), 2)", null);
    if (Bug.FRG327_FIXED) {
        f.checkBoolean("cast(null as integer) in (0, null, 2)", null);
        f.checkBoolean("1 in (0, null, 2)", null);
    }
    if (!f.brokenTestsEnabled()) {
        return;
    }
    // AND has lower precedence than IN
    f.checkBoolean("false and true in (false, false)", false);
    if (!Bug.TODO_FIXED) {
        return;
    }
    f.checkFails("'foo' in (^)^", "(?s).*Encountered \"\\)\" at .*", false);
}
Also used : SqlOperatorFixture(org.apache.calcite.sql.test.SqlOperatorFixture) Test(org.junit.jupiter.api.Test)

Example 9 with SqlOperatorFixture

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

the class SqlOperatorTest method testLogFunc.

@Test
void testLogFunc() {
    final SqlOperatorFixture f = fixture();
    f.setFor(SqlStdOperatorTable.LOG10, VmName.EXPAND);
    f.checkScalarApprox("log10(10)", "DOUBLE NOT NULL", isWithin(1.0, 0.000001));
    f.checkScalarApprox("log10(100.0)", "DOUBLE NOT NULL", isWithin(2.0, 0.000001));
    f.checkScalarApprox("log10(cast(10e8 as double))", "DOUBLE NOT NULL", isWithin(9.0, 0.000001));
    f.checkScalarApprox("log10(cast(10e2 as float))", "DOUBLE NOT NULL", isWithin(3.0, 0.000001));
    f.checkScalarApprox("log10(cast(10e-3 as real))", "DOUBLE NOT NULL", isWithin(-2.0, 0.000001));
    f.checkNull("log10(cast(null as real))");
}
Also used : SqlOperatorFixture(org.apache.calcite.sql.test.SqlOperatorFixture) Test(org.junit.jupiter.api.Test)

Example 10 with SqlOperatorFixture

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

the class SqlOperatorTest method testCurrentRoleFunc.

@Test
void testCurrentRoleFunc() {
    final SqlOperatorFixture f = fixture();
    f.setFor(SqlStdOperatorTable.CURRENT_ROLE, VM_FENNEL);
    // By default, the CURRENT_ROLE function returns
    // the empty string because a role has to be set explicitly.
    f.checkString("CURRENT_ROLE", "", "VARCHAR(2000) NOT NULL");
}
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