Search in sources :

Example 6 with BOOLEAN

use of io.prestosql.spi.type.BooleanType.BOOLEAN in project hetu-core by openlookeng.

the class TestSemiJoinStatsRule method testSemiJoinPropagatesSourceStats.

@Test
public void testSemiJoinPropagatesSourceStats() {
    SymbolStatsEstimate stats = SymbolStatsEstimate.builder().setLowValue(1).setHighValue(10).setDistinctValuesCount(5).setNullsFraction(0.3).build();
    tester().assertStatsFor(pb -> {
        Symbol a = pb.symbol("a", BIGINT);
        Symbol b = pb.symbol("b", BIGINT);
        Symbol c = pb.symbol("c", BIGINT);
        Symbol semiJoinOutput = pb.symbol("sjo", BOOLEAN);
        return pb.semiJoin(pb.values(a, b), pb.values(c), a, c, semiJoinOutput, Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty());
    }).withSourceStats(0, PlanNodeStatsEstimate.builder().setOutputRowCount(10).addSymbolStatistics(new Symbol("a"), stats).addSymbolStatistics(new Symbol("b"), stats).build()).withSourceStats(1, PlanNodeStatsEstimate.builder().setOutputRowCount(20).addSymbolStatistics(new Symbol("c"), stats).build()).check(check -> check.outputRowsCount(10).symbolStats("a", assertion -> assertion.isEqualTo(stats)).symbolStats("b", assertion -> assertion.isEqualTo(stats)).symbolStatsUnknown("c").symbolStatsUnknown("sjo"));
}
Also used : Symbol(io.prestosql.spi.plan.Symbol) Optional(java.util.Optional) BOOLEAN(io.prestosql.spi.type.BooleanType.BOOLEAN) Test(org.testng.annotations.Test) BIGINT(io.prestosql.spi.type.BigintType.BIGINT) Symbol(io.prestosql.spi.plan.Symbol) Test(org.testng.annotations.Test)

Example 7 with BOOLEAN

use of io.prestosql.spi.type.BooleanType.BOOLEAN in project hetu-core by openlookeng.

the class TestHistogram method testManyValuesInducingRehash.

