Search in sources :

Example 1 with ArrayType

use of io.trino.spi.type.ArrayType in project trino by trinodb.

the class ArrayTransformFunction method specialize.

@Override
protected ScalarFunctionImplementation specialize(BoundSignature boundSignature) {
    Type inputType = ((ArrayType) boundSignature.getArgumentTypes().get(0)).getElementType();
    Type outputType = ((ArrayType) boundSignature.getReturnType()).getElementType();
    Class<?> generatedClass = generateTransform(inputType, outputType);
    return new ChoicesScalarFunctionImplementation(boundSignature, FAIL_ON_NULL, ImmutableList.of(NEVER_NULL, FUNCTION), ImmutableList.of(UnaryFunctionInterface.class), methodHandle(generatedClass, "transform", PageBuilder.class, Block.class, UnaryFunctionInterface.class), Optional.of(methodHandle(generatedClass, "createPageBuilder")));
}
Also used : ArrayType(io.trino.spi.type.ArrayType) ArrayType(io.trino.spi.type.ArrayType) SqlTypeBytecodeExpression.constantType(io.trino.sql.gen.SqlTypeBytecodeExpression.constantType) Type(io.trino.spi.type.Type) TypeSignature.functionType(io.trino.spi.type.TypeSignature.functionType) TypeSignature.arrayType(io.trino.spi.type.TypeSignature.arrayType) UnaryFunctionInterface(io.trino.sql.gen.lambda.UnaryFunctionInterface) BytecodeBlock(io.airlift.bytecode.BytecodeBlock) Block(io.trino.spi.block.Block) PageBuilder(io.trino.spi.PageBuilder)

Example 2 with ArrayType

use of io.trino.spi.type.ArrayType in project trino by trinodb.

the class ArrayReduceFunction method specialize.

@Override
protected ScalarFunctionImplementation specialize(BoundSignature boundSignature) {
    ArrayType arrayType = (ArrayType) boundSignature.getArgumentTypes().get(0);
    Type inputType = arrayType.getElementType();
    Type intermediateType = boundSignature.getArgumentTypes().get(1);
    Type outputType = boundSignature.getReturnType();
    MethodHandle methodHandle = METHOD_HANDLE.bindTo(inputType);
    return new ChoicesScalarFunctionImplementation(boundSignature, NULLABLE_RETURN, ImmutableList.of(NEVER_NULL, BOXED_NULLABLE, FUNCTION, FUNCTION), ImmutableList.of(BinaryFunctionInterface.class, UnaryFunctionInterface.class), methodHandle.asType(methodHandle.type().changeParameterType(1, Primitives.wrap(intermediateType.getJavaType())).changeReturnType(Primitives.wrap(outputType.getJavaType()))), Optional.empty());
}
Also used : ArrayType(io.trino.spi.type.ArrayType) Type(io.trino.spi.type.Type) TypeSignature.functionType(io.trino.spi.type.TypeSignature.functionType) TypeSignature.arrayType(io.trino.spi.type.TypeSignature.arrayType) ArrayType(io.trino.spi.type.ArrayType) BinaryFunctionInterface(io.trino.sql.gen.lambda.BinaryFunctionInterface) UnaryFunctionInterface(io.trino.sql.gen.lambda.UnaryFunctionInterface) MethodHandle(java.lang.invoke.MethodHandle)

Example 3 with ArrayType

use of io.trino.spi.type.ArrayType in project trino by trinodb.

the class ExtractSpatialJoins method addPartitioningNodes.

private static PlanNode addPartitioningNodes(PlannerContext plannerContext, Context context, PlanNode node, Symbol partitionSymbol, KdbTree kdbTree, Expression geometry, Optional<Expression> radius) {
    Assignments.Builder projections = Assignments.builder();
    for (Symbol outputSymbol : node.getOutputSymbols()) {
        projections.putIdentity(outputSymbol);
    }
    TypeSignature typeSignature = new TypeSignature(KDB_TREE_TYPENAME);
    FunctionCallBuilder spatialPartitionsCall = FunctionCallBuilder.resolve(context.getSession(), plannerContext.getMetadata()).setName(QualifiedName.of("spatial_partitions")).addArgument(typeSignature, new Cast(new StringLiteral(KdbTreeUtils.toJson(kdbTree)), toSqlType(plannerContext.getTypeManager().getType(typeSignature)))).addArgument(GEOMETRY_TYPE_SIGNATURE, geometry);
    radius.ifPresent(value -> spatialPartitionsCall.addArgument(DOUBLE, value));
    FunctionCall partitioningFunction = spatialPartitionsCall.build();
    Symbol partitionsSymbol = context.getSymbolAllocator().newSymbol(partitioningFunction, new ArrayType(INTEGER));
    projections.put(partitionsSymbol, partitioningFunction);
    return new UnnestNode(context.getIdAllocator().getNextId(), new ProjectNode(context.getIdAllocator().getNextId(), node, projections.build()), node.getOutputSymbols(), ImmutableList.of(new UnnestNode.Mapping(partitionsSymbol, ImmutableList.of(partitionSymbol))), Optional.empty(), INNER, Optional.empty());
}
Also used : Cast(io.trino.sql.tree.Cast) ArrayType(io.trino.spi.type.ArrayType) TypeSignature(io.trino.spi.type.TypeSignature) StringLiteral(io.trino.sql.tree.StringLiteral) UnnestNode(io.trino.sql.planner.plan.UnnestNode) Symbol(io.trino.sql.planner.Symbol) Assignments(io.trino.sql.planner.plan.Assignments) ProjectNode(io.trino.sql.planner.plan.ProjectNode) FunctionCall(io.trino.sql.tree.FunctionCall) FunctionCallBuilder(io.trino.sql.planner.FunctionCallBuilder)

