use of org.apache.calcite.sql.test.SqlOperatorFixture in project calcite by apache.
the class SqlOperatorTest method testRandSeedFunc.
@Test
void testRandSeedFunc() {
final SqlOperatorFixture f = fixture();
f.setFor(SqlStdOperatorTable.RAND, VmName.EXPAND);
f.checkScalarApprox("rand(1)", "DOUBLE NOT NULL", isWithin(0.6016, 0.0001));
f.checkScalarApprox("rand(2)", "DOUBLE NOT NULL", isWithin(0.4728, 0.0001));
}
use of org.apache.calcite.sql.test.SqlOperatorFixture in project calcite by apache.
the class SqlOperatorTest method testRegrSxxFunc.
@Test
void testRegrSxxFunc() {
final SqlOperatorFixture f = fixture();
f.setFor(SqlStdOperatorTable.REGR_SXX, VM_EXPAND);
f.checkFails("regr_sxx(^*^)", "Unknown identifier '\\*'", false);
f.enableTypeCoercion(false).checkFails("^regr_sxx(cast(null as varchar(2))," + " cast(null as varchar(2)))^", "(?s)Cannot apply 'REGR_SXX' to arguments of type " + "'REGR_SXX\\(<VARCHAR\\(2\\)>, <VARCHAR\\(2\\)>\\)'\\. " + "Supported form\\(s\\): " + "'REGR_SXX\\(<NUMERIC>, <NUMERIC>\\)'.*", false);
f.checkType("regr_sxx(cast(null as varchar(2)), cast(null as varchar(2)))", "DECIMAL(19, 9)");
f.checkType("regr_sxx(CAST(NULL AS INTEGER), CAST(NULL AS INTEGER))", "INTEGER");
f.checkAggType("regr_sxx(1.5, 2.5)", "DECIMAL(2, 1) NOT NULL");
if (!f.brokenTestsEnabled()) {
return;
}
// with zero values
f.checkAgg("regr_sxx(x)", new String[] {}, isNullValue());
}
use of org.apache.calcite.sql.test.SqlOperatorFixture in project calcite by apache.
the class SqlOperatorTest method testPiFunc.
@Test
void testPiFunc() {
final SqlOperatorFixture f = fixture();
f.setFor(SqlStdOperatorTable.PI, VmName.EXPAND);
f.checkScalarApprox("PI", "DOUBLE NOT NULL", isWithin(3.1415d, 0.0001d));
f.checkFails("^PI()^", "No match found for function signature PI\\(\\)", false);
// assert that PI function is not dynamic [CALCITE-2750]
assertThat("PI operator should not be identified as dynamic function", PI.isDynamicFunction(), is(false));
}
use of org.apache.calcite.sql.test.SqlOperatorFixture in project calcite by apache.
the class SqlOperatorTest method testModOperator.
@Test
void testModOperator() {
// "%" is allowed under MYSQL_5 SQL conformance level
final SqlOperatorFixture f0 = fixture();
final SqlOperatorFixture f = f0.withConformance(SqlConformanceEnum.MYSQL_5);
f.setFor(SqlStdOperatorTable.PERCENT_REMAINDER);
f.checkScalarExact("4%2", 0);
f.checkScalarExact("8%5", 3);
f.checkScalarExact("-12%7", -5);
f.checkScalarExact("-12%-7", -5);
f.checkScalarExact("12%-7", 5);
f.checkScalarExact("cast(12 as tinyint) % cast(-7 as tinyint)", "TINYINT NOT NULL", "5");
if (!DECIMAL) {
return;
}
f.checkScalarExact("cast(9 as decimal(2, 0)) % 7", "INTEGER NOT NULL", "2");
f.checkScalarExact("7 % cast(9 as decimal(2, 0))", "DECIMAL(2, 0) NOT NULL", "7");
f.checkScalarExact("cast(-9 as decimal(2, 0)) % cast(7 as decimal(1, 0))", "DECIMAL(1, 0) NOT NULL", "-2");
}
use of org.apache.calcite.sql.test.SqlOperatorFixture in project calcite by apache.
the class SqlOperatorTest method testCastToBoolean.
@Test
void testCastToBoolean() {
final SqlOperatorFixture f = fixture();
f.setFor(SqlStdOperatorTable.CAST, VmName.EXPAND);
// string to boolean
f.checkBoolean("cast('true' as boolean)", true);
f.checkBoolean("cast('false' as boolean)", false);
f.checkBoolean("cast(' trUe' as boolean)", true);
f.checkBoolean("cast(' tr' || 'Ue' as boolean)", true);
f.checkBoolean("cast(' fALse' as boolean)", false);
f.checkFails("cast('unknown' as boolean)", INVALID_CHAR_MESSAGE, true);
f.checkBoolean("cast(cast('true' as varchar(10)) as boolean)", true);
f.checkBoolean("cast(cast('false' as varchar(10)) as boolean)", false);
f.checkFails("cast(cast('blah' as varchar(10)) as boolean)", INVALID_CHAR_MESSAGE, true);
}
Aggregations