private void testManyValuesInducingRehash(InternalAggregationFunction aggregationFunction) {
    double distinctFraction = 0.1f;
    int numGroups = 50000;
    int itemCount = 30;
    Random random = new Random();
    GroupedAccumulator groupedAccumulator = createGroupedAccumulator(aggregationFunction);
    for (int j = 0; j < numGroups; j++) {
        Map<String, Long> expectedValues = new HashMap<>();
        List<String> valueList = new ArrayList<>();
        for (int i = 0; i < itemCount; i++) {
            String str = String.valueOf(i % 10);
            String item = IntStream.range(0, itemCount).mapToObj(x -> str).collect(Collectors.joining());
            boolean distinctValue = random.nextDouble() < distinctFraction;
            if (distinctValue) {
                // produce a unique value for the histogram
                item = j + "-" + item;
                valueList.add(item);
            } else {
                valueList.add(item);
            }
            expectedValues.compute(item, (k, v) -> v == null ? 1L : ++v);
        }
        Block block = createStringsBlock(valueList);
        AggregationTestInputBuilder testInputBuilder = new AggregationTestInputBuilder(new Block[] { block }, aggregationFunction);
        AggregationTestInput test1 = testInputBuilder.build();
        test1.runPagesOnAccumulatorWithAssertion(j, groupedAccumulator, new AggregationTestOutput(expectedValues));
    }
}
Also used : DateTimeZone(org.joda.time.DateTimeZone) Arrays(java.util.Arrays) NAME(io.prestosql.operator.aggregation.histogram.Histogram.NAME) DateTimeZoneIndex.getDateTimeZone(io.prestosql.spi.util.DateTimeZoneIndex.getDateTimeZone) AggregationTestUtils.assertAggregation(io.prestosql.operator.aggregation.AggregationTestUtils.assertAggregation) StructuralTestUtil.mapBlockOf(io.prestosql.util.StructuralTestUtil.mapBlockOf) Test(org.testng.annotations.Test) Random(java.util.Random) AggregationTestInput(io.prestosql.operator.aggregation.groupby.AggregationTestInput) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) Map(java.util.Map) RowType(io.prestosql.spi.type.RowType) BOOLEAN(io.prestosql.spi.type.BooleanType.BOOLEAN) TimeZoneKey.getTimeZoneKey(io.prestosql.spi.type.TimeZoneKey.getTimeZoneKey) Ints(org.testng.internal.collections.Ints) BIGINT(io.prestosql.spi.type.BigintType.BIGINT) BlockAssertions.createStringsBlock(io.prestosql.block.BlockAssertions.createStringsBlock) ImmutableMap(com.google.common.collect.ImmutableMap) BlockBuilder(io.prestosql.spi.block.BlockBuilder) SqlTimestampWithTimeZone(io.prestosql.spi.type.SqlTimestampWithTimeZone) MetadataManager.createTestMetadataManager(io.prestosql.metadata.MetadataManager.createTestMetadataManager) ArrayType(io.prestosql.spi.type.ArrayType) TimeZoneKey(io.prestosql.spi.type.TimeZoneKey) Collectors(java.util.stream.Collectors) Metadata(io.prestosql.metadata.Metadata) List(java.util.List) Optional(java.util.Optional) TIMESTAMP_WITH_TIME_ZONE(io.prestosql.spi.type.TimestampWithTimeZoneType.TIMESTAMP_WITH_TIME_ZONE) TypeSignature(io.prestosql.spi.type.TypeSignature) GroupByAggregationTestUtils(io.prestosql.operator.aggregation.groupby.GroupByAggregationTestUtils) BlockAssertions.createStringArraysBlock(io.prestosql.block.BlockAssertions.createStringArraysBlock) IntStream(java.util.stream.IntStream) DateTimeEncoding.packDateTimeWithZone(io.prestosql.spi.type.DateTimeEncoding.packDateTimeWithZone) StandardTypes(io.prestosql.spi.type.StandardTypes) AggregationTestOutput(io.prestosql.operator.aggregation.groupby.AggregationTestOutput) HashMap(java.util.HashMap) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) ArrayList(java.util.ArrayList) MapType(io.prestosql.spi.type.MapType) OperatorAssertion.toRow(io.prestosql.operator.OperatorAssertion.toRow) VARCHAR(io.prestosql.spi.type.VarcharType.VARCHAR) ImmutableList(com.google.common.collect.ImmutableList) DOUBLE(io.prestosql.spi.type.DoubleType.DOUBLE) Signature(io.prestosql.spi.function.Signature) Block(io.prestosql.spi.block.Block) NEW(io.prestosql.operator.aggregation.histogram.HistogramGroupImplementation.NEW) BlockAssertions.createBooleansBlock(io.prestosql.block.BlockAssertions.createBooleansBlock) DateTime(org.joda.time.DateTime) StructuralTestUtil.mapType(io.prestosql.util.StructuralTestUtil.mapType) BlockAssertions.createDoublesBlock(io.prestosql.block.BlockAssertions.createDoublesBlock) HistogramGroupImplementation(io.prestosql.operator.aggregation.histogram.HistogramGroupImplementation) BlockAssertions.createLongsBlock(io.prestosql.block.BlockAssertions.createLongsBlock) AggregationTestInputBuilder(io.prestosql.operator.aggregation.groupby.AggregationTestInputBuilder) FeaturesConfig(io.prestosql.sql.analyzer.FeaturesConfig) AGGREGATE(io.prestosql.spi.function.FunctionKind.AGGREGATE) Assert.assertTrue(org.testng.Assert.assertTrue) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Random(java.util.Random) AggregationTestOutput(io.prestosql.operator.aggregation.groupby.AggregationTestOutput) BlockAssertions.createStringsBlock(io.prestosql.block.BlockAssertions.createStringsBlock) BlockAssertions.createStringArraysBlock(io.prestosql.block.BlockAssertions.createStringArraysBlock) Block(io.prestosql.spi.block.Block) BlockAssertions.createBooleansBlock(io.prestosql.block.BlockAssertions.createBooleansBlock) BlockAssertions.createDoublesBlock(io.prestosql.block.BlockAssertions.createDoublesBlock) BlockAssertions.createLongsBlock(io.prestosql.block.BlockAssertions.createLongsBlock) AggregationTestInput(io.prestosql.operator.aggregation.groupby.AggregationTestInput) AggregationTestInputBuilder(io.prestosql.operator.aggregation.groupby.AggregationTestInputBuilder)

