use of io.prestosql.spi.type.VarbinaryType in project hetu-core by openlookeng.
the class MySqlRowExpressionConverter method visitCall.
@Override
public String visitCall(CallExpression call, JdbcConverterContext context) {
// remote udf verify
FunctionHandle functionHandle = call.getFunctionHandle();
if (!isDefaultFunction(call)) {
Optional<String> result = mySqlApplyRemoteFunctionPushDown.rewriteRemoteFunction(call, this, context);
if (result.isPresent()) {
return result.get();
}
throw new PrestoException(NOT_SUPPORTED, String.format("MySql connector does not support remote function: %s.%s", call.getDisplayName(), call.getFunctionHandle().getFunctionNamespace()));
}
if (standardFunctionResolution.isArrayConstructor(functionHandle)) {
throw new PrestoException(NOT_SUPPORTED, "MySql connector does not support array constructor");
}
if (standardFunctionResolution.isSubscriptFunction(functionHandle)) {
throw new PrestoException(NOT_SUPPORTED, "MySql 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().equals(VARCHAR)) {
String value = argument.accept(this, context);
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);
}
use of io.prestosql.spi.type.VarbinaryType in project hetu-core by openlookeng.
the class OrcTester method getJavaObjectInspector.
private static ObjectInspector getJavaObjectInspector(Type type) {
if (type.equals(BOOLEAN)) {
return javaBooleanObjectInspector;
}
if (type.equals(BIGINT)) {
return javaLongObjectInspector;
}
if (type.equals(INTEGER)) {
return javaIntObjectInspector;
}
if (type.equals(SMALLINT)) {
return javaShortObjectInspector;
}
if (type.equals(TINYINT)) {
return javaByteObjectInspector;
}
if (type.equals(REAL)) {
return javaFloatObjectInspector;
}
if (type.equals(DOUBLE)) {
return javaDoubleObjectInspector;
}
if (type instanceof VarcharType) {
return javaStringObjectInspector;
}
if (type instanceof CharType) {
int charLength = ((CharType) type).getLength();
return new JavaHiveCharObjectInspector(getCharTypeInfo(charLength));
}
if (type instanceof VarbinaryType) {
return javaByteArrayObjectInspector;
}
if (type.equals(DATE)) {
return javaDateObjectInspector;
}
if (type.equals(TIMESTAMP)) {
return javaTimestampObjectInspector;
}
if (type instanceof DecimalType) {
DecimalType decimalType = (DecimalType) type;
return getPrimitiveJavaObjectInspector(new DecimalTypeInfo(decimalType.getPrecision(), decimalType.getScale()));
}
if (type.getTypeSignature().getBase().equals(StandardTypes.ARRAY)) {
return getStandardListObjectInspector(getJavaObjectInspector(type.getTypeParameters().get(0)));
}
if (type.getTypeSignature().getBase().equals(StandardTypes.MAP)) {
ObjectInspector keyObjectInspector = getJavaObjectInspector(type.getTypeParameters().get(0));
ObjectInspector valueObjectInspector = getJavaObjectInspector(type.getTypeParameters().get(1));
return getStandardMapObjectInspector(keyObjectInspector, valueObjectInspector);
}
if (type.getTypeSignature().getBase().equals(StandardTypes.ROW)) {
return getStandardStructObjectInspector(type.getTypeSignature().getParameters().stream().map(parameter -> parameter.getNamedTypeSignature().getName().get()).collect(toList()), type.getTypeParameters().stream().map(OrcTester::getJavaObjectInspector).collect(toList()));
}
throw new IllegalArgumentException("unsupported type: " + type);
}
use of io.prestosql.spi.type.VarbinaryType in project hetu-core by openlookeng.
the class LiteralInterpreter method evaluate.
public static Object evaluate(ConstantExpression node) {
Type type = node.getType();
if (node.getValue() == null) {
return null;
}
if (type instanceof BooleanType) {
return node.getValue();
}
if (type instanceof BigintType || type instanceof TinyintType || type instanceof SmallintType || type instanceof IntegerType) {
return node.getValue();
}
if (type instanceof DoubleType) {
return node.getValue();
}
if (type instanceof RealType) {
Long number = (Long) node.getValue();
return intBitsToFloat(number.intValue());
}
if (type instanceof DecimalType) {
DecimalType decimalType = (DecimalType) type;
if (decimalType.isShort()) {
checkState(node.getValue() instanceof Long);
return decodeDecimal(BigInteger.valueOf((long) node.getValue()), decimalType);
}
checkState(node.getValue() instanceof Slice);
Slice value = (Slice) node.getValue();
return decodeDecimal(decodeUnscaledValue(value), decimalType);
}
if (type instanceof VarcharType || type instanceof CharType) {
return (node.getValue() instanceof String) ? node.getValue() : ((Slice) node.getValue()).toStringUtf8();
}
if (type instanceof VarbinaryType) {
return new SqlVarbinary(((Slice) node.getValue()).getBytes());
}
if (type instanceof DateType) {
return new SqlDate(((Long) node.getValue()).intValue());
}
if (type instanceof TimeType) {
return new SqlTime((long) node.getValue());
}
if (type instanceof TimestampType) {
try {
return new SqlTimestamp((long) node.getValue());
} catch (RuntimeException e) {
throw new PrestoException(GENERIC_USER_ERROR, format("'%s' is not a valid timestamp literal", (String) node.getValue()));
}
}
if (type instanceof IntervalDayTimeType) {
return new SqlIntervalDayTime((long) node.getValue());
}
if (type instanceof IntervalYearMonthType) {
return new SqlIntervalYearMonth(((Long) node.getValue()).intValue());
}
if (type.getJavaType().equals(Slice.class)) {
// DO NOT ever remove toBase64. Calling toString directly on Slice whose base is not byte[] will cause JVM to crash.
return "'" + VarbinaryFunctions.toBase64((Slice) node.getValue()).toStringUtf8() + "'";
}
// We should not fail at the moment; just return the raw value (block, regex, etc) to the user
return node.getValue();
}
use of io.prestosql.spi.type.VarbinaryType 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);
}
use of io.prestosql.spi.type.VarbinaryType in project pulsar by apache.
the class PulsarPrimitiveRowDecoder method decodeRow.
@Override
public Optional<Map<DecoderColumnHandle, FieldValueProvider>> decodeRow(ByteBuf byteBuf) {
if (columnHandle == null) {
return Optional.empty();
}
Object value = schema.decode(byteBuf);
Map<DecoderColumnHandle, FieldValueProvider> primitiveColumn = new HashMap<>();
if (value == null) {
primitiveColumn.put(columnHandle, FieldValueProviders.nullValueProvider());
} else {
Type type = columnHandle.getType();
if (type instanceof BooleanType) {
primitiveColumn.put(columnHandle, booleanValueProvider(Boolean.valueOf((Boolean) value)));
} else if (type instanceof TinyintType || type instanceof SmallintType || type instanceof IntegerType || type instanceof BigintType) {
primitiveColumn.put(columnHandle, longValueProvider(Long.parseLong(value.toString())));
} else if (type instanceof DoubleType) {
primitiveColumn.put(columnHandle, doubleValueProvider(Double.parseDouble(value.toString())));
} else if (type instanceof RealType) {
primitiveColumn.put(columnHandle, longValueProvider(Float.floatToIntBits((Float.parseFloat(value.toString())))));
} else if (type instanceof VarbinaryType) {
primitiveColumn.put(columnHandle, bytesValueProvider((byte[]) value));
} else if (type instanceof VarcharType) {
primitiveColumn.put(columnHandle, bytesValueProvider(value.toString().getBytes()));
} else if (type instanceof DateType) {
primitiveColumn.put(columnHandle, longValueProvider(((Date) value).getTime()));
} else if (type instanceof TimeType) {
primitiveColumn.put(columnHandle, longValueProvider(((Time) value).getTime()));
} else if (type instanceof TimestampType) {
primitiveColumn.put(columnHandle, longValueProvider(((Timestamp) value).getTime()));
} else {
primitiveColumn.put(columnHandle, bytesValueProvider(value.toString().getBytes()));
}
}
return Optional.of(primitiveColumn);
}
Aggregations