Search in sources :

Example 1 with FunctionAndTypeManager

use of io.prestosql.metadata.FunctionAndTypeManager 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);
}
Also used : BuiltInScalarFunctionImplementation(io.prestosql.spi.function.BuiltInScalarFunctionImplementation) MethodHandle(java.lang.invoke.MethodHandle) Slice(io.airlift.slice.Slice) StandardTypes(io.prestosql.spi.type.StandardTypes) BoundVariables(io.prestosql.metadata.BoundVariables) UsedByGeneratedCode(io.prestosql.spi.annotation.UsedByGeneratedCode) BlockBuilderAppender.createBlockBuilderAppender(io.prestosql.util.JsonUtil.BlockBuilderAppender.createBlockBuilderAppender) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) BlockBuilderAppender(io.prestosql.util.JsonUtil.BlockBuilderAppender) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) ImmutableList(com.google.common.collect.ImmutableList) ConnectorSession(io.prestosql.spi.connector.ConnectorSession) Failures.checkCondition(io.prestosql.util.Failures.checkCondition) START_OBJECT(com.fasterxml.jackson.core.JsonToken.START_OBJECT) OperatorType(io.prestosql.spi.function.OperatorType) Map(java.util.Map) RowType(io.prestosql.spi.type.RowType) RETURN_NULL_ON_NULL(io.prestosql.spi.function.BuiltInScalarFunctionImplementation.NullConvention.RETURN_NULL_ON_NULL) JsonToken(com.fasterxml.jackson.core.JsonToken) JsonUtil.createJsonParser(io.prestosql.util.JsonUtil.createJsonParser) Block(io.prestosql.spi.block.Block) PrestoException(io.prestosql.spi.PrestoException) JsonParser(com.fasterxml.jackson.core.JsonParser) BlockBuilder(io.prestosql.spi.block.BlockBuilder) SqlOperator(io.prestosql.metadata.SqlOperator) Reflection.methodHandle(io.prestosql.spi.util.Reflection.methodHandle) INVALID_CAST_ARGUMENT(io.prestosql.spi.StandardErrorCode.INVALID_CAST_ARGUMENT) JsonUtil.getFieldNameToIndex(io.prestosql.util.JsonUtil.getFieldNameToIndex) String.format(java.lang.String.format) List(java.util.List) JSON_FACTORY(io.prestosql.util.JsonUtil.JSON_FACTORY) START_ARRAY(com.fasterxml.jackson.core.JsonToken.START_ARRAY) JsonUtil.canCastFromJson(io.prestosql.util.JsonUtil.canCastFromJson) ArgumentProperty.valueTypeArgumentProperty(io.prestosql.spi.function.BuiltInScalarFunctionImplementation.ArgumentProperty.valueTypeArgumentProperty) Optional(java.util.Optional) Field(io.prestosql.spi.type.RowType.Field) Signature.withVariadicBound(io.prestosql.spi.function.Signature.withVariadicBound) JsonUtil.truncateIfNecessaryForErrorMessage(io.prestosql.util.JsonUtil.truncateIfNecessaryForErrorMessage) SingleRowBlockWriter(io.prestosql.spi.block.SingleRowBlockWriter) JsonUtil.parseJsonToSingleRowBlock(io.prestosql.util.JsonUtil.parseJsonToSingleRowBlock) FunctionAndTypeManager(io.prestosql.metadata.FunctionAndTypeManager) JsonCastException(io.prestosql.util.JsonCastException) Field(io.prestosql.spi.type.RowType.Field) BuiltInScalarFunctionImplementation(io.prestosql.spi.function.BuiltInScalarFunctionImplementation) BlockBuilderAppender.createBlockBuilderAppender(io.prestosql.util.JsonUtil.BlockBuilderAppender.createBlockBuilderAppender) BlockBuilderAppender(io.prestosql.util.JsonUtil.BlockBuilderAppender) RowType(io.prestosql.spi.type.RowType) MethodHandle(java.lang.invoke.MethodHandle)

Example 2 with FunctionAndTypeManager

use of io.prestosql.metadata.FunctionAndTypeManager in project hetu-core by openlookeng.

the class FormatFunction method valueConverter.