Example 8 with BOOLEAN

use of io.prestosql.spi.type.BooleanType.BOOLEAN in project hetu-core by openlookeng.

the class SetOperationNodeTranslator method makeSetContainmentPlan.

public TranslationResult makeSetContainmentPlan(SetOperationNode node) {
    checkArgument(!(node instanceof UnionNode), "Cannot simplify a UnionNode");
    List<Symbol> markers = allocateSymbols(node.getSources().size(), MARKER, BOOLEAN);
    // identity projection for all the fields in each of the sources plus marker columns
    List<PlanNode> withMarkers = appendMarkers(markers, node.getSources(), node);
    // add a union over all the rewritten sources. The outputs of the union have the same name as the
    // original intersect node
    List<Symbol> outputs = node.getOutputSymbols();
    UnionNode union = union(withMarkers, ImmutableList.copyOf(concat(outputs, markers)));
    // add count aggregations and filter rows where any of the counts is >= 1
    List<Symbol> aggregationOutputs = allocateSymbols(markers.size(), "count", BIGINT);
    AggregationNode aggregation = computeCounts(union, outputs, markers, aggregationOutputs);
    List<Expression> presentExpression = aggregationOutputs.stream().map(symbol -> new ComparisonExpression(GREATER_THAN_OR_EQUAL, toSymbolReference(symbol), GENERIC_LITERAL)).collect(toImmutableList());
    return new TranslationResult(aggregation, presentExpression);
}
Also used : GREATER_THAN_OR_EQUAL(io.prestosql.sql.tree.ComparisonExpression.Operator.GREATER_THAN_OR_EQUAL) StandardTypes(io.prestosql.spi.type.StandardTypes) Literal(io.prestosql.sql.tree.Literal) DEFAULT_NAMESPACE(io.prestosql.spi.connector.CatalogSchemaName.DEFAULT_NAMESPACE) TRUE_LITERAL(io.prestosql.sql.tree.BooleanLiteral.TRUE_LITERAL) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) AggregationNode(io.prestosql.spi.plan.AggregationNode) CallExpression(io.prestosql.spi.relation.CallExpression) Cast(io.prestosql.sql.tree.Cast) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) ImmutableList(com.google.common.collect.ImmutableList) Iterables.concat(com.google.common.collect.Iterables.concat) Map(java.util.Map) OriginalExpressionUtils.castToRowExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression) Objects.requireNonNull(java.util.Objects.requireNonNull) BOOLEAN(io.prestosql.spi.type.BooleanType.BOOLEAN) Type(io.prestosql.spi.type.Type) BIGINT(io.prestosql.spi.type.BigintType.BIGINT) AggregationNode.singleGroupingSet(io.prestosql.spi.plan.AggregationNode.singleGroupingSet) Symbol(io.prestosql.spi.plan.Symbol) SetOperationNodeUtils.sourceSymbolMap(io.prestosql.sql.planner.optimizations.SetOperationNodeUtils.sourceSymbolMap) TypeSignatureProvider.fromTypes(io.prestosql.sql.analyzer.TypeSignatureProvider.fromTypes) ImmutableMap(com.google.common.collect.ImmutableMap) Assignments(io.prestosql.spi.plan.Assignments) SetOperationNode(io.prestosql.spi.plan.SetOperationNode) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) NullLiteral(io.prestosql.sql.tree.NullLiteral) PlanNode(io.prestosql.spi.plan.PlanNode) ProjectNode(io.prestosql.spi.plan.ProjectNode) Metadata(io.prestosql.metadata.Metadata) PlanSymbolAllocator(io.prestosql.sql.planner.PlanSymbolAllocator) SymbolUtils.toSymbolReference(io.prestosql.sql.planner.SymbolUtils.toSymbolReference) List(java.util.List) GenericLiteral(io.prestosql.sql.tree.GenericLiteral) SymbolReference(io.prestosql.sql.tree.SymbolReference) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) PlanNodeIdAllocator(io.prestosql.spi.plan.PlanNodeIdAllocator) UnionNode(io.prestosql.spi.plan.UnionNode) Optional(java.util.Optional) Expression(io.prestosql.sql.tree.Expression) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) PlanNode(io.prestosql.spi.plan.PlanNode) UnionNode(io.prestosql.spi.plan.UnionNode) CallExpression(io.prestosql.spi.relation.CallExpression) OriginalExpressionUtils.castToRowExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) Expression(io.prestosql.sql.tree.Expression) Symbol(io.prestosql.spi.plan.Symbol) AggregationNode(io.prestosql.spi.plan.AggregationNode)

