Search in sources :

Example 1 with Metadata

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

the class BenchmarkPageProcessor method setup.

@Setup
public void setup() {
    inputPage = createInputPage();
    Metadata metadata = createTestMetadataManager();
    compiledProcessor = new ExpressionCompiler(metadata, new PageFunctionCompiler(metadata, 0)).compilePageProcessor(Optional.of(FILTER), ImmutableList.of(PROJECT)).get();
}
Also used : Metadata(io.prestosql.metadata.Metadata) Setup(org.openjdk.jmh.annotations.Setup)

Example 2 with Metadata

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

the class InCodeGeneratorBenchmark method setup.

@Setup
public void setup() {
    Random random = new Random();
    RowExpression[] arguments = new RowExpression[1 + inListCount];
    switch(type) {
        case StandardTypes.BIGINT:
            prestoType = BIGINT;
            for (int i = 1; i <= inListCount; i++) {
                arguments[i] = constant((long) random.nextInt(), BIGINT);
            }
            break;
        case StandardTypes.DOUBLE:
            prestoType = DOUBLE;
            for (int i = 1; i <= inListCount; i++) {
                arguments[i] = constant(random.nextDouble(), DOUBLE);
            }
            break;
        case StandardTypes.VARCHAR:
            prestoType = VARCHAR;
            for (int i = 1; i <= inListCount; i++) {
                arguments[i] = constant(Slices.utf8Slice(Long.toString(random.nextLong())), VARCHAR);
            }
            break;
        default:
            throw new IllegalStateException();
    }
    arguments[0] = field(0, prestoType);
    RowExpression project = field(0, prestoType);
    PageBuilder pageBuilder = new PageBuilder(ImmutableList.of(prestoType));
    for (int i = 0; i < 10_000; i++) {
        pageBuilder.declarePosition();
        switch(type) {
            case StandardTypes.BIGINT:
                BIGINT.writeLong(pageBuilder.getBlockBuilder(0), random.nextInt());
                break;
            case StandardTypes.DOUBLE:
                DOUBLE.writeDouble(pageBuilder.getBlockBuilder(0), random.nextDouble());
                break;
            case StandardTypes.VARCHAR:
                VARCHAR.writeSlice(pageBuilder.getBlockBuilder(0), Slices.utf8Slice(Long.toString(random.nextLong())));
                break;
        }
    }
    inputPage = pageBuilder.build();
    RowExpression filter = new SpecialForm(IN, BOOLEAN, arguments);
    Metadata metadata = createTestMetadataManager();
    processor = new ExpressionCompiler(metadata, new PageFunctionCompiler(metadata, 0)).compilePageProcessor(Optional.of(filter), ImmutableList.of(project)).get();
}
Also used : Random(java.util.Random) Metadata(io.prestosql.metadata.Metadata) RowExpression(io.prestosql.spi.relation.RowExpression) PageBuilder(io.prestosql.spi.PageBuilder) SpecialForm(io.prestosql.spi.relation.SpecialForm) Setup(org.openjdk.jmh.annotations.Setup)

Example 3 with Metadata

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

the class ValuesMatcher method detailMatches.

