use of org.apache.calcite.sql.test.SqlOperatorFixture in project calcite by apache.
the class SqlOperatorTest method testConcatOperator.
@Test
void testConcatOperator() {
final SqlOperatorFixture f = fixture();
f.setFor(SqlStdOperatorTable.CONCAT, VmName.EXPAND);
f.checkString(" 'a'||'b' ", "ab", "CHAR(2) NOT NULL");
f.checkNull(" 'a' || cast(null as char(2)) ");
f.checkNull(" cast(null as char(2)) || 'b' ");
f.checkNull(" cast(null as char(1)) || cast(null as char(2)) ");
f.checkString(" x'fe'||x'df' ", "fedf", "BINARY(2) NOT NULL");
f.checkString(" cast('fe' as char(2)) || cast('df' as varchar)", "fedf", "VARCHAR NOT NULL");
// Precision is larger than VARCHAR allows, so result is unbounded
f.checkString(" cast('fe' as char(2)) || cast('df' as varchar(65535))", "fedf", "VARCHAR NOT NULL");
f.checkString(" cast('fe' as char(2)) || cast('df' as varchar(33333))", "fedf", "VARCHAR(33335) NOT NULL");
f.checkNull("x'ff' || cast(null as varbinary)");
f.checkNull(" cast(null as ANY) || cast(null as ANY) ");
f.checkString("cast('a' as varchar) || cast('b' as varchar) " + "|| cast('c' as varchar)", "abc", "VARCHAR NOT NULL");
}
use of org.apache.calcite.sql.test.SqlOperatorFixture in project calcite by apache.
the class SqlOperatorTest method testJsonPredicate.
@Test
void testJsonPredicate() {
final SqlOperatorFixture f = fixture();
f.checkBoolean("'{}' is json value", true);
f.checkBoolean("'{]' is json value", false);
f.checkBoolean("'{}' is json object", true);
f.checkBoolean("'[]' is json object", false);
f.checkBoolean("'{}' is json array", false);
f.checkBoolean("'[]' is json array", true);
f.checkBoolean("'100' is json scalar", true);
f.checkBoolean("'[]' is json scalar", false);
f.checkBoolean("'{}' is not json value", false);
f.checkBoolean("'{]' is not json value", true);
f.checkBoolean("'{}' is not json object", false);
f.checkBoolean("'[]' is not json object", true);
f.checkBoolean("'{}' is not json array", true);
f.checkBoolean("'[]' is not json array", false);
f.checkBoolean("'100' is not json scalar", false);
f.checkBoolean("'[]' is not json scalar", true);
}
use of org.apache.calcite.sql.test.SqlOperatorFixture in project calcite by apache.
the class SqlOperatorTest method testCardinalityFunc.
@Test
void testCardinalityFunc() {
final SqlOperatorFixture f = fixture();
f.setFor(SqlStdOperatorTable.CARDINALITY, VM_FENNEL, VM_JAVA);
f.checkScalarExact("cardinality(multiset[cast(null as integer),2])", 2);
if (!f.brokenTestsEnabled()) {
return;
}
// applied to array
f.checkScalarExact("cardinality(array['foo', 'bar'])", 2);
// applied to map
f.checkScalarExact("cardinality(map['foo', 1, 'bar', 2])", 2);
}
use of org.apache.calcite.sql.test.SqlOperatorFixture in project calcite by apache.
the class SqlOperatorTest method testYear.
@Test
void testYear() {
final SqlOperatorFixture f = fixture();
f.setFor(SqlStdOperatorTable.YEAR, VM_FENNEL, VM_JAVA);
f.checkScalar("year(date '2008-1-23')", "2008", "BIGINT NOT NULL");
f.checkNull("year(cast(null as date))");
}
use of org.apache.calcite.sql.test.SqlOperatorFixture in project calcite by apache.
the class SqlOperatorTest method testTruncateFunc.
@Test
void testTruncateFunc() {
final SqlOperatorFixture f = fixture();
f.setFor(SqlStdOperatorTable.TRUNCATE, VmName.EXPAND);
f.checkType("truncate(42, -1)", "INTEGER NOT NULL");
f.checkType("truncate(cast(42 as float), 1)", "FLOAT NOT NULL");
f.checkType("truncate(case when false then 42 else null end, -1)", "INTEGER");
f.enableTypeCoercion(false).checkFails("^truncate('abc', 'def')^", "Cannot apply 'TRUNCATE' to arguments of type " + "'TRUNCATE\\(<CHAR\\(3\\)>, <CHAR\\(3\\)>\\)'\\. Supported " + "form\\(s\\): 'TRUNCATE\\(<NUMERIC>, <INTEGER>\\)'", false);
f.checkType("truncate('abc', 'def')", "DECIMAL(19, 9) NOT NULL");
f.checkScalar("truncate(42, -1)", 40, "INTEGER NOT NULL");
f.checkScalar("truncate(cast(42.345 as decimal(2, 3)), 2)", BigDecimal.valueOf(4234, 2), "DECIMAL(2, 3) NOT NULL");
f.checkScalar("truncate(cast(-42.345 as decimal(2, 3)), 2)", BigDecimal.valueOf(-4234, 2), "DECIMAL(2, 3) NOT NULL");
f.checkNull("truncate(cast(null as integer), 1)");
f.checkNull("truncate(cast(null as double), 1)");
f.checkNull("truncate(43.21, cast(null as integer))");
f.checkScalar("truncate(42)", 42, "INTEGER NOT NULL");
f.checkScalar("truncate(42.324)", BigDecimal.valueOf(42, 0), "DECIMAL(5, 3) NOT NULL");
f.checkScalar("truncate(cast(42.324 as float))", 42F, "FLOAT NOT NULL");
f.checkScalar("truncate(cast(42.345 as decimal(2, 3)))", BigDecimal.valueOf(42, 0), "DECIMAL(2, 3) NOT NULL");
f.checkNull("truncate(cast(null as integer))");
f.checkNull("truncate(cast(null as double))");
}
Aggregations