private static BiFunction<ConnectorSession, Block, Object> valueConverter(FunctionAndTypeManager functionAndTypeManager, Type type, int position) {
    if (type.equals(UNKNOWN)) {
        return (session, block) -> null;
    }
    if (type.equals(BOOLEAN)) {
        return (session, block) -> type.getBoolean(block, position);
    }
    if (type.equals(TINYINT) || type.equals(SMALLINT) || type.equals(INTEGER) || type.equals(BIGINT)) {
        return (session, block) -> type.getLong(block, position);
    }
    if (type.equals(REAL)) {
        return (session, block) -> intBitsToFloat(toIntExact(type.getLong(block, position)));
    }
    if (type.equals(DOUBLE)) {
        return (session, block) -> type.getDouble(block, position);
    }
    if (type.equals(DATE)) {
        return (session, block) -> LocalDate.ofEpochDay(type.getLong(block, position));
    }
    if (type.equals(TIMESTAMP_WITH_TIME_ZONE)) {
        return (session, block) -> toZonedDateTime(type.getLong(block, position));
    }
    if (type.equals(TIMESTAMP)) {
        return (session, block) -> toLocalDateTime(type.getLong(block, position));
    }
    if (type.equals(TIME)) {
        return (session, block) -> toLocalTime(session, type.getLong(block, position));
    }
    // TODO: support TIME WITH TIME ZONE by making SqlTimeWithTimeZone implement TemporalAccessor
    if (type.equals(JSON)) {
        FunctionHandle functionHandle = functionAndTypeManager.resolveFunction(Optional.empty(), QualifiedObjectName.valueOf(DEFAULT_NAMESPACE, "json_format"), fromTypes(JSON));
        MethodHandle handle = functionAndTypeManager.getBuiltInScalarFunctionImplementation(functionHandle).getMethodHandle();
        return (session, block) -> convertToString(handle, type.getSlice(block, position));
    }
    if (isShortDecimal(type)) {
        int scale = ((DecimalType) type).getScale();
        return (session, block) -> BigDecimal.valueOf(type.getLong(block, position), scale);
    }
    if (isLongDecimal(type)) {
        int scale = ((DecimalType) type).getScale();
        return (session, block) -> new BigDecimal(decodeUnscaledValue(type.getSlice(block, position)), scale);
    }
    if (isVarcharType(type) || isCharType(type)) {
        return (session, block) -> type.getSlice(block, position).toStringUtf8();
    }
    BiFunction<ConnectorSession, Block, Object> function;
    if (type.getJavaType() == long.class) {
        function = (session, block) -> type.getLong(block, position);
    } else if (type.getJavaType() == double.class) {
        function = (session, block) -> type.getDouble(block, position);
    } else if (type.getJavaType() == boolean.class) {
        function = (session, block) -> type.getBoolean(block, position);
    } else if (type.getJavaType() == Slice.class) {
        function = (session, block) -> type.getSlice(block, position);
    } else {
        function = (session, block) -> type.getObject(block, position);
    }
    MethodHandle handle = castToVarchar(functionAndTypeManager, type);
    if ((handle == null) || (handle.type().parameterCount() != 1)) {
        throw new PrestoException(NOT_SUPPORTED, "Type not supported for formatting: " + type.getDisplayName());
    }
    return (session, block) -> convertToString(handle, function.apply(session, block));
}
Also used : DateTimeEncoding.unpackZoneKey(io.prestosql.spi.type.DateTimeEncoding.unpackZoneKey) Varchars.isVarcharType(io.prestosql.spi.type.Varchars.isVarcharType) ZonedDateTime(java.time.ZonedDateTime) BiFunction(java.util.function.BiFunction) SCALAR(io.prestosql.spi.function.FunctionKind.SCALAR) OperatorNotFoundException(io.prestosql.metadata.OperatorNotFoundException) INVALID_FUNCTION_ARGUMENT(io.prestosql.spi.StandardErrorCode.INVALID_FUNCTION_ARGUMENT) DecimalType(io.prestosql.spi.type.DecimalType) BoundVariables(io.prestosql.metadata.BoundVariables) DEFAULT_NAMESPACE(io.prestosql.spi.connector.CatalogSchemaName.DEFAULT_NAMESPACE) UsedByGeneratedCode(io.prestosql.spi.annotation.UsedByGeneratedCode) BigDecimal(java.math.BigDecimal) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) ConnectorSession(io.prestosql.spi.connector.ConnectorSession) LocalTime(java.time.LocalTime) IllegalFormatException(java.util.IllegalFormatException) BOOLEAN(io.prestosql.spi.type.BooleanType.BOOLEAN) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) JSON(io.prestosql.type.JsonType.JSON) Type(io.prestosql.spi.type.Type) ZoneOffset(java.time.ZoneOffset) BIGINT(io.prestosql.spi.type.BigintType.BIGINT) Chars.isCharType(io.prestosql.spi.type.Chars.isCharType) PrestoException(io.prestosql.spi.PrestoException) DateTimeEncoding.unpackMillisUtc(io.prestosql.spi.type.DateTimeEncoding.unpackMillisUtc) CastType(io.prestosql.metadata.CastType) SqlScalarFunction(io.prestosql.metadata.SqlScalarFunction) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) TIME(io.prestosql.spi.type.TimeType.TIME) Reflection.methodHandle(io.prestosql.spi.util.Reflection.methodHandle) Decimals.isLongDecimal(io.prestosql.spi.type.Decimals.isLongDecimal) TIMESTAMP(io.prestosql.spi.type.TimestampType.TIMESTAMP) TINYINT(io.prestosql.spi.type.TinyintType.TINYINT) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Instant(java.time.Instant) ZoneId(java.time.ZoneId) String.format(java.lang.String.format) FunctionHandle(io.prestosql.spi.function.FunctionHandle) Decimals.isShortDecimal(io.prestosql.spi.type.Decimals.isShortDecimal) List(java.util.List) LocalDate(java.time.LocalDate) ArgumentProperty.valueTypeArgumentProperty(io.prestosql.spi.function.BuiltInScalarFunctionImplementation.ArgumentProperty.valueTypeArgumentProperty) Optional(java.util.Optional) NOT_SUPPORTED(io.prestosql.spi.StandardErrorCode.NOT_SUPPORTED) TIMESTAMP_WITH_TIME_ZONE(io.prestosql.spi.type.TimestampWithTimeZoneType.TIMESTAMP_WITH_TIME_ZONE) Signature.withVariadicBound(io.prestosql.spi.function.Signature.withVariadicBound) FunctionAndTypeManager(io.prestosql.metadata.FunctionAndTypeManager) UNKNOWN(io.prestosql.spi.type.UnknownType.UNKNOWN) BuiltInScalarFunctionImplementation(io.prestosql.spi.function.BuiltInScalarFunctionImplementation) MethodHandle(java.lang.invoke.MethodHandle) Slice(io.airlift.slice.Slice) LocalDateTime(java.time.LocalDateTime) INTEGER(io.prestosql.spi.type.IntegerType.INTEGER) Float.intBitsToFloat(java.lang.Float.intBitsToFloat) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) VARCHAR(io.prestosql.spi.type.VarcharType.VARCHAR) Failures.internalError(io.prestosql.util.Failures.internalError) ImmutableList(com.google.common.collect.ImmutableList) RETURN_NULL_ON_NULL(io.prestosql.spi.function.BuiltInScalarFunctionImplementation.NullConvention.RETURN_NULL_ON_NULL) DOUBLE(io.prestosql.spi.type.DoubleType.DOUBLE) DATE(io.prestosql.spi.type.DateType.DATE) REAL(io.prestosql.spi.type.RealType.REAL) Math.toIntExact(java.lang.Math.toIntExact) Signature(io.prestosql.spi.function.Signature) Block(io.prestosql.spi.block.Block) Streams.mapWithIndex(com.google.common.collect.Streams.mapWithIndex) TypeSignatureProvider.fromTypes(io.prestosql.sql.analyzer.TypeSignatureProvider.fromTypes) Decimals.decodeUnscaledValue(io.prestosql.spi.type.Decimals.decodeUnscaledValue) SMALLINT(io.prestosql.spi.type.SmallintType.SMALLINT) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) Slice(io.airlift.slice.Slice) DecimalType(io.prestosql.spi.type.DecimalType) Block(io.prestosql.spi.block.Block) ConnectorSession(io.prestosql.spi.connector.ConnectorSession) PrestoException(io.prestosql.spi.PrestoException) FunctionHandle(io.prestosql.spi.function.FunctionHandle) BigDecimal(java.math.BigDecimal) MethodHandle(java.lang.invoke.MethodHandle)