Example 9 with BOOLEAN

use of io.prestosql.spi.type.BooleanType.BOOLEAN in project hetu-core by openlookeng.

the class MongoSession method guessFieldType.

private Optional<TypeSignature> guessFieldType(Object value) {
    if (value == null) {
        return Optional.empty();
    }
    TypeSignature typeSignature = null;
    if (value instanceof String) {
        typeSignature = createUnboundedVarcharType().getTypeSignature();
    } else if (value instanceof Integer || value instanceof Long) {
        typeSignature = BIGINT.getTypeSignature();
    } else if (value instanceof Boolean) {
        typeSignature = BOOLEAN.getTypeSignature();
    } else if (value instanceof Float || value instanceof Double) {
        typeSignature = DOUBLE.getTypeSignature();
    } else if (value instanceof Date) {
        typeSignature = TIMESTAMP.getTypeSignature();
    } else if (value instanceof ObjectId) {
        typeSignature = OBJECT_ID.getTypeSignature();
    } else if (value instanceof List) {
        List<Optional<TypeSignature>> subTypes = ((List<?>) value).stream().map(this::guessFieldType).collect(toList());
        if (subTypes.isEmpty() || subTypes.stream().anyMatch(Optional::isPresent)) {
            return Optional.empty();
        }
        Set<TypeSignature> signatures = subTypes.stream().map(Optional::get).collect(toSet());
        if (signatures.size() == 1) {
            typeSignature = new TypeSignature(StandardTypes.ARRAY, signatures.stream().map(TypeSignatureParameter::of).collect(Collectors.toList()));
        } else {
            // TODO: presto cli doesn't handle empty field name row type yet
            typeSignature = new TypeSignature(StandardTypes.ROW, IntStream.range(0, subTypes.size()).mapToObj(idx -> TypeSignatureParameter.of(new NamedTypeSignature(Optional.of(new RowFieldName(format("%s%d", implicitPrefix, idx + 1), false)), subTypes.get(idx).get()))).collect(toList()));
        }
    } else if (value instanceof Document) {
        List<TypeSignatureParameter> parameters = new ArrayList<>();
        for (String key : ((Document) value).keySet()) {
            Optional<TypeSignature> fieldType = guessFieldType(((Document) value).get(key));
            if (fieldType.isPresent()) {
                parameters.add(TypeSignatureParameter.of(new NamedTypeSignature(Optional.of(new RowFieldName(key, false)), fieldType.get())));
            }
        }
        if (!parameters.isEmpty()) {
            typeSignature = new TypeSignature(StandardTypes.ROW, parameters);
        }
    }
    return Optional.ofNullable(typeSignature);
}
Also used : Document(org.bson.Document) Arrays(java.util.Arrays) OBJECT_ID(io.hetu.core.plugin.mongodb.ObjectIdType.OBJECT_ID) LoadingCache(com.google.common.cache.LoadingCache) Date(java.util.Date) MongoDatabase(com.mongodb.client.MongoDatabase) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) TableNotFoundException(io.prestosql.spi.connector.TableNotFoundException) Map(java.util.Map) BOOLEAN(io.prestosql.spi.type.BooleanType.BOOLEAN) RowFieldName(io.prestosql.spi.type.RowFieldName) Type(io.prestosql.spi.type.Type) BIGINT(io.prestosql.spi.type.BigintType.BIGINT) ENGLISH(java.util.Locale.ENGLISH) Collectors.toSet(java.util.stream.Collectors.toSet) PrestoException(io.prestosql.spi.PrestoException) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Set(java.util.Set) TIMESTAMP(io.prestosql.spi.type.TimestampType.TIMESTAMP) TINYINT(io.prestosql.spi.type.TinyintType.TINYINT) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Preconditions.checkState(com.google.common.base.Preconditions.checkState) CacheLoader(com.google.common.cache.CacheLoader) List(java.util.List) FindIterable(com.mongodb.client.FindIterable) VarcharType.createUnboundedVarcharType(io.prestosql.spi.type.VarcharType.createUnboundedVarcharType) Domain(io.prestosql.spi.predicate.Domain) Optional(java.util.Optional) CacheBuilder(com.google.common.cache.CacheBuilder) TypeSignature(io.prestosql.spi.type.TypeSignature) IntStream(java.util.stream.IntStream) MongoCollection(com.mongodb.client.MongoCollection) Slice(io.airlift.slice.Slice) StandardTypes(io.prestosql.spi.type.StandardTypes) Logger(io.airlift.log.Logger) Shorts(com.google.common.primitives.Shorts) TypeSignatureParameter(io.prestosql.spi.type.TypeSignatureParameter) MINUTES(java.util.concurrent.TimeUnit.MINUTES) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) NamedTypeSignature(io.prestosql.spi.type.NamedTypeSignature) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) ImmutableList(com.google.common.collect.ImmutableList) MongoCursor(com.mongodb.client.MongoCursor) Verify.verify(com.google.common.base.Verify.verify) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) Range(io.prestosql.spi.predicate.Range) Objects.requireNonNull(java.util.Objects.requireNonNull) DOUBLE(io.prestosql.spi.type.DoubleType.DOUBLE) Math.toIntExact(java.lang.Math.toIntExact) IntegerType(io.prestosql.spi.type.IntegerType) ColumnMetadata(io.prestosql.spi.connector.ColumnMetadata) TupleDomain(io.prestosql.spi.predicate.TupleDomain) SignedBytes(com.google.common.primitives.SignedBytes) TypeManager(io.prestosql.spi.type.TypeManager) SchemaNotFoundException(io.prestosql.spi.connector.SchemaNotFoundException) IndexOptions(com.mongodb.client.model.IndexOptions) Throwables.throwIfInstanceOf(com.google.common.base.Throwables.throwIfInstanceOf) Primitives(com.google.common.primitives.Primitives) Collectors.toList(java.util.stream.Collectors.toList) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) SMALLINT(io.prestosql.spi.type.SmallintType.SMALLINT) MongoClient(com.mongodb.MongoClient) DeleteResult(com.mongodb.client.result.DeleteResult) ObjectId(org.bson.types.ObjectId) HOURS(java.util.concurrent.TimeUnit.HOURS) VisibleForTesting(com.google.common.annotations.VisibleForTesting) VarcharType(io.prestosql.spi.type.VarcharType) Optional(java.util.Optional) ObjectId(org.bson.types.ObjectId) RowFieldName(io.prestosql.spi.type.RowFieldName) NamedTypeSignature(io.prestosql.spi.type.NamedTypeSignature) Document(org.bson.Document) Date(java.util.Date) TypeSignature(io.prestosql.spi.type.TypeSignature) NamedTypeSignature(io.prestosql.spi.type.NamedTypeSignature) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) Collectors.toList(java.util.stream.Collectors.toList)

