Search in sources :

Example 56 with RelDataType

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;
            }
        }
    }
}
Also used : RelDataType(org.apache.calcite.rel.type.RelDataType) TimestampString(org.apache.calcite.util.TimestampString) SqlString(org.apache.calcite.sql.util.SqlString) SqlLiteral(org.apache.calcite.sql.SqlLiteral) SqlString(org.apache.calcite.sql.util.SqlString) SqlLimitsTest(org.apache.calcite.test.SqlLimitsTest) Test(org.junit.Test)

Example 57 with RelDataType

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());
        }
    }
}
Also used : Charset(java.nio.charset.Charset) RelDataType(org.apache.calcite.rel.type.RelDataType)

Example 58 with RelDataType

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);
}
Also used : RelDataType(org.apache.calcite.rel.type.RelDataType)

Example 59 with RelDataType

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);
}
Also used : RelDataType(org.apache.calcite.rel.type.RelDataType)

Example 60 with RelDataType

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();
}
Also used : RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) RelDataType(org.apache.calcite.rel.type.RelDataType)

Aggregations

RelDataType (org.apache.calcite.rel.type.RelDataType)834 RexNode (org.apache.calcite.rex.RexNode)268 ArrayList (java.util.ArrayList)214 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)209 RelNode (org.apache.calcite.rel.RelNode)153 SqlNode (org.apache.calcite.sql.SqlNode)143 RelDataTypeFactory (org.apache.calcite.rel.type.RelDataTypeFactory)123 RexBuilder (org.apache.calcite.rex.RexBuilder)118 Test (org.junit.Test)62 ImmutableList (com.google.common.collect.ImmutableList)58 RexInputRef (org.apache.calcite.rex.RexInputRef)57 List (java.util.List)51 SqlIdentifier (org.apache.calcite.sql.SqlIdentifier)45 RexLiteral (org.apache.calcite.rex.RexLiteral)44 SqlNodeList (org.apache.calcite.sql.SqlNodeList)42 ImmutableBitSet (org.apache.calcite.util.ImmutableBitSet)40 AggregateCall (org.apache.calcite.rel.core.AggregateCall)39 BitString (org.apache.calcite.util.BitString)38 BigDecimal (java.math.BigDecimal)35 RelBuilder (org.apache.calcite.tools.RelBuilder)34