Search in sources :

Example 41 with RelNode

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode in project hive by apache.

the class HiveSubQRemoveRelBuilder method values.

/**
 * Creates a {@link Values} with a specified row type.
 *
 * <p>This method can handle cases that {@link #values(String[], Object...)}
 * cannot, such as all values of a column being null, or there being zero
 * rows.
 *
 * @param tupleList Tuple list
 * @param rowType Row type
 */
public HiveSubQRemoveRelBuilder values(Iterable<? extends List<RexLiteral>> tupleList, RelDataType rowType) {
    RelNode values = valuesFactory.createValues(cluster, rowType, copy(tupleList));
    push(values);
    return this;
}
Also used : RelNode(org.apache.calcite.rel.RelNode)

Example 42 with RelNode

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode in project hive by apache.

the class HiveSubQRemoveRelBuilder method convert.

/**
 * Creates a projection that converts the current relational expression's
 * output to a desired row type.
 *
 * @param castRowType row type after cast
 * @param rename      if true, use field names from castRowType; if false,
 *                    preserve field names from rel
 */
public HiveSubQRemoveRelBuilder convert(RelDataType castRowType, boolean rename) {
    final RelNode r = build();
    final RelNode r2 = RelOptUtil.createCastRel(r, castRowType, rename, projectFactory);
    push(r2);
    return this;
}
Also used : RelNode(org.apache.calcite.rel.RelNode)

Example 43 with RelNode

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode in project drill by apache.

the class SqlConverter method toRel.

public RelRoot toRel(final SqlNode validatedNode) {
    initCluster(initPlanner());
    DrillViewExpander viewExpander = new DrillViewExpander(this);
    final SqlToRelConverter sqlToRelConverter = new SqlToRelConverter(viewExpander, validator, catalog, cluster, DrillConvertletTable.INSTANCE, sqlToRelConverterConfig);
    boolean topLevelQuery = !isInnerQuery || isExpandedView;
    RelRoot rel = sqlToRelConverter.convertQuery(validatedNode, false, topLevelQuery);
    // add another project to remove them.
    if (topLevelQuery && rel.rel.getRowType().getFieldCount() - rel.fields.size() > 0) {
        RexBuilder builder = rel.rel.getCluster().getRexBuilder();
        RelNode relNode = rel.rel;
        List<RexNode> expressions = rel.fields.stream().map(f -> builder.makeInputRef(relNode, f.left)).collect(Collectors.toList());
        RelNode project = LogicalProject.create(rel.rel, expressions, rel.validatedRowType);
        rel = RelRoot.of(project, rel.validatedRowType, rel.kind);
    }
    return rel.withRel(sqlToRelConverter.flattenTypes(rel.rel, true));
}
Also used : Arrays(java.util.Arrays) UserException(org.apache.drill.common.exceptions.UserException) DrillSqlParseException(org.apache.drill.exec.planner.sql.parser.impl.DrillSqlParseException) LoggerFactory(org.slf4j.LoggerFactory) RelRoot(org.apache.calcite.rel.RelRoot) DrillParserConfig(org.apache.drill.exec.planner.sql.DrillParserConfig) DrillRelDataTypeSystem(org.apache.drill.exec.planner.types.DrillRelDataTypeSystem) FunctionImplementationRegistry(org.apache.drill.exec.expr.fn.FunctionImplementationRegistry) Utilities(org.apache.drill.exec.util.Utilities) SqlToRelConverter(org.apache.calcite.sql2rel.SqlToRelConverter) SqlNode(org.apache.calcite.sql.SqlNode) RexNode(org.apache.calcite.rex.RexNode) DynamicSchema(org.apache.calcite.jdbc.DynamicSchema) ConventionTraitDef(org.apache.calcite.plan.ConventionTraitDef) RelOptCluster(org.apache.calcite.plan.RelOptCluster) JavaTypeFactory(org.apache.calcite.adapter.java.JavaTypeFactory) RelDataType(org.apache.calcite.rel.type.RelDataType) QueryContext(org.apache.drill.exec.ops.QueryContext) SchemaUtilites(org.apache.drill.exec.planner.sql.SchemaUtilites) RelOptCostFactory(org.apache.calcite.plan.RelOptCostFactory) SchemaPlus(org.apache.calcite.schema.SchemaPlus) Logger(org.slf4j.Logger) RelCollationTraitDef(org.apache.calcite.rel.RelCollationTraitDef) LogicalProject(org.apache.calcite.rel.logical.LogicalProject) RexBuilder(org.apache.calcite.rex.RexBuilder) DrillDistributionTraitDef(org.apache.drill.exec.planner.physical.DrillDistributionTraitDef) SqlOperatorTable(org.apache.calcite.sql.SqlOperatorTable) DrillConstExecutor(org.apache.drill.exec.planner.logical.DrillConstExecutor) JavaTypeFactoryImpl(org.apache.calcite.jdbc.JavaTypeFactoryImpl) RelNode(org.apache.calcite.rel.RelNode) Collectors(java.util.stream.Collectors) ChainedSqlOperatorTable(org.apache.calcite.sql.util.ChainedSqlOperatorTable) List(java.util.List) DrillConfig(org.apache.drill.common.config.DrillConfig) PlannerSettings(org.apache.drill.exec.planner.physical.PlannerSettings) DrillConvertletTable(org.apache.drill.exec.planner.sql.DrillConvertletTable) SqlParser(org.apache.calcite.sql.parser.SqlParser) DrillCostBase(org.apache.drill.exec.planner.cost.DrillCostBase) VolcanoPlanner(org.apache.calcite.plan.volcano.VolcanoPlanner) ExecConstants(org.apache.drill.exec.ExecConstants) DrillRelFactories(org.apache.drill.exec.planner.logical.DrillRelFactories) SqlParseException(org.apache.calcite.sql.parser.SqlParseException) RelOptPlanner(org.apache.calcite.plan.RelOptPlanner) Hook(org.apache.calcite.runtime.Hook) UserSession(org.apache.drill.exec.rpc.user.UserSession) JaninoRelMetadataProvider(org.apache.calcite.rel.metadata.JaninoRelMetadataProvider) SqlToRelConverter(org.apache.calcite.sql2rel.SqlToRelConverter) RelNode(org.apache.calcite.rel.RelNode) RexBuilder(org.apache.calcite.rex.RexBuilder) RelRoot(org.apache.calcite.rel.RelRoot) RexNode(org.apache.calcite.rex.RexNode)

