Search in sources :

Example 1 with RowExpression

use of io.prestosql.spi.relation.RowExpression 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 2 with RowExpression

use of io.prestosql.spi.relation.RowExpression in project hetu-core by openlookeng.

the class PageProcessorBenchmark method rowExpression.

private RowExpression rowExpression(String value) {
    Expression expression = createExpression(value, METADATA, TypeProvider.copyOf(symbolTypes));
    Map<NodeRef<Expression>, Type> expressionTypes = TYPE_ANALYZER.getTypes(TEST_SESSION, TypeProvider.copyOf(symbolTypes), expression);
    return SqlToRowExpressionTranslator.translate(expression, SCALAR, expressionTypes, sourceLayout, METADATA.getFunctionAndTypeManager(), TEST_SESSION, true);
}
Also used : NodeRef(io.prestosql.sql.tree.NodeRef) Type(io.prestosql.spi.type.Type) FunctionAssertions.createExpression(io.prestosql.operator.scalar.FunctionAssertions.createExpression) RowExpression(io.prestosql.spi.relation.RowExpression) Expression(io.prestosql.sql.tree.Expression)

Example 3 with RowExpression

use of io.prestosql.spi.relation.RowExpression in project hetu-core by openlookeng.

the class MySqlRowExpressionConverter method visitCall.

@Override
public String visitCall(CallExpression call, JdbcConverterContext context) {
    // remote udf verify
    FunctionHandle functionHandle = call.getFunctionHandle();
    if (!isDefaultFunction(call)) {
        Optional<String> result = mySqlApplyRemoteFunctionPushDown.rewriteRemoteFunction(call, this, context);
        if (result.isPresent()) {
            return result.get();
        }
        throw new PrestoException(NOT_SUPPORTED, String.format("MySql connector does not support remote function: %s.%s", call.getDisplayName(), call.getFunctionHandle().getFunctionNamespace()));
    }
    if (standardFunctionResolution.isArrayConstructor(functionHandle)) {
        throw new PrestoException(NOT_SUPPORTED, "MySql connector does not support array constructor");
    }
    if (standardFunctionResolution.isSubscriptFunction(functionHandle)) {
        throw new PrestoException(NOT_SUPPORTED, "MySql connector does not support subscript expression");
    }
    if (standardFunctionResolution.isCastFunction(functionHandle)) {
        // deal with literal, when generic literal expression translate to rowExpression, it will be
        // translated to a 'CAST' rowExpression with a varchar type 'CONSTANT' rowExpression, in some
        // case, 'CAST' is superfluous
        RowExpression argument = call.getArguments().get(0);
        Type type = call.getType();
        if (argument instanceof ConstantExpression && argument.getType().equals(VARCHAR)) {
            String value = argument.accept(this, context);
            if (type instanceof VarcharType || type instanceof CharType || type instanceof VarbinaryType || type instanceof DecimalType || type instanceof RealType || type instanceof DoubleType) {
                return value;
            }
        }
        if (call.getType().getDisplayName().equals(LIKE_PATTERN_NAME)) {
            return call.getArguments().get(0).accept(this, context);
        }
        return getCastExpression(call.getArguments().get(0).accept(this, context), call.getType());
    }
    return super.visitCall(call, context);
}
Also used : VarcharType(io.prestosql.spi.type.VarcharType) ConstantExpression(io.prestosql.spi.relation.ConstantExpression) RowExpression(io.prestosql.spi.relation.RowExpression) PrestoException(io.prestosql.spi.PrestoException) RealType(io.prestosql.spi.type.RealType) CharType(io.prestosql.spi.type.CharType) DecimalType(io.prestosql.spi.type.DecimalType) DoubleType(io.prestosql.spi.type.DoubleType) Type(io.prestosql.spi.type.Type) RealType(io.prestosql.spi.type.RealType) VarbinaryType(io.prestosql.spi.type.VarbinaryType) VarcharType(io.prestosql.spi.type.VarcharType) VarbinaryType(io.prestosql.spi.type.VarbinaryType) DoubleType(io.prestosql.spi.type.DoubleType) DecimalType(io.prestosql.spi.type.DecimalType) CharType(io.prestosql.spi.type.CharType) FunctionHandle(io.prestosql.spi.function.FunctionHandle)

Example 4 with RowExpression

use of io.prestosql.spi.relation.RowExpression 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 RowExpression

use of io.prestosql.spi.relation.RowExpression 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

RowExpression (io.prestosql.spi.relation.RowExpression)146 Symbol (io.prestosql.spi.plan.Symbol)51 VariableReferenceExpression (io.prestosql.spi.relation.VariableReferenceExpression)43 ArrayList (java.util.ArrayList)42 Test (org.testng.annotations.Test)38 ImmutableList (com.google.common.collect.ImmutableList)37 List (java.util.List)34 ConstantExpression (io.prestosql.spi.relation.ConstantExpression)32 CallExpression (io.prestosql.spi.relation.CallExpression)31 Map (java.util.Map)31 Metadata (io.prestosql.metadata.Metadata)27 Expression (io.prestosql.sql.tree.Expression)27 Optional (java.util.Optional)24 Type (io.prestosql.spi.type.Type)23 ProjectNode (io.prestosql.spi.plan.ProjectNode)21 SpecialForm (io.prestosql.spi.relation.SpecialForm)21 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)20 ImmutableMap (com.google.common.collect.ImmutableMap)20 PlanNode (io.prestosql.spi.plan.PlanNode)20 FunctionHandle (io.prestosql.spi.function.FunctionHandle)19