Search in sources :

Example 1 with Time

use of io.prestosql.spi.sql.expression.Time in project hetu-core by openlookeng.

the class OracleRowExpressionConverter method visitCall.

@Override
public String visitCall(CallExpression call, JdbcConverterContext context) {
    FunctionHandle functionHandle = call.getFunctionHandle();
    String functionName = functionMetadataManager.getFunctionMetadata(functionHandle).getName().getObjectName();
    if (timeExtractFields.contains(functionName)) {
        if (call.getArguments().size() == 1) {
            try {
                Time.ExtractField field = Time.ExtractField.valueOf(functionName.toUpperCase(ENGLISH));
                return format("EXTRACT(%s FROM %s)", field, call.getArguments().get(0).accept(this, context));
            } catch (IllegalArgumentException e) {
                throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Illegal argument: " + e);
            }
        } else {
            throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Illegal argument num of function " + functionName);
        }
    }
    if (functionName.equals(AT_TIMEZONE_FUNCTION_NAME)) {
        if (call.getArguments().size() == 2) {
            return format("%s AT TIME ZONE %s", call.getArguments().get(0).accept(this, context), call.getArguments().get(1).accept(this, context));
        } else {
            throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Illegal argument num of function " + functionName);
        }
    }
    if (standardFunctionResolution.isArrayConstructor(functionHandle)) {
        throw new PrestoException(NOT_SUPPORTED, "Oracle connector does not support array constructor");
    }
    if (standardFunctionResolution.isSubscriptFunction(functionHandle)) {
        throw new PrestoException(NOT_SUPPORTED, "Oracle connector does not support subscript expression");
    }
    if (standardFunctionResolution.isCastFunction(functionHandle)) {
        // deal with literal, when generic literal expression translate to rowExpression, it will be
        // translated to a 'CAST' rowExpression with a varchar type 'CONSTANT' rowExpression, in some
        // case, 'CAST' is superfluous
        RowExpression argument = call.getArguments().get(0);
        Type type = call.getType();
        if (argument instanceof ConstantExpression && argument.getType() instanceof VarcharType) {
            String value = argument.accept(this, context);
            if (type instanceof DateType) {
                return format("date %s", value);
            }
            if (type instanceof VarcharType || type instanceof CharType || type instanceof VarbinaryType || type instanceof DecimalType || type instanceof RealType || type instanceof DoubleType) {
                return value;
            }
        }
        if (call.getType().getDisplayName().equals(LIKE_PATTERN_NAME)) {
            return call.getArguments().get(0).accept(this, context);
        }
        return getCastExpression(call.getArguments().get(0).accept(this, context), call.getType());
    }
    return super.visitCall(call, context);
}
Also used : VarcharType(io.prestosql.spi.type.VarcharType) ConstantExpression(io.prestosql.spi.relation.ConstantExpression) RowExpression(io.prestosql.spi.relation.RowExpression) Time(io.prestosql.spi.sql.expression.Time) PrestoException(io.prestosql.spi.PrestoException) RealType(io.prestosql.spi.type.RealType) CharType(io.prestosql.spi.type.CharType) DecimalType(io.prestosql.spi.type.DecimalType) DoubleType(io.prestosql.spi.type.DoubleType) Type(io.prestosql.spi.type.Type) RealType(io.prestosql.spi.type.RealType) VarbinaryType(io.prestosql.spi.type.VarbinaryType) DateType(io.prestosql.spi.type.DateType) VarcharType(io.prestosql.spi.type.VarcharType) VarbinaryType(io.prestosql.spi.type.VarbinaryType) DoubleType(io.prestosql.spi.type.DoubleType) DecimalType(io.prestosql.spi.type.DecimalType) CharType(io.prestosql.spi.type.CharType) FunctionHandle(io.prestosql.spi.function.FunctionHandle) DateType(io.prestosql.spi.type.DateType)

Aggregations

PrestoException (io.prestosql.spi.PrestoException)1 FunctionHandle (io.prestosql.spi.function.FunctionHandle)1 ConstantExpression (io.prestosql.spi.relation.ConstantExpression)1 RowExpression (io.prestosql.spi.relation.RowExpression)1 Time (io.prestosql.spi.sql.expression.Time)1 CharType (io.prestosql.spi.type.CharType)1 DateType (io.prestosql.spi.type.DateType)1 DecimalType (io.prestosql.spi.type.DecimalType)1 DoubleType (io.prestosql.spi.type.DoubleType)1 RealType (io.prestosql.spi.type.RealType)1 Type (io.prestosql.spi.type.Type)1 VarbinaryType (io.prestosql.spi.type.VarbinaryType)1 VarcharType (io.prestosql.spi.type.VarcharType)1