Search in sources :

Example 1 with IntervalSqlType

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

the class SqlDatetimePlusOperator method inferReturnType.

// ~ Methods ----------------------------------------------------------------
@Override
public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
    final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
    final RelDataType leftType = opBinding.getOperandType(0);
    final IntervalSqlType unitType = (IntervalSqlType) opBinding.getOperandType(1);
    switch(unitType.getIntervalQualifier().getStartUnit()) {
        case HOUR:
        case MINUTE:
        case SECOND:
        case MILLISECOND:
        case MICROSECOND:
            return typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.TIMESTAMP), leftType.isNullable() || unitType.isNullable());
        default:
            return leftType;
    }
}
Also used : IntervalSqlType(org.apache.calcite.sql.type.IntervalSqlType) RelDataTypeFactory(org.apache.calcite.rel.type.RelDataTypeFactory) RelDataType(org.apache.calcite.rel.type.RelDataType)

Aggregations

RelDataType (org.apache.calcite.rel.type.RelDataType)1 RelDataTypeFactory (org.apache.calcite.rel.type.RelDataTypeFactory)1 IntervalSqlType (org.apache.calcite.sql.type.IntervalSqlType)1