use of io.prestosql.spi.function.BuiltInScalarFunctionImplementation in project hetu-core by openlookeng.
the class JsonToArrayCast method specialize.
@Override
public BuiltInScalarFunctionImplementation specialize(BoundVariables boundVariables, int arity, FunctionAndTypeManager functionAndTypeManager) {
checkArgument(arity == 1, "Expected arity to be 1");
Type type = boundVariables.getTypeVariable("T");
ArrayType arrayType = (ArrayType) functionAndTypeManager.getParameterizedType(StandardTypes.ARRAY, ImmutableList.of(TypeSignatureParameter.of(type.getTypeSignature())));
checkCondition(canCastFromJson(arrayType), INVALID_CAST_ARGUMENT, "Cannot cast JSON to %s", arrayType);
BlockBuilderAppender elementAppender = BlockBuilderAppender.createBlockBuilderAppender(arrayType.getElementType());
MethodHandle methodHandle = METHOD_HANDLE.bindTo(arrayType).bindTo(elementAppender);
return new BuiltInScalarFunctionImplementation(true, ImmutableList.of(valueTypeArgumentProperty(RETURN_NULL_ON_NULL)), methodHandle);
}
use of io.prestosql.spi.function.BuiltInScalarFunctionImplementation in project hetu-core by openlookeng.
the class JsonToMapCast method specialize.
@Override
public BuiltInScalarFunctionImplementation specialize(BoundVariables boundVariables, int arity, FunctionAndTypeManager functionAndTypeManager) {
checkArgument(arity == 1, "Expected arity to be 1");
Type keyType = boundVariables.getTypeVariable("K");
Type valueType = boundVariables.getTypeVariable("V");
MapType mapType = (MapType) functionAndTypeManager.getParameterizedType(StandardTypes.MAP, ImmutableList.of(TypeSignatureParameter.of(keyType.getTypeSignature()), TypeSignatureParameter.of(valueType.getTypeSignature())));
checkCondition(canCastFromJson(mapType), INVALID_CAST_ARGUMENT, "Cannot cast JSON to %s", mapType);
BlockBuilderAppender keyAppender = createBlockBuilderAppender(mapType.getKeyType());
BlockBuilderAppender valueAppender = createBlockBuilderAppender(mapType.getValueType());
MethodHandle methodHandle = METHOD_HANDLE.bindTo(mapType).bindTo(keyAppender).bindTo(valueAppender);
return new BuiltInScalarFunctionImplementation(true, ImmutableList.of(valueTypeArgumentProperty(RETURN_NULL_ON_NULL)), methodHandle);
}
use of io.prestosql.spi.function.BuiltInScalarFunctionImplementation in project hetu-core by openlookeng.
the class JsonToRowCast method specialize.
@Override
public BuiltInScalarFunctionImplementation specialize(BoundVariables boundVariables, int arity, FunctionAndTypeManager functionAndTypeManager) {
checkArgument(arity == 1, "Expected arity to be 1");
RowType rowType = (RowType) boundVariables.getTypeVariable("T");
checkCondition(canCastFromJson(rowType), INVALID_CAST_ARGUMENT, "Cannot cast JSON to %s", rowType);
List<Field> rowFields = rowType.getFields();
BlockBuilderAppender[] fieldAppenders = rowFields.stream().map(rowField -> createBlockBuilderAppender(rowField.getType())).toArray(BlockBuilderAppender[]::new);
MethodHandle methodHandle = METHOD_HANDLE.bindTo(rowType).bindTo(fieldAppenders).bindTo(getFieldNameToIndex(rowFields));
return new BuiltInScalarFunctionImplementation(true, ImmutableList.of(valueTypeArgumentProperty(RETURN_NULL_ON_NULL)), methodHandle);
}
use of io.prestosql.spi.function.BuiltInScalarFunctionImplementation in project hetu-core by openlookeng.
the class ElementToArrayConcatFunction method specialize.
@Override
public BuiltInScalarFunctionImplementation specialize(BoundVariables boundVariables, int arity, FunctionAndTypeManager functionAndTypeManager) {
Type type = boundVariables.getTypeVariable("E");
MethodHandle methodHandle;
if (type.getJavaType() == boolean.class) {
methodHandle = METHOD_HANDLE_BOOLEAN;
} else if (type.getJavaType() == long.class) {
methodHandle = METHOD_HANDLE_LONG;
} else if (type.getJavaType() == double.class) {
methodHandle = METHOD_HANDLE_DOUBLE;
} else if (type.getJavaType() == Slice.class) {
methodHandle = METHOD_HANDLE_SLICE;
} else {
methodHandle = METHOD_HANDLE_OBJECT;
}
methodHandle = methodHandle.bindTo(type);
return new BuiltInScalarFunctionImplementation(false, ImmutableList.of(valueTypeArgumentProperty(RETURN_NULL_ON_NULL), valueTypeArgumentProperty(RETURN_NULL_ON_NULL)), methodHandle);
}
use of io.prestosql.spi.function.BuiltInScalarFunctionImplementation in project hetu-core by openlookeng.
the class ArrayToElementConcatFunction method specialize.
@Override
public BuiltInScalarFunctionImplementation specialize(BoundVariables boundVariables, int arity, FunctionAndTypeManager functionAndTypeManager) {
Type type = boundVariables.getTypeVariable("E");
MethodHandle methodHandle;
if (type.getJavaType() == boolean.class) {
methodHandle = METHOD_HANDLE_BOOLEAN;
} else if (type.getJavaType() == long.class) {
methodHandle = METHOD_HANDLE_LONG;
} else if (type.getJavaType() == double.class) {
methodHandle = METHOD_HANDLE_DOUBLE;
} else if (type.getJavaType() == Slice.class) {
methodHandle = METHOD_HANDLE_SLICE;
} else {
methodHandle = METHOD_HANDLE_OBJECT;
}
methodHandle = methodHandle.bindTo(type);
return new BuiltInScalarFunctionImplementation(false, ImmutableList.of(valueTypeArgumentProperty(RETURN_NULL_ON_NULL), valueTypeArgumentProperty(RETURN_NULL_ON_NULL)), methodHandle);
}
Aggregations