use of org.apache.calcite.sql.util.SqlString in project calcite by apache.
the class JdbcTable method scan.
public Enumerable<Object[]> scan(DataContext root) {
final JavaTypeFactory typeFactory = root.getTypeFactory();
final SqlString sql = generateSql();
return ResultSetEnumerable.of(jdbcSchema.getDataSource(), sql.getSql(), JdbcUtils.ObjectArrayRowBuilder.factory(fieldClasses(typeFactory)));
}
use of org.apache.calcite.sql.util.SqlString in project calcite by apache.
the class SqlOperatorBaseTest method testLiteralBeyondLimit.
/**
* 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 testLiteralBeyondLimit() {
tester.setFor(SqlStdOperatorTable.CAST);
final List<RelDataType> types = SqlLimitsTest.getTypes(tester.getValidator().getTypeFactory());
for (RelDataType type : types) {
for (Object o : getValues((BasicSqlType) type, false)) {
SqlLiteral literal = type.getSqlTypeName().createLiteral(o, SqlParserPos.ZERO);
SqlString literalString = literal.toSqlString(AnsiSqlDialect.DEFAULT);
if ((type.getSqlTypeName() == SqlTypeName.BIGINT) || ((type.getSqlTypeName() == SqlTypeName.DECIMAL) && (type.getPrecision() == 19))) {
// Values which are too large to be literals fail at
// validate time.
tester.checkFails("CAST(^" + literalString + "^ AS " + type + ")", "Numeric literal '.*' out of range", false);
} else if ((type.getSqlTypeName() == SqlTypeName.CHAR) || (type.getSqlTypeName() == SqlTypeName.VARCHAR) || (type.getSqlTypeName() == SqlTypeName.BINARY) || (type.getSqlTypeName() == SqlTypeName.VARBINARY)) {
// Casting overlarge string/binary values do not fail -
// they are truncated. See testCastTruncates().
} else {
// Value outside legal bound should fail at runtime (not
// validate time).
//
// NOTE: Because Java and Fennel calcs give
// different errors, the pattern hedges its bets.
tester.checkFails("CAST(" + literalString + " AS " + type + ")", "(?s).*(Overflow during calculation or cast\\.|Code=22003).*", true);
}
}
}
}
Aggregations