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))");
}
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());
}
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);
}
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))");
}
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");
}
Aggregations