Example 3 with FunctionAndTypeManager

use of io.prestosql.metadata.FunctionAndTypeManager in project hetu-core by openlookeng.

the class ArrayJoin method specializeArrayJoin.

private static BuiltInScalarFunctionImplementation specializeArrayJoin(Map<String, Type> types, FunctionAndTypeManager functionAndTypeManager, List<Boolean> nullableArguments, MethodHandle methodHandle) {
    Type type = types.get("T");
    List<ArgumentProperty> argumentProperties = nullableArguments.stream().map(nullable -> nullable ? valueTypeArgumentProperty(USE_BOXED_TYPE) : valueTypeArgumentProperty(RETURN_NULL_ON_NULL)).collect(toImmutableList());
    if (type instanceof UnknownType) {
        return new BuiltInScalarFunctionImplementation(false, argumentProperties, methodHandle.bindTo(null), Optional.of(STATE_FACTORY));
    } else {
        try {
            BuiltInScalarFunctionImplementation castFunction = functionAndTypeManager.getBuiltInScalarFunctionImplementation(functionAndTypeManager.lookupCast(CastType.CAST, type.getTypeSignature(), VARCHAR_TYPE_SIGNATURE));
            MethodHandle getter;
            Class<?> elementType = type.getJavaType();
            if (elementType == boolean.class) {
                getter = GET_BOOLEAN;
            } else if (elementType == double.class) {
                getter = GET_DOUBLE;
            } else if (elementType == long.class) {
                getter = GET_LONG;
            } else if (elementType == Slice.class) {
                getter = GET_SLICE;
            } else {
                throw new UnsupportedOperationException("Unsupported type: " + elementType.getName());
            }
            MethodHandle cast = castFunction.getMethodHandle();
            // if the cast doesn't take a ConnectorSession, create an adapter that drops the provided session
            if (cast.type().parameterArray()[0] != ConnectorSession.class) {
                cast = MethodHandles.dropArguments(cast, 0, ConnectorSession.class);
            }
            // Adapt a target cast that takes (ConnectorSession, ?) to one that takes (Block, int, ConnectorSession), which will be invoked by the implementation
            // The first two arguments (Block, int) are filtered through the element type's getXXX method to produce the underlying value that needs to be passed to
            // the cast.
            cast = MethodHandles.permuteArguments(cast, MethodType.methodType(Slice.class, cast.type().parameterArray()[1], cast.type().parameterArray()[0]), 1, 0);
            cast = MethodHandles.dropArguments(cast, 1, int.class);
            cast = MethodHandles.dropArguments(cast, 1, Block.class);
            cast = MethodHandles.foldArguments(cast, getter.bindTo(type));
            MethodHandle target = MethodHandles.insertArguments(methodHandle, 0, cast);
            return new BuiltInScalarFunctionImplementation(false, argumentProperties, target, Optional.of(STATE_FACTORY));
        } catch (PrestoException e) {
            throw new PrestoException(INVALID_FUNCTION_ARGUMENT, String.format("Input type %s not supported", type), e);
        }
    }
}
Also used : BuiltInScalarFunctionImplementation(io.prestosql.spi.function.BuiltInScalarFunctionImplementation) UnknownType(io.prestosql.spi.type.UnknownType) MethodHandle(java.lang.invoke.MethodHandle) Slice(io.airlift.slice.Slice) FunctionKind(io.prestosql.spi.function.FunctionKind) StandardTypes(io.prestosql.spi.type.StandardTypes) ArgumentProperty(io.prestosql.spi.function.BuiltInScalarFunctionImplementation.ArgumentProperty) INVALID_FUNCTION_ARGUMENT(io.prestosql.spi.StandardErrorCode.INVALID_FUNCTION_ARGUMENT) BoundVariables(io.prestosql.metadata.BoundVariables) DEFAULT_NAMESPACE(io.prestosql.spi.connector.CatalogSchemaName.DEFAULT_NAMESPACE) USE_BOXED_TYPE(io.prestosql.spi.function.BuiltInScalarFunctionImplementation.NullConvention.USE_BOXED_TYPE) UsedByGeneratedCode(io.prestosql.spi.annotation.UsedByGeneratedCode) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) VARCHAR(io.prestosql.spi.type.VarcharType.VARCHAR) ImmutableList(com.google.common.collect.ImmutableList) ConnectorSession(io.prestosql.spi.connector.ConnectorSession) Map(java.util.Map) RETURN_NULL_ON_NULL(io.prestosql.spi.function.BuiltInScalarFunctionImplementation.NullConvention.RETURN_NULL_ON_NULL) Type(io.prestosql.spi.type.Type) Signature(io.prestosql.spi.function.Signature) Block(io.prestosql.spi.block.Block) PrestoException(io.prestosql.spi.PrestoException) CastType(io.prestosql.metadata.CastType) SqlScalarFunction(io.prestosql.metadata.SqlScalarFunction) BlockBuilder(io.prestosql.spi.block.BlockBuilder) MethodHandles(java.lang.invoke.MethodHandles) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Reflection.methodHandle(io.prestosql.spi.util.Reflection.methodHandle) PageBuilder(io.prestosql.spi.PageBuilder) Signature.typeVariable(io.prestosql.spi.function.Signature.typeVariable) List(java.util.List) MethodType(java.lang.invoke.MethodType) GENERIC_INTERNAL_ERROR(io.prestosql.spi.StandardErrorCode.GENERIC_INTERNAL_ERROR) ArgumentProperty.valueTypeArgumentProperty(io.prestosql.spi.function.BuiltInScalarFunctionImplementation.ArgumentProperty.valueTypeArgumentProperty) Optional(java.util.Optional) TypeSignature(io.prestosql.spi.type.TypeSignature) FunctionAndTypeManager(io.prestosql.metadata.FunctionAndTypeManager) ArgumentProperty(io.prestosql.spi.function.BuiltInScalarFunctionImplementation.ArgumentProperty) ArgumentProperty.valueTypeArgumentProperty(io.prestosql.spi.function.BuiltInScalarFunctionImplementation.ArgumentProperty.valueTypeArgumentProperty) BuiltInScalarFunctionImplementation(io.prestosql.spi.function.BuiltInScalarFunctionImplementation) PrestoException(io.prestosql.spi.PrestoException) UnknownType(io.prestosql.spi.type.UnknownType) UnknownType(io.prestosql.spi.type.UnknownType) Type(io.prestosql.spi.type.Type) CastType(io.prestosql.metadata.CastType) MethodType(java.lang.invoke.MethodType) Slice(io.airlift.slice.Slice) Block(io.prestosql.spi.block.Block) ConnectorSession(io.prestosql.spi.connector.ConnectorSession) MethodHandle(java.lang.invoke.MethodHandle)

