Search in sources :

Example 6 with FunctionAndTypeManager

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

the class StatisticsAggregationPlanner method createAggregation.

private ColumnStatisticsAggregation createAggregation(QualifiedName functionName, SymbolReference input, Type inputType, Type outputType) {
    Signature signature = metadata.getFunctionAndTypeManager().resolveBuiltInFunction(functionName, fromTypes(inputType));
    FunctionAndTypeManager functionAndTypeManager = metadata.getFunctionAndTypeManager();
    FunctionHandle functionHandle = functionAndTypeManager.lookupFunction(functionName.getSuffix(), TypeSignatureProvider.fromTypes(ImmutableList.of(inputType)));
    Type resolvedType = metadata.getType(getOnlyElement(signature.getArgumentTypes()));
    verify(resolvedType.equals(inputType), "resolved function input type does not match the input type: %s != %s", resolvedType, inputType);
    return new ColumnStatisticsAggregation(new AggregationNode.Aggregation(new CallExpression(functionName.getSuffix(), functionHandle, outputType, ImmutableList.of(castToRowExpression(input)), Optional.empty()), ImmutableList.of(castToRowExpression(input)), false, Optional.empty(), Optional.empty(), Optional.empty()), outputType);
}
Also used : ColumnStatisticType(io.prestosql.spi.statistics.ColumnStatisticType) TableStatisticType(io.prestosql.spi.statistics.TableStatisticType) Type(io.prestosql.spi.type.Type) FunctionAndTypeManager(io.prestosql.metadata.FunctionAndTypeManager) Signature(io.prestosql.spi.function.Signature) AggregationNode(io.prestosql.spi.plan.AggregationNode) FunctionHandle(io.prestosql.spi.function.FunctionHandle) CallExpression(io.prestosql.spi.relation.CallExpression)

Example 7 with FunctionAndTypeManager

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

the class FormatFunction method specialize.

@Override
public BuiltInScalarFunctionImplementation specialize(BoundVariables boundVariables, int arity, FunctionAndTypeManager functionAndTypeManager) {
    Type rowType = boundVariables.getTypeVariable("T");
    List<BiFunction<ConnectorSession, Block, Object>> converters = mapWithIndex(rowType.getTypeParameters().stream(), (type, index) -> converter(functionAndTypeManager, type, toIntExact(index))).collect(toImmutableList());
    return new BuiltInScalarFunctionImplementation(false, ImmutableList.of(valueTypeArgumentProperty(RETURN_NULL_ON_NULL), valueTypeArgumentProperty(RETURN_NULL_ON_NULL)), METHOD_HANDLE.bindTo(converters));
}
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) Varchars.isVarcharType(io.prestosql.spi.type.Varchars.isVarcharType) DecimalType(io.prestosql.spi.type.DecimalType) Type(io.prestosql.spi.type.Type) Chars.isCharType(io.prestosql.spi.type.Chars.isCharType) CastType(io.prestosql.metadata.CastType) BiFunction(java.util.function.BiFunction) BuiltInScalarFunctionImplementation(io.prestosql.spi.function.BuiltInScalarFunctionImplementation)

Example 8 with FunctionAndTypeManager

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

the class FunctionCallCodeGenerator method generateExpression.

@Override
public BytecodeNode generateExpression(FunctionHandle functionHandle, BytecodeGeneratorContext context, Type returnType, List<RowExpression> arguments) {
    FunctionAndTypeManager functionAndTypeManager = context.getFunctionManager();
    BuiltInScalarFunctionImplementation function = functionAndTypeManager.getBuiltInScalarFunctionImplementation(functionHandle);
    List<BytecodeNode> argumentsBytecode = new ArrayList<>();
    for (int i = 0; i < arguments.size(); i++) {
        RowExpression argument = arguments.get(i);
        BuiltInScalarFunctionImplementation.ArgumentProperty argumentProperty = function.getArgumentProperty(i);
        if (argumentProperty.getArgumentType() == VALUE_TYPE) {
            argumentsBytecode.add(context.generate(argument));
        } else {
            argumentsBytecode.add(context.generate(argument, Optional.of(argumentProperty.getLambdaInterface())));
        }
    }
    return context.generateCall(functionAndTypeManager.getFunctionMetadata(functionHandle).getName().getObjectName(), function, argumentsBytecode);
}
Also used : FunctionAndTypeManager(io.prestosql.metadata.FunctionAndTypeManager) BuiltInScalarFunctionImplementation(io.prestosql.spi.function.BuiltInScalarFunctionImplementation) ArrayList(java.util.ArrayList) RowExpression(io.prestosql.spi.relation.RowExpression) BytecodeNode(io.airlift.bytecode.BytecodeNode)

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