Example 44 with RelNode

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode in project drill by apache.

the class ExcessiveExchangeIdentifier method visitPrel.

@Override
public Prel visitPrel(Prel prel, MajorFragmentStat s) throws RuntimeException {
    List<RelNode> children = Lists.newArrayList();
    s.add(prel);
    // consistent decision.
    for (Prel p : prel) {
        s.add(p);
    }
    s.setHashDistribution(prel);
    for (Prel p : prel) {
        children.add(p.accept(this, s));
    }
    if (children.equals(prel.getInputs())) {
        return prel;
    }
    return (Prel) prel.copy(prel.getTraitSet(), children);
}
Also used : RelNode(org.apache.calcite.rel.RelNode) LateralJoinPrel(org.apache.drill.exec.planner.physical.LateralJoinPrel) ExchangePrel(org.apache.drill.exec.planner.physical.ExchangePrel) ScanPrel(org.apache.drill.exec.planner.physical.ScanPrel) Prel(org.apache.drill.exec.planner.physical.Prel) SingleMergeExchangePrel(org.apache.drill.exec.planner.physical.SingleMergeExchangePrel) ProjectPrel(org.apache.drill.exec.planner.physical.ProjectPrel) ScreenPrel(org.apache.drill.exec.planner.physical.ScreenPrel) FilterPrel(org.apache.drill.exec.planner.physical.FilterPrel) UnnestPrel(org.apache.drill.exec.planner.physical.UnnestPrel) LimitPrel(org.apache.drill.exec.planner.physical.LimitPrel) HashToMergeExchangePrel(org.apache.drill.exec.planner.physical.HashToMergeExchangePrel)

Example 45 with RelNode

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode in project drill by apache.

the class ExcessiveExchangeIdentifier method visitLateral.

@Override
public Prel visitLateral(LateralJoinPrel prel, MajorFragmentStat s) throws RuntimeException {
    List<RelNode> children = Lists.newArrayList();
    s.add(prel);
    for (Prel p : prel) {
        s.add(p);
    }
    // Traverse the left side of the Lateral join first. Left side of the
    // Lateral shouldn't have any restrictions on Exchanges.
    children.add(((Prel) prel.getInput(0)).accept(this, s));
    // Save the outermost Lateral join so as to unset the flag later.
    if (topMostLateralJoin == null) {
        topMostLateralJoin = prel;
    }
    // Right side of the Lateral shouldn't have any Exchanges. Hence set the
    // flag so that visitExchange removes the exchanges.
    s.setRightSideOfLateral(true);
    children.add(((Prel) prel.getInput(1)).accept(this, s));
    if (topMostLateralJoin == prel) {
        topMostLateralJoin = null;
        s.setRightSideOfLateral(false);
    }
    if (children.equals(prel.getInputs())) {
        return prel;
    }
    return (Prel) prel.copy(prel.getTraitSet(), children);
}
Also used : RelNode(org.apache.calcite.rel.RelNode) LateralJoinPrel(org.apache.drill.exec.planner.physical.LateralJoinPrel) ExchangePrel(org.apache.drill.exec.planner.physical.ExchangePrel) ScanPrel(org.apache.drill.exec.planner.physical.ScanPrel) Prel(org.apache.drill.exec.planner.physical.Prel) SingleMergeExchangePrel(org.apache.drill.exec.planner.physical.SingleMergeExchangePrel) ProjectPrel(org.apache.drill.exec.planner.physical.ProjectPrel) ScreenPrel(org.apache.drill.exec.planner.physical.ScreenPrel) FilterPrel(org.apache.drill.exec.planner.physical.FilterPrel) UnnestPrel(org.apache.drill.exec.planner.physical.UnnestPrel) LimitPrel(org.apache.drill.exec.planner.physical.LimitPrel) HashToMergeExchangePrel(org.apache.drill.exec.planner.physical.HashToMergeExchangePrel)

Aggregations

RelNode (org.apache.calcite.rel.RelNode)1600 RexNode (org.apache.calcite.rex.RexNode)488 ArrayList (java.util.ArrayList)417 Test (org.junit.jupiter.api.Test)389 RelBuilder (org.apache.calcite.tools.RelBuilder)342 RelDataType (org.apache.calcite.rel.type.RelDataType)246 RexBuilder (org.apache.calcite.rex.RexBuilder)217 ImmutableBitSet (org.apache.calcite.util.ImmutableBitSet)215 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)213 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)166 RexInputRef (org.apache.calcite.rex.RexInputRef)164 Project (org.apache.calcite.rel.core.Project)162 RelMetadataQuery (org.apache.calcite.rel.metadata.RelMetadataQuery)156 TimestampString (org.apache.calcite.util.TimestampString)154 List (java.util.List)151 RelTraitSet (org.apache.calcite.plan.RelTraitSet)143 Pair (org.apache.calcite.util.Pair)131 ImmutableList (com.google.common.collect.ImmutableList)126 Nullable (org.checkerframework.checker.nullness.qual.Nullable)119 HashMap (java.util.HashMap)117