Example 4 with FunctionAndTypeManager

use of io.prestosql.metadata.FunctionAndTypeManager in project hetu-core by openlookeng.

the class NullIfCodeGenerator method generateExpression.

@Override
public BytecodeNode generateExpression(FunctionHandle functionHandle, BytecodeGeneratorContext generatorContext, Type returnType, List<RowExpression> arguments) {
    Scope scope = generatorContext.getScope();
    RowExpression first = arguments.get(0);
    RowExpression second = arguments.get(1);
    LabelNode notMatch = new LabelNode("notMatch");
    // push first arg on the stack
    Variable firstValue = scope.createTempVariable(first.getType().getJavaType());
    BytecodeBlock block = new BytecodeBlock().comment("check if first arg is null").append(generatorContext.generate(first)).append(ifWasNullPopAndGoto(scope, notMatch, void.class)).dup(first.getType().getJavaType()).putVariable(firstValue);
    Type firstType = first.getType();
    Type secondType = second.getType();
    // if (equal(cast(first as <common type>), cast(second as <common type>))
    FunctionAndTypeManager functionAndTypeManager = generatorContext.getFunctionManager();
    FunctionHandle equalFunction = functionAndTypeManager.resolveOperatorFunctionHandle(EQUAL, TypeSignatureProvider.fromTypes(firstType, secondType));
    FunctionMetadata equalFunctionMetadata = functionAndTypeManager.getFunctionMetadata(equalFunction);
    BuiltInScalarFunctionImplementation equalsFunction = generatorContext.getFunctionManager().getBuiltInScalarFunctionImplementation(equalFunction);
    BytecodeNode equalsCall = generatorContext.generateCall(EQUAL.name(), equalsFunction, ImmutableList.of(cast(generatorContext, firstValue, firstType, equalFunctionMetadata.getArgumentTypes().get(0)), cast(generatorContext, generatorContext.generate(second, Optional.empty()), secondType, equalFunctionMetadata.getArgumentTypes().get(1))));
    BytecodeBlock conditionBlock = new BytecodeBlock().append(equalsCall).append(BytecodeUtils.ifWasNullClearPopAndGoto(scope, notMatch, void.class, boolean.class));
    // if first and second are equal, return null
    BytecodeBlock trueBlock = new BytecodeBlock().append(generatorContext.wasNull().set(constantTrue())).pop(first.getType().getJavaType()).pushJavaDefault(first.getType().getJavaType());
    // else return first (which is still on the stack
    block.append(new IfStatement().condition(conditionBlock).ifTrue(trueBlock).ifFalse(notMatch));
    return block;
}
Also used : LabelNode(io.airlift.bytecode.instruction.LabelNode) FunctionMetadata(io.prestosql.spi.function.FunctionMetadata) IfStatement(io.airlift.bytecode.control.IfStatement) CastType(io.prestosql.metadata.CastType) Type(io.prestosql.spi.type.Type) Variable(io.airlift.bytecode.Variable) Scope(io.airlift.bytecode.Scope) FunctionAndTypeManager(io.prestosql.metadata.FunctionAndTypeManager) BuiltInScalarFunctionImplementation(io.prestosql.spi.function.BuiltInScalarFunctionImplementation) BytecodeBlock(io.airlift.bytecode.BytecodeBlock) RowExpression(io.prestosql.spi.relation.RowExpression) BytecodeNode(io.airlift.bytecode.BytecodeNode) FunctionHandle(io.prestosql.spi.function.FunctionHandle)