@Override
public MatchResult detailMatches(PlanNode node, StatsProvider stats, Session session, Metadata metadata, SymbolAliases symbolAliases) {
    checkState(shapeMatches(node), "Plan testing framework error: shapeMatches returned false in detailMatches in %s", this.getClass().getName());
    ValuesNode valuesNode = (ValuesNode) node;
    if (!expectedRows.map(rows -> rows.equals(valuesNode.getRows().stream().map(rowExpressions -> rowExpressions.stream().map(rowExpression -> {
        if (isExpression(rowExpression)) {
            return castToExpression(rowExpression);
        }
        ConstantExpression expression = (ConstantExpression) rowExpression;
        if (expression.getType().getJavaType() == boolean.class) {
            return new BooleanLiteral(String.valueOf(expression.getValue()));
        }
        if (expression.getType().getJavaType() == long.class) {
            return new LongLiteral(String.valueOf(expression.getValue()));
        }
        if (expression.getType().getJavaType() == double.class) {
            return new DoubleLiteral(String.valueOf(expression.getValue()));
        }
        if (expression.getType().getJavaType() == Slice.class) {
            return new StringLiteral(String.valueOf(expression.getValue()));
        }
        return new GenericLiteral(expression.getType().toString(), String.valueOf(expression.getValue()));
    }).collect(toImmutableList())).collect(toImmutableList()))).orElse(true)) {
        return NO_MATCH;
    }
    return match(SymbolAliases.builder().putAll(Maps.transformValues(outputSymbolAliases, index -> toSymbolReference(valuesNode.getOutputSymbols().get(index)))).build());
}
Also used : Slice(io.airlift.slice.Slice) ConstantExpression(io.prestosql.spi.relation.ConstantExpression) OriginalExpressionUtils.isExpression(io.prestosql.sql.relational.OriginalExpressionUtils.isExpression) BooleanLiteral(io.prestosql.sql.tree.BooleanLiteral) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) Session(io.prestosql.Session) OriginalExpressionUtils.castToExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToExpression) NO_MATCH(io.prestosql.sql.planner.assertions.MatchResult.NO_MATCH) StatsProvider(io.prestosql.cost.StatsProvider) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) MatchResult.match(io.prestosql.sql.planner.assertions.MatchResult.match) PlanNode(io.prestosql.spi.plan.PlanNode) Maps(com.google.common.collect.Maps) Metadata(io.prestosql.metadata.Metadata) Preconditions.checkState(com.google.common.base.Preconditions.checkState) SymbolUtils.toSymbolReference(io.prestosql.sql.planner.SymbolUtils.toSymbolReference) ValuesNode(io.prestosql.spi.plan.ValuesNode) List(java.util.List) DoubleLiteral(io.prestosql.sql.tree.DoubleLiteral) GenericLiteral(io.prestosql.sql.tree.GenericLiteral) LongLiteral(io.prestosql.sql.tree.LongLiteral) StringLiteral(io.prestosql.sql.tree.StringLiteral) Optional(java.util.Optional) Expression(io.prestosql.sql.tree.Expression) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) ValuesNode(io.prestosql.spi.plan.ValuesNode) StringLiteral(io.prestosql.sql.tree.StringLiteral) LongLiteral(io.prestosql.sql.tree.LongLiteral) BooleanLiteral(io.prestosql.sql.tree.BooleanLiteral) Slice(io.airlift.slice.Slice) ConstantExpression(io.prestosql.spi.relation.ConstantExpression) DoubleLiteral(io.prestosql.sql.tree.DoubleLiteral) GenericLiteral(io.prestosql.sql.tree.GenericLiteral)

Example 4 with Metadata

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

the class JoinMatcher method detailMatches.

@Override
public MatchResult detailMatches(PlanNode node, StatsProvider stats, Session session, Metadata metadata, SymbolAliases symbolAliases) {
    checkState(shapeMatches(node), "Plan testing framework error: shapeMatches returned false in detailMatches in %s", this.getClass().getName());
    JoinNode joinNode = (JoinNode) node;
    if (joinNode.getCriteria().size() != equiCriteria.size()) {
        return NO_MATCH;
    }
    if (filter.isPresent()) {
        if (!joinNode.getFilter().isPresent()) {
            return NO_MATCH;
        }
        RowExpression expression = joinNode.getFilter().get();
        if (isExpression(expression)) {
            if (!new ExpressionVerifier(symbolAliases).process(castToExpression(expression), filter.get())) {
                return NO_MATCH;
            }
        } else {
            if (!new RowExpressionVerifier(symbolAliases, metadata, session, node.getOutputSymbols()).process(filter.get(), expression)) {
                return NO_MATCH;
            }
        }
    } else {
        if (joinNode.getFilter().isPresent()) {
            return NO_MATCH;
        }
    }
    if (distributionType.isPresent() && !distributionType.equals(joinNode.getDistributionType())) {
        return NO_MATCH;
    }
    if (spillable.isPresent() && !spillable.equals(joinNode.isSpillable())) {
        return NO_MATCH;
    }
    /*
         * Have to use order-independent comparison; there are no guarantees what order
         * the equi criteria will have after planning and optimizing.
         */
    Set<JoinNode.EquiJoinClause> actual = ImmutableSet.copyOf(joinNode.getCriteria());
    Set<JoinNode.EquiJoinClause> expected = equiCriteria.stream().map(maker -> maker.getExpectedValue(symbolAliases)).collect(toImmutableSet());
    if (!expected.equals(actual)) {
        return NO_MATCH;
    }
    if (dynamicFilter.isPresent() && !dynamicFilter.get().match(joinNode, symbolAliases).isMatch()) {
        return NO_MATCH;
    }
    return MatchResult.match();
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) StatsProvider(io.prestosql.cost.StatsProvider) Set(java.util.Set) PlanNode(io.prestosql.spi.plan.PlanNode) Metadata(io.prestosql.metadata.Metadata) Preconditions.checkState(com.google.common.base.Preconditions.checkState) OriginalExpressionUtils.isExpression(io.prestosql.sql.relational.OriginalExpressionUtils.isExpression) List(java.util.List) DistributionType(io.prestosql.spi.plan.JoinNode.DistributionType) Objects.requireNonNull(java.util.Objects.requireNonNull) Session(io.prestosql.Session) RowExpression(io.prestosql.spi.relation.RowExpression) Optional(java.util.Optional) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) OriginalExpressionUtils.castToExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToExpression) NO_MATCH(io.prestosql.sql.planner.assertions.MatchResult.NO_MATCH) Expression(io.prestosql.sql.tree.Expression) JoinNode(io.prestosql.spi.plan.JoinNode) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) JoinNode(io.prestosql.spi.plan.JoinNode) RowExpression(io.prestosql.spi.relation.RowExpression)

