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);
}
Aggregations