Example 4 with ArrayType

use of io.trino.spi.type.ArrayType in project trino by trinodb.

the class SessionPropertyManager method getJsonCodecForType.

private static <T> JsonCodec<T> getJsonCodecForType(Type type) {
    if (VarcharType.VARCHAR.equals(type)) {
        return (JsonCodec<T>) JSON_CODEC_FACTORY.jsonCodec(String.class);
    }
    if (BooleanType.BOOLEAN.equals(type)) {
        return (JsonCodec<T>) JSON_CODEC_FACTORY.jsonCodec(Boolean.class);
    }
    if (BigintType.BIGINT.equals(type)) {
        return (JsonCodec<T>) JSON_CODEC_FACTORY.jsonCodec(Long.class);
    }
    if (IntegerType.INTEGER.equals(type)) {
        return (JsonCodec<T>) JSON_CODEC_FACTORY.jsonCodec(Integer.class);
    }
    if (DoubleType.DOUBLE.equals(type)) {
        return (JsonCodec<T>) JSON_CODEC_FACTORY.jsonCodec(Double.class);
    }
    if (type instanceof ArrayType) {
        Type elementType = ((ArrayType) type).getElementType();
        return (JsonCodec<T>) JSON_CODEC_FACTORY.listJsonCodec(getJsonCodecForType(elementType));
    }
    if (type instanceof MapType) {
        Type keyType = ((MapType) type).getKeyType();
        Type valueType = ((MapType) type).getValueType();
        return (JsonCodec<T>) JSON_CODEC_FACTORY.mapJsonCodec(getMapKeyType(keyType), getJsonCodecForType(valueType));
    }
    throw new TrinoException(INVALID_SESSION_PROPERTY, format("Session property type %s is not supported", type));
}
Also used : ArrayType(io.trino.spi.type.ArrayType) JsonCodec(io.airlift.json.JsonCodec) DoubleType(io.trino.spi.type.DoubleType) Type(io.trino.spi.type.Type) BooleanType(io.trino.spi.type.BooleanType) BigintType(io.trino.spi.type.BigintType) VarcharType(io.trino.spi.type.VarcharType) IntegerType(io.trino.spi.type.IntegerType) MapType(io.trino.spi.type.MapType) ArrayType(io.trino.spi.type.ArrayType) TrinoException(io.trino.spi.TrinoException) MapType(io.trino.spi.type.MapType)

Example 5 with ArrayType

use of io.trino.spi.type.ArrayType in project trino by trinodb.

the class ZipFunction method specialize.

@Override
protected ScalarFunctionImplementation specialize(BoundSignature boundSignature) {
    List<Type> types = boundSignature.getArgumentTypes().stream().map(ArrayType.class::cast).map(ArrayType::getElementType).collect(toImmutableList());
    List<Class<?>> javaArgumentTypes = nCopies(types.size(), Block.class);
    MethodHandle methodHandle = METHOD_HANDLE.bindTo(types).asVarargsCollector(Block[].class).asType(methodType(Block.class, javaArgumentTypes));
    return new ChoicesScalarFunctionImplementation(boundSignature, FAIL_ON_NULL, nCopies(types.size(), NEVER_NULL), methodHandle);
}
Also used : ArrayType(io.trino.spi.type.ArrayType) Type(io.trino.spi.type.Type) TypeSignature.arrayType(io.trino.spi.type.TypeSignature.arrayType) MethodType.methodType(java.lang.invoke.MethodType.methodType) RowType(io.trino.spi.type.RowType) ArrayType(io.trino.spi.type.ArrayType) TypeSignature.rowType(io.trino.spi.type.TypeSignature.rowType) Block(io.trino.spi.block.Block) MethodHandle(java.lang.invoke.MethodHandle)

Aggregations

ArrayType (io.trino.spi.type.ArrayType)289 Test (org.testng.annotations.Test)205 Type (io.trino.spi.type.Type)92 RowType (io.trino.spi.type.RowType)86 ImmutableList (com.google.common.collect.ImmutableList)66 List (java.util.List)62 ArrayList (java.util.ArrayList)59 MapType (io.trino.spi.type.MapType)43 Arrays.asList (java.util.Arrays.asList)36 Collections.singletonList (java.util.Collections.singletonList)34 VarcharType (io.trino.spi.type.VarcharType)32 VarcharType.createUnboundedVarcharType (io.trino.spi.type.VarcharType.createUnboundedVarcharType)32 BlockBuilder (io.trino.spi.block.BlockBuilder)31 MessageType (org.apache.parquet.schema.MessageType)31 DecimalType.createDecimalType (io.trino.spi.type.DecimalType.createDecimalType)30 MessageTypeParser.parseMessageType (org.apache.parquet.schema.MessageTypeParser.parseMessageType)27 DecimalType (io.trino.spi.type.DecimalType)26 StructuralTestUtil.mapType (io.trino.testing.StructuralTestUtil.mapType)24 Block (io.trino.spi.block.Block)23 Map (java.util.Map)23