Example 10 with BOOLEAN

use of io.prestosql.spi.type.BooleanType.BOOLEAN in project hetu-core by openlookeng.

the class TestSignatureBinder method testFunction.

@Test
public void testFunction() {
    Signature simple = functionSignature().returnType(parseTypeSignature("boolean")).argumentTypes(parseTypeSignature("function(integer,integer)")).build();
    assertThat(simple).boundTo("integer").fails();
    assertThat(simple).boundTo("function(integer,integer)").succeeds();
    // TODO: Support coercion of return type of lambda
    assertThat(simple).boundTo("function(integer,smallint)").withCoercion().fails();
    assertThat(simple).boundTo("function(integer,bigint)").withCoercion().fails();
    Signature applyTwice = functionSignature().returnType(parseTypeSignature("V")).argumentTypes(parseTypeSignature("T"), parseTypeSignature("function(T,U)"), parseTypeSignature("function(U,V)")).typeVariableConstraints(typeVariable("T"), typeVariable("U"), typeVariable("V")).build();
    assertThat(applyTwice).boundTo("integer", "integer", "integer").fails();
    assertThat(applyTwice).boundTo("integer", "function(integer,varchar)", "function(varchar,double)").produces(BoundVariables.builder().setTypeVariable("T", INTEGER).setTypeVariable("U", VARCHAR).setTypeVariable("V", DOUBLE).build());
    assertThat(applyTwice).boundTo("integer", new TypeSignatureProvider(functionArgumentTypes -> TypeSignature.parseTypeSignature("function(integer,varchar)")), new TypeSignatureProvider(functionArgumentTypes -> TypeSignature.parseTypeSignature("function(varchar,double)"))).produces(BoundVariables.builder().setTypeVariable("T", INTEGER).setTypeVariable("U", VARCHAR).setTypeVariable("V", DOUBLE).build());
    assertThat(applyTwice).boundTo(// pass function argument to non-function position of a function
    new TypeSignatureProvider(functionArgumentTypes -> TypeSignature.parseTypeSignature("function(integer,varchar)")), new TypeSignatureProvider(functionArgumentTypes -> TypeSignature.parseTypeSignature("function(integer,varchar)")), new TypeSignatureProvider(functionArgumentTypes -> TypeSignature.parseTypeSignature("function(varchar,double)"))).fails();
    assertThat(applyTwice).boundTo(new TypeSignatureProvider(functionArgumentTypes -> TypeSignature.parseTypeSignature("function(integer,varchar)")), // pass non-function argument to function position of a function
    "integer", new TypeSignatureProvider(functionArgumentTypes -> TypeSignature.parseTypeSignature("function(varchar,double)"))).fails();
    Signature flatMap = functionSignature().returnType(parseTypeSignature("array(T)")).argumentTypes(parseTypeSignature("array(T)"), parseTypeSignature("function(T, array(T))")).typeVariableConstraints(typeVariable("T")).build();
    assertThat(flatMap).boundTo("array(integer)", "function(integer, array(integer))").produces(BoundVariables.builder().setTypeVariable("T", INTEGER).build());
    Signature varargApply = functionSignature().returnType(parseTypeSignature("T")).argumentTypes(parseTypeSignature("T"), parseTypeSignature("function(T, T)")).typeVariableConstraints(typeVariable("T")).setVariableArity(true).build();
    assertThat(varargApply).boundTo("integer", "function(integer, integer)", "function(integer, integer)", "function(integer, integer)").produces(BoundVariables.builder().setTypeVariable("T", INTEGER).build());
    assertThat(varargApply).boundTo("integer", "function(integer, integer)", "function(integer, double)", "function(double, double)").fails();
    Signature loop = functionSignature().returnType(parseTypeSignature("T")).argumentTypes(parseTypeSignature("T"), parseTypeSignature("function(T, T)")).typeVariableConstraints(typeVariable("T")).build();
    assertThat(loop).boundTo("integer", new TypeSignatureProvider(paramTypes -> new FunctionType(paramTypes, BIGINT).getTypeSignature())).fails();
    assertThat(loop).boundTo("integer", new TypeSignatureProvider(paramTypes -> new FunctionType(paramTypes, BIGINT).getTypeSignature())).withCoercion().produces(BoundVariables.builder().setTypeVariable("T", BIGINT).build());
    // TODO: Support coercion of return type of lambda
    assertThat(loop).withCoercion().boundTo("integer", new TypeSignatureProvider(paramTypes -> new FunctionType(paramTypes, SMALLINT).getTypeSignature())).fails();
    // TODO: Support coercion of return type of lambda
    // Without coercion support for return type of lambda, the return type of lambda must be `varchar(x)` to avoid need for coercions.
    Signature varcharApply = functionSignature().returnType(parseTypeSignature("varchar")).argumentTypes(parseTypeSignature("varchar"), parseTypeSignature("function(varchar, varchar(x))", ImmutableSet.of("x"))).build();
    assertThat(varcharApply).withCoercion().boundTo("varchar(10)", new TypeSignatureProvider(paramTypes -> new FunctionType(paramTypes, createVarcharType(1)).getTypeSignature())).succeeds();
    Signature sortByKey = functionSignature().returnType(parseTypeSignature("array(T)")).argumentTypes(parseTypeSignature("array(T)"), parseTypeSignature("function(T,E)")).typeVariableConstraints(typeVariable("T"), orderableTypeParameter("E")).build();
    assertThat(sortByKey).boundTo("array(integer)", new TypeSignatureProvider(paramTypes -> new FunctionType(paramTypes, VARCHAR).getTypeSignature())).produces(BoundVariables.builder().setTypeVariable("T", INTEGER).setTypeVariable("E", VARCHAR).build());
}
Also used : TypeSignatureProvider(io.prestosql.sql.analyzer.TypeSignatureProvider) StandardTypes(io.prestosql.spi.type.StandardTypes) Signature.orderableTypeParameter(io.prestosql.spi.function.Signature.orderableTypeParameter) TypeSignatureProvider(io.prestosql.sql.analyzer.TypeSignatureProvider) TypeVariableConstraint(io.prestosql.spi.function.TypeVariableConstraint) SCALAR(io.prestosql.spi.function.FunctionKind.SCALAR) Assert.assertEquals(org.testng.Assert.assertEquals) DecimalType(io.prestosql.spi.type.DecimalType) Test(org.testng.annotations.Test) INTEGER(io.prestosql.spi.type.IntegerType.INTEGER) Signature.comparableTypeParameter(io.prestosql.spi.function.Signature.comparableTypeParameter) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) VARCHAR(io.prestosql.spi.type.VarcharType.VARCHAR) ImmutableList(com.google.common.collect.ImmutableList) Objects.requireNonNull(java.util.Objects.requireNonNull) SignatureBuilder(io.prestosql.spi.function.SignatureBuilder) BOOLEAN(io.prestosql.spi.type.BooleanType.BOOLEAN) DOUBLE(io.prestosql.spi.type.DoubleType.DOUBLE) Type(io.prestosql.spi.type.Type) Signature(io.prestosql.spi.function.Signature) BIGINT(io.prestosql.spi.type.BigintType.BIGINT) Assert.assertFalse(org.testng.Assert.assertFalse) ImmutableSet(com.google.common.collect.ImmutableSet) TypeSignatureProvider.fromTypes(io.prestosql.sql.analyzer.TypeSignatureProvider.fromTypes) ImmutableMap(com.google.common.collect.ImmutableMap) MetadataManager.createTestMetadataManager(io.prestosql.metadata.MetadataManager.createTestMetadataManager) Assert.fail(org.testng.Assert.fail) FunctionType(io.prestosql.spi.type.FunctionType) Set(java.util.Set) Assert.assertNotNull(org.testng.Assert.assertNotNull) Signature.typeVariable(io.prestosql.spi.function.Signature.typeVariable) String.format(java.lang.String.format) VarcharType.createVarcharType(io.prestosql.spi.type.VarcharType.createVarcharType) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) SMALLINT(io.prestosql.spi.type.SmallintType.SMALLINT) Optional(java.util.Optional) Assert.assertTrue(org.testng.Assert.assertTrue) TypeSignature(io.prestosql.spi.type.TypeSignature) Signature.withVariadicBound(io.prestosql.spi.function.Signature.withVariadicBound) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) Signature(io.prestosql.spi.function.Signature) TypeSignature(io.prestosql.spi.type.TypeSignature) FunctionType(io.prestosql.spi.type.FunctionType) Test(org.testng.annotations.Test)