Example 5 with FunctionAndTypeManager

use of io.prestosql.metadata.FunctionAndTypeManager in project hetu-core by openlookeng.

the class AbstractGreatestLeast method specialize.

@Override
public BuiltInScalarFunctionImplementation specialize(BoundVariables boundVariables, int arity, FunctionAndTypeManager functionAndTypeManager) {
    Type type = boundVariables.getTypeVariable("E");
    checkArgument(type.isOrderable(), "Type must be orderable");
    MethodHandle compareMethod = functionAndTypeManager.getBuiltInScalarFunctionImplementation(functionAndTypeManager.resolveOperatorFunctionHandle(operatorType, TypeSignatureProvider.fromTypes(type, type))).getMethodHandle();
    List<Class<?>> javaTypes = IntStream.range(0, arity).mapToObj(i -> type.getJavaType()).collect(toImmutableList());
    Class<?> clazz = generate(javaTypes, type, compareMethod);
    MethodHandle methodHandle = methodHandle(clazz, getSignature().getNameSuffix(), javaTypes.toArray(new Class<?>[javaTypes.size()]));
    return new BuiltInScalarFunctionImplementation(false, nCopies(javaTypes.size(), valueTypeArgumentProperty(RETURN_NULL_ON_NULL)), methodHandle);
}
Also used : BytecodeUtils.invoke(io.prestosql.sql.gen.BytecodeUtils.invoke) BytecodeBlock(io.airlift.bytecode.BytecodeBlock) INVALID_FUNCTION_ARGUMENT(io.prestosql.spi.StandardErrorCode.INVALID_FUNCTION_ARGUMENT) Scope(io.airlift.bytecode.Scope) DynamicClassLoader(io.airlift.bytecode.DynamicClassLoader) BoundVariables(io.prestosql.metadata.BoundVariables) CompilerUtils.makeClassName(io.prestosql.util.CompilerUtils.makeClassName) Access.a(io.airlift.bytecode.Access.a) UsedByGeneratedCode(io.prestosql.spi.annotation.UsedByGeneratedCode) Parameter.arg(io.airlift.bytecode.Parameter.arg) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) OperatorType(io.prestosql.spi.function.OperatorType) Type(io.prestosql.spi.type.Type) CallSiteBinder(io.prestosql.sql.gen.CallSiteBinder) MethodDefinition(io.airlift.bytecode.MethodDefinition) PrestoException(io.prestosql.spi.PrestoException) SqlScalarFunction(io.prestosql.metadata.SqlScalarFunction) Collections.nCopies(java.util.Collections.nCopies) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Reflection.methodHandle(io.prestosql.spi.util.Reflection.methodHandle) String.format(java.lang.String.format) Collectors.joining(java.util.stream.Collectors.joining) List(java.util.List) PRIVATE(io.airlift.bytecode.Access.PRIVATE) ArgumentProperty.valueTypeArgumentProperty(io.prestosql.spi.function.BuiltInScalarFunctionImplementation.ArgumentProperty.valueTypeArgumentProperty) NOT_SUPPORTED(io.prestosql.spi.StandardErrorCode.NOT_SUPPORTED) FunctionAndTypeManager(io.prestosql.metadata.FunctionAndTypeManager) ClassDefinition(io.airlift.bytecode.ClassDefinition) IntStream(java.util.stream.IntStream) ParameterizedType.type(io.airlift.bytecode.ParameterizedType.type) Variable(io.airlift.bytecode.Variable) BuiltInScalarFunctionImplementation(io.prestosql.spi.function.BuiltInScalarFunctionImplementation) MethodHandle(java.lang.invoke.MethodHandle) FunctionKind(io.prestosql.spi.function.FunctionKind) StandardTypes(io.prestosql.spi.type.StandardTypes) Signature.orderableTypeParameter(io.prestosql.spi.function.Signature.orderableTypeParameter) TypeSignatureProvider(io.prestosql.sql.analyzer.TypeSignatureProvider) Parameter(io.airlift.bytecode.Parameter) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) ImmutableList(com.google.common.collect.ImmutableList) Failures.checkCondition(io.prestosql.util.Failures.checkCondition) CompilerUtils.defineClass(io.prestosql.util.CompilerUtils.defineClass) Objects.requireNonNull(java.util.Objects.requireNonNull) RETURN_NULL_ON_NULL(io.prestosql.spi.function.BuiltInScalarFunctionImplementation.NullConvention.RETURN_NULL_ON_NULL) Signature(io.prestosql.spi.function.Signature) FINAL(io.airlift.bytecode.Access.FINAL) STATIC(io.airlift.bytecode.Access.STATIC) IfStatement(io.airlift.bytecode.control.IfStatement) PUBLIC(io.airlift.bytecode.Access.PUBLIC) OperatorType(io.prestosql.spi.function.OperatorType) Type(io.prestosql.spi.type.Type) BuiltInScalarFunctionImplementation(io.prestosql.spi.function.BuiltInScalarFunctionImplementation) CompilerUtils.defineClass(io.prestosql.util.CompilerUtils.defineClass) MethodHandle(java.lang.invoke.MethodHandle)

Aggregations

FunctionAndTypeManager (io.prestosql.metadata.FunctionAndTypeManager)8 BuiltInScalarFunctionImplementation (io.prestosql.spi.function.BuiltInScalarFunctionImplementation)7 Type (io.prestosql.spi.type.Type)6 ImmutableList (com.google.common.collect.ImmutableList)5 BoundVariables (io.prestosql.metadata.BoundVariables)5 PrestoException (io.prestosql.spi.PrestoException)5 UsedByGeneratedCode (io.prestosql.spi.annotation.UsedByGeneratedCode)5 ArgumentProperty.valueTypeArgumentProperty (io.prestosql.spi.function.BuiltInScalarFunctionImplementation.ArgumentProperty.valueTypeArgumentProperty)5 RETURN_NULL_ON_NULL (io.prestosql.spi.function.BuiltInScalarFunctionImplementation.NullConvention.RETURN_NULL_ON_NULL)5 Signature (io.prestosql.spi.function.Signature)5 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)4 Slice (io.airlift.slice.Slice)4 CastType (io.prestosql.metadata.CastType)4 SqlScalarFunction (io.prestosql.metadata.SqlScalarFunction)4 INVALID_FUNCTION_ARGUMENT (io.prestosql.spi.StandardErrorCode.INVALID_FUNCTION_ARGUMENT)4 Block (io.prestosql.spi.block.Block)4 ConnectorSession (io.prestosql.spi.connector.ConnectorSession)4 QualifiedObjectName (io.prestosql.spi.connector.QualifiedObjectName)4 FunctionHandle (io.prestosql.spi.function.FunctionHandle)4 TypeSignature.parseTypeSignature (io.prestosql.spi.type.TypeSignature.parseTypeSignature)4