Search in sources :

Example 61 with SqlTypeName

use of org.apache.calcite.sql.type.SqlTypeName in project calcite by apache.

the class SqlTypeNameTest method testSqlxml.

@Test
void testSqlxml() {
    SqlTypeName tn = SqlTypeName.getNameForJdbcType(ExtraSqlTypes.SQLXML);
    // SQLXML not supported yet
    assertEquals(null, tn, "SQLXML maps to non-null type");
}
Also used : SqlTypeName(org.apache.calcite.sql.type.SqlTypeName) Test(org.junit.jupiter.api.Test)

Example 62 with SqlTypeName

use of org.apache.calcite.sql.type.SqlTypeName in project calcite by apache.

the class SqlTypeNameTest method testNumeric.

@Test
void testNumeric() {
    SqlTypeName tn = SqlTypeName.getNameForJdbcType(Types.NUMERIC);
    assertEquals(DECIMAL, tn, "NUMERIC did not map to DECIMAL");
}
Also used : SqlTypeName(org.apache.calcite.sql.type.SqlTypeName) Test(org.junit.jupiter.api.Test)

Example 63 with SqlTypeName

use of org.apache.calcite.sql.type.SqlTypeName in project calcite by apache.

the class SqlTypeNameTest method testFloat.

@Test
void testFloat() {
    SqlTypeName tn = SqlTypeName.getNameForJdbcType(Types.FLOAT);
    assertEquals(FLOAT, tn, "FLOAT did not map to FLOAT");
}
Also used : SqlTypeName(org.apache.calcite.sql.type.SqlTypeName) Test(org.junit.jupiter.api.Test)

Example 64 with SqlTypeName

use of org.apache.calcite.sql.type.SqlTypeName in project calcite by apache.

the class SqlTypeNameTest method testTimestamp.

@Test
void testTimestamp() {
    SqlTypeName tn = SqlTypeName.getNameForJdbcType(Types.TIMESTAMP);
    assertEquals(TIMESTAMP, tn, "TIMESTAMP did not map to TIMESTAMP");
}
Also used : SqlTypeName(org.apache.calcite.sql.type.SqlTypeName) Test(org.junit.jupiter.api.Test)

Example 65 with SqlTypeName

use of org.apache.calcite.sql.type.SqlTypeName in project calcite by apache.

the class DruidQuery method isValidLeafCast.

/**
 * Returns whether a {@link RexNode} is a valid Druid cast operation.
 *
 * @param rexNode RexNode
 *
 * @return whether the operand is an inputRef and it is a valid Druid Cast
 * operation
 */
private static boolean isValidLeafCast(RexNode rexNode) {
    assert rexNode.isA(SqlKind.CAST);
    final RexNode input = ((RexCall) rexNode).getOperands().get(0);
    if (!input.isA(SqlKind.INPUT_REF)) {
        // it is not a leaf cast don't bother going further.
        return false;
    }
    final SqlTypeName toTypeName = rexNode.getType().getSqlTypeName();
    if (toTypeName.getFamily() == SqlTypeFamily.CHARACTER) {
        // CAST of input to character type
        return true;
    }
    if (toTypeName.getFamily() == SqlTypeFamily.NUMERIC) {
        // CAST of input to numeric type, it is part of a bounded comparison
        return true;
    }
    if (toTypeName.getFamily() == SqlTypeFamily.TIMESTAMP || toTypeName.getFamily() == SqlTypeFamily.DATETIME) {
        // CAST of literal to timestamp type
        return true;
    }
    if (toTypeName.getFamily().contains(input.getType())) {
        // same type it is okay to push it
        return true;
    }
    // Currently other CAST operations cannot be pushed to Druid
    return false;
}
Also used : SqlTypeName(org.apache.calcite.sql.type.SqlTypeName) RexNode(org.apache.calcite.rex.RexNode)

Aggregations

SqlTypeName (org.apache.calcite.sql.type.SqlTypeName)184 RelDataType (org.apache.calcite.rel.type.RelDataType)62 Test (org.junit.jupiter.api.Test)39 List (java.util.List)31 BigDecimal (java.math.BigDecimal)30 ArrayList (java.util.ArrayList)30 ImmutableList (com.google.common.collect.ImmutableList)26 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)26 Map (java.util.Map)25 RexNode (org.apache.calcite.rex.RexNode)25 NlsString (org.apache.calcite.util.NlsString)21 DateString (org.apache.calcite.util.DateString)18 TimeString (org.apache.calcite.util.TimeString)18 TimestampString (org.apache.calcite.util.TimestampString)18 ByteString (org.apache.calcite.avatica.util.ByteString)17 RelDataTypeFactory (org.apache.calcite.rel.type.RelDataTypeFactory)16 SqlKind (org.apache.calcite.sql.SqlKind)15 Calendar (java.util.Calendar)14 Objects (java.util.Objects)13 Util (org.apache.calcite.util.Util)13