Example 5 with Metadata

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

the class DynamicFilterMatcher method match.

public MatchResult match(FilterNode filterNode, Metadata metadata, Session session, SymbolAliases symbolAliases) {
    checkState(this.filterNode == null, "filterNode must be null at this point");
    this.filterNode = filterNode;
    this.symbolAliases = symbolAliases;
    FunctionResolution functionResolution = new FunctionResolution(metadata.getFunctionAndTypeManager());
    LogicalRowExpressions logicalRowExpressions = new LogicalRowExpressions(new RowExpressionDeterminismEvaluator(metadata), functionResolution, metadata.getFunctionAndTypeManager());
    boolean staticFilterMatches = expectedStaticFilter.map(filter -> {
        RowExpressionVerifier verifier = new RowExpressionVerifier(symbolAliases, metadata, session, filterNode.getOutputSymbols());
        RowExpression staticFilter = logicalRowExpressions.combineConjuncts(extractDynamicFilters(filterNode.getPredicate()).getStaticConjuncts());
        return verifier.process(filter, staticFilter);
    }).orElse(true);
    return new MatchResult(match() && staticFilterMatches);
}
Also used : DynamicFilters.extractDynamicFilters(io.prestosql.sql.DynamicFilters.extractDynamicFilters) LogicalRowExpressions(io.prestosql.expressions.LogicalRowExpressions) HashMap(java.util.HashMap) FilterNode(io.prestosql.spi.plan.FilterNode) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) Session(io.prestosql.Session) JoinNode(io.prestosql.spi.plan.JoinNode) Symbol(io.prestosql.spi.plan.Symbol) RowExpressionDeterminismEvaluator(io.prestosql.sql.relational.RowExpressionDeterminismEvaluator) StatsProvider(io.prestosql.cost.StatsProvider) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) DynamicFilters(io.prestosql.sql.DynamicFilters) PlanNode(io.prestosql.spi.plan.PlanNode) VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) Metadata(io.prestosql.metadata.Metadata) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) FunctionResolution(io.prestosql.sql.relational.FunctionResolution) RowExpression(io.prestosql.spi.relation.RowExpression) Optional(java.util.Optional) Expression(io.prestosql.sql.tree.Expression) Joiner(com.google.common.base.Joiner) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) RowExpressionDeterminismEvaluator(io.prestosql.sql.relational.RowExpressionDeterminismEvaluator) LogicalRowExpressions(io.prestosql.expressions.LogicalRowExpressions) RowExpression(io.prestosql.spi.relation.RowExpression) FunctionResolution(io.prestosql.sql.relational.FunctionResolution)

Aggregations

Metadata (io.prestosql.metadata.Metadata)79 Session (io.prestosql.Session)39 List (java.util.List)39 Optional (java.util.Optional)37 Map (java.util.Map)28 Type (io.prestosql.spi.type.Type)27 PlanNodeId (io.prestosql.spi.plan.PlanNodeId)26 Symbol (io.prestosql.spi.plan.Symbol)26 RowExpression (io.prestosql.spi.relation.RowExpression)26 Objects.requireNonNull (java.util.Objects.requireNonNull)25 ImmutableList (com.google.common.collect.ImmutableList)24 PlanNode (io.prestosql.spi.plan.PlanNode)24 TableHandle (io.prestosql.spi.metadata.TableHandle)22 Set (java.util.Set)22 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)21 Page (io.prestosql.spi.Page)20 Expression (io.prestosql.sql.tree.Expression)20 Test (org.testng.annotations.Test)19 QualifiedObjectName (io.prestosql.spi.connector.QualifiedObjectName)18 ImmutableMap (com.google.common.collect.ImmutableMap)17