Aggregations

BIGINT (io.prestosql.spi.type.BigintType.BIGINT)14 BOOLEAN (io.prestosql.spi.type.BooleanType.BOOLEAN)14 Optional (java.util.Optional)14 ImmutableList (com.google.common.collect.ImmutableList)12 List (java.util.List)12 ImmutableMap (com.google.common.collect.ImmutableMap)11 DOUBLE (io.prestosql.spi.type.DoubleType.DOUBLE)11 Type (io.prestosql.spi.type.Type)11 SMALLINT (io.prestosql.spi.type.SmallintType.SMALLINT)10 INTEGER (io.prestosql.spi.type.IntegerType.INTEGER)9 REAL (io.prestosql.spi.type.RealType.REAL)9 TINYINT (io.prestosql.spi.type.TinyintType.TINYINT)9 Map (java.util.Map)9 StandardTypes (io.prestosql.spi.type.StandardTypes)8 TIMESTAMP (io.prestosql.spi.type.TimestampType.TIMESTAMP)8 Slice (io.airlift.slice.Slice)7 DecimalType (io.prestosql.spi.type.DecimalType)7 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)6 DATE (io.prestosql.spi.type.DateType.DATE)6 MetadataManager.createTestMetadataManager (io.prestosql.metadata.MetadataManager.createTestMetadataManager)5