use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataType in project calcite by apache.
the class SqlOperatorBaseTest method testLiteralAtLimit.
/**
* Tests that CAST fails when given a value just outside the valid range for
* that type. For example,
*
* <ul>
* <li>CAST(-200 AS TINYINT) fails because the value is less than -128;
* <li>CAST(1E-999 AS FLOAT) fails because the value underflows;
* <li>CAST(123.4567891234567 AS FLOAT) fails because the value loses
* precision.
* </ul>
*/
@Test
public void testLiteralAtLimit() {
tester.setFor(SqlStdOperatorTable.CAST);
if (!enable) {
return;
}
final List<RelDataType> types = SqlLimitsTest.getTypes(tester.getValidator().getTypeFactory());
for (RelDataType type : types) {
for (Object o : getValues((BasicSqlType) type, true)) {
SqlLiteral literal = type.getSqlTypeName().createLiteral(o, SqlParserPos.ZERO);
SqlString literalString = literal.toSqlString(AnsiSqlDialect.DEFAULT);
final String expr = "CAST(" + literalString + " AS " + type + ")";
try {
tester.checkType(expr, type.getFullTypeString());
if (type.getSqlTypeName() == SqlTypeName.BINARY) {
// Casting a string/binary values may change the value.
// For example, CAST(X'AB' AS BINARY(2)) yields
// X'AB00'.
} else {
tester.checkScalar(expr + " = " + literalString, true, "BOOLEAN NOT NULL");
}
} catch (Error e) {
System.out.println("Failed for expr=[" + expr + "]");
throw e;
} catch (RuntimeException e) {
System.out.println("Failed for expr=[" + expr + "]");
throw e;
}
}
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataType in project calcite by apache.
the class SqlTesterImpl method checkCharset.
public void checkCharset(String expression, Charset expectedCharset) {
for (String sql : buildQueries(expression)) {
RelDataType actualType = getColumnType(sql);
Charset actualCharset = actualType.getCharset();
if (!expectedCharset.equals(actualCharset)) {
fail("\n" + "Expected=" + expectedCharset.name() + "\n" + " actual=" + actualCharset.name());
}
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataType in project calcite by apache.
the class SqlTesterImpl method checkResultType.
public void checkResultType(String sql, String expected) {
RelDataType actualType = getResultType(sql);
String actual = SqlTests.getTypeString(actualType);
assertEquals(expected, actual);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataType in project calcite by apache.
the class SqlTesterImpl method checkColumnType.
public void checkColumnType(String sql, String expected) {
RelDataType actualType = getColumnType(sql);
String actual = SqlTests.getTypeString(actualType);
assertEquals(expected, actual);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.type.RelDataType in project calcite by apache.
the class SqlTesterImpl method getColumnType.
public RelDataType getColumnType(String sql) {
RelDataType rowType = getResultType(sql);
final List<RelDataTypeField> fields = rowType.getFieldList();
assertEquals("expected query to return 1 field", 1, fields.size());
return fields.get(0).getType();
}
Aggregations