Search in sources :

Example 11 with SqlTypeName

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

the class JdbcToEnumerableConverter method generateGet.

private void generateGet(EnumerableRelImplementor implementor, PhysType physType, BlockBuilder builder, ParameterExpression resultSet_, int i, Expression target, Expression calendar_, SqlDialect.CalendarPolicy calendarPolicy) {
    final Primitive primitive = Primitive.ofBoxOr(physType.fieldClass(i));
    final RelDataType fieldType = physType.getRowType().getFieldList().get(i).getType();
    final List<Expression> dateTimeArgs = new ArrayList<Expression>();
    dateTimeArgs.add(Expressions.constant(i + 1));
    SqlTypeName sqlTypeName = fieldType.getSqlTypeName();
    boolean offset = false;
    switch(calendarPolicy) {
        case LOCAL:
            dateTimeArgs.add(calendar_);
            break;
        case NULL:
            // instead use the version of the getXXX that doesn't take a Calendar
            break;
        case DIRECT:
            sqlTypeName = SqlTypeName.ANY;
            break;
        case SHIFT:
            switch(sqlTypeName) {
                case TIMESTAMP:
                case DATE:
                    offset = true;
            }
            break;
    }
    final Expression source;
    switch(sqlTypeName) {
        case DATE:
        case TIME:
        case TIMESTAMP:
            source = Expressions.call(getMethod(sqlTypeName, fieldType.isNullable(), offset), Expressions.<Expression>list().append(Expressions.call(resultSet_, getMethod2(sqlTypeName), dateTimeArgs)).appendIf(offset, getTimeZoneExpression(implementor)));
            break;
        case ARRAY:
            final Expression x = Expressions.convert_(Expressions.call(resultSet_, jdbcGetMethod(primitive), Expressions.constant(i + 1)), java.sql.Array.class);
            source = Expressions.call(BuiltInMethod.JDBC_ARRAY_TO_LIST.method, x);
            break;
        default:
            source = Expressions.call(resultSet_, jdbcGetMethod(primitive), Expressions.constant(i + 1));
    }
    builder.add(Expressions.statement(Expressions.assign(target, source)));
    // object
    if (primitive != null) {
        builder.add(Expressions.ifThen(Expressions.call(resultSet_, "wasNull"), Expressions.statement(Expressions.assign(target, Expressions.constant(null)))));
    }
}
Also used : Primitive(org.apache.calcite.linq4j.tree.Primitive) SqlTypeName(org.apache.calcite.sql.type.SqlTypeName) Expression(org.apache.calcite.linq4j.tree.Expression) UnaryExpression(org.apache.calcite.linq4j.tree.UnaryExpression) ParameterExpression(org.apache.calcite.linq4j.tree.ParameterExpression) ArrayList(java.util.ArrayList) RelDataType(org.apache.calcite.rel.type.RelDataType)

Example 12 with SqlTypeName

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

the class SqlLiteralChainOperator method inferReturnType.

// Result type is the same as all the args, but its size is the
// total size.
// REVIEW mb 8/8/04: Possibly this can be achieved by combining
// the strategy useFirstArgType with a new transformer.
public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
    // Here we know all the operands have the same type,
    // which has a size (precision), but not a scale.
    RelDataType ret = opBinding.getOperandType(0);
    SqlTypeName typeName = ret.getSqlTypeName();
    assert typeName.allowsPrecNoScale() : "LiteralChain has impossible operand type " + typeName;
    int size = 0;
    for (RelDataType type : opBinding.collectOperandTypes()) {
        size += type.getPrecision();
        assert type.getSqlTypeName() == typeName;
    }
    return opBinding.getTypeFactory().createSqlType(typeName, size);
}
Also used : SqlTypeName(org.apache.calcite.sql.type.SqlTypeName) RelDataType(org.apache.calcite.rel.type.RelDataType)

Example 13 with SqlTypeName

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

the class SqlTypeNameTest method testStruct.

@Test
public void testStruct() {
    SqlTypeName tn = SqlTypeName.getNameForJdbcType(Types.STRUCT);
    assertEquals("STRUCT did not map to null", SqlTypeName.STRUCTURED, tn);
}
Also used : SqlTypeName(org.apache.calcite.sql.type.SqlTypeName) Test(org.junit.Test)

Example 14 with SqlTypeName

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

the class SqlTypeNameTest method testVarchar.

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

Example 15 with SqlTypeName

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

the class SqlTypeNameTest method testDouble.

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

Aggregations

SqlTypeName (org.apache.calcite.sql.type.SqlTypeName)116 Test (org.junit.Test)38 RelDataType (org.apache.calcite.rel.type.RelDataType)28 RexNode (org.apache.calcite.rex.RexNode)18 BigDecimal (java.math.BigDecimal)13 ArrayList (java.util.ArrayList)12 List (java.util.List)11 RelDataTypeFactory (org.apache.calcite.rel.type.RelDataTypeFactory)8 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)8 ImmutableList (com.google.common.collect.ImmutableList)7 Map (java.util.Map)7 DateString (org.apache.calcite.util.DateString)7 TimeString (org.apache.calcite.util.TimeString)7 TimestampString (org.apache.calcite.util.TimestampString)7 ISE (io.druid.java.util.common.ISE)6 SqlKind (org.apache.calcite.sql.SqlKind)6 NlsString (org.apache.calcite.util.NlsString)6 Calendar (java.util.Calendar)5 Nullable (javax.annotation.Nullable)5 RexBuilder (org.apache.calcite.rex.RexBuilder)5