Search in sources :

Example 36 with Project

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Project in project flink by apache.

the class HiveParserDMLHelper method replaceDistForStaticParts.

private RelNode replaceDistForStaticParts(LogicalDistribution hiveDist, Table destTable, Map<String, String> staticPartSpec, Map<String, RelDataType> targetColToType) {
    Project project = (Project) hiveDist.getInput();
    RelNode expandedProject = replaceProjectForStaticPart(project, staticPartSpec, destTable, targetColToType);
    hiveDist.replaceInput(0, null);
    final int toShift = staticPartSpec.size();
    final int numDynmPart = destTable.getTTable().getPartitionKeys().size() - toShift;
    return LogicalDistribution.create(expandedProject, shiftRelCollation(hiveDist.getCollation(), project, toShift, numDynmPart), shiftDistKeys(hiveDist.getDistKeys(), project, toShift, numDynmPart));
}
Also used : Project(org.apache.calcite.rel.core.Project) LogicalProject(org.apache.calcite.rel.logical.LogicalProject) RelNode(org.apache.calcite.rel.RelNode)

Example 37 with Project

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Project in project flink by apache.

the class HiveParserDMLHelper method addTypeConversions.

static RelNode addTypeConversions(RexBuilder rexBuilder, RelNode queryRelNode, List<RelDataType> targetCalcTypes, List<TypeInfo> targetHiveTypes, SqlFunctionConverter funcConverter) throws SemanticException {
    if (queryRelNode instanceof Project) {
        return replaceProjectForTypeConversion(rexBuilder, (Project) queryRelNode, targetCalcTypes, targetHiveTypes, funcConverter);
    } else {
        // current node is not Project, we search for it in inputs
        RelNode newInput = addTypeConversions(rexBuilder, queryRelNode.getInput(0), targetCalcTypes, targetHiveTypes, funcConverter);
        queryRelNode.replaceInput(0, newInput);
        return queryRelNode;
    }
}
Also used : Project(org.apache.calcite.rel.core.Project) LogicalProject(org.apache.calcite.rel.logical.LogicalProject) RelNode(org.apache.calcite.rel.RelNode)

Example 38 with Project

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Project in project beam by apache.

the class ArrayScanToJoinConverter method convert.

/**
 * Returns a LogicJoin.
 */
@Override
public RelNode convert(ResolvedArrayScan zetaNode, List<RelNode> inputs) {
    List<RexNode> projects = new ArrayList<>();
    RelNode leftInput = inputs.get(0);
    ResolvedColumnRef columnRef = (ResolvedColumnRef) zetaNode.getArrayExpr();
    CorrelationId correlationId = getCluster().createCorrel();
    getCluster().getQuery().mapCorrel(correlationId.getName(), leftInput);
    String columnName = String.format("%s%s", zetaNode.getElementColumn().getTableName(), zetaNode.getElementColumn().getName());
    projects.add(getCluster().getRexBuilder().makeFieldAccess(getCluster().getRexBuilder().makeCorrel(leftInput.getRowType(), correlationId), getExpressionConverter().indexOfProjectionColumnRef(columnRef.getColumn().getId(), zetaNode.getInputScan().getColumnList())));
    RelNode projectNode = LogicalProject.create(createOneRow(getCluster()), ImmutableList.of(), projects, ImmutableList.of(columnName));
    // Create an UnCollect
    boolean ordinality = (zetaNode.getArrayOffsetColumn() != null);
    // If they aren't true we need the Project to reorder columns.
    assert zetaNode.getElementColumn().getId() == 1;
    assert !ordinality || zetaNode.getArrayOffsetColumn().getColumn().getId() == 2;
    ZetaSqlUnnest uncollectNode = ZetaSqlUnnest.create(projectNode.getTraitSet(), projectNode, ordinality);
    List<RexInputRef> rightProjects = new ArrayList<>();
    List<String> rightNames = new ArrayList<>();
    rightProjects.add(getCluster().getRexBuilder().makeInputRef(uncollectNode, 0));
    rightNames.add(columnName);
    if (ordinality) {
        rightProjects.add(getCluster().getRexBuilder().makeInputRef(uncollectNode, 1));
        rightNames.add(String.format(zetaNode.getArrayOffsetColumn().getColumn().getTableName(), zetaNode.getArrayOffsetColumn().getColumn().getName()));
    }
    RelNode rightInput = LogicalProject.create(uncollectNode, ImmutableList.of(), rightProjects, rightNames);
    // Join condition should be a RexNode converted from join_expr.
    RexNode condition = getExpressionConverter().convertRexNodeFromResolvedExpr(zetaNode.getJoinExpr());
    JoinRelType joinRelType = zetaNode.getIsOuter() ? JoinRelType.LEFT : JoinRelType.INNER;
    return LogicalJoin.create(leftInput, rightInput, ImmutableList.of(), condition, ImmutableSet.of(), joinRelType, false, ImmutableList.of());
}
Also used : ArrayList(java.util.ArrayList) ResolvedColumnRef(com.google.zetasql.resolvedast.ResolvedNodes.ResolvedColumnRef) JoinRelType(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.JoinRelType) RelNode(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode) ZetaSqlUnnest(org.apache.beam.sdk.extensions.sql.zetasql.unnest.ZetaSqlUnnest) RexInputRef(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexInputRef) CorrelationId(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.CorrelationId) RexNode(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexNode)

Example 39 with Project

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Project in project beam by apache.

the class ArrayScanLiteralToUncollectConverter method convert.

@Override
public RelNode convert(ResolvedArrayScan zetaNode, List<RelNode> inputs) {
    RexNode arrayLiteralExpression = getExpressionConverter().convertRexNodeFromResolvedExpr(zetaNode.getArrayExpr());
    String fieldName = String.format("%s%s", zetaNode.getElementColumn().getTableName(), zetaNode.getElementColumn().getName());
    RelNode projectNode = LogicalProject.create(createOneRow(getCluster()), ImmutableList.of(), Collections.singletonList(arrayLiteralExpression), ImmutableList.of(fieldName));
    boolean ordinality = (zetaNode.getArrayOffsetColumn() != null);
    // If they aren't true we need to add a Project to reorder columns.
    assert zetaNode.getElementColumn().getId() == 1;
    assert !ordinality || zetaNode.getArrayOffsetColumn().getColumn().getId() == 2;
    return ZetaSqlUnnest.create(projectNode.getTraitSet(), projectNode, ordinality);
}
Also used : RelNode(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode) RexNode(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexNode)

Example 40 with Project

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Project in project druid by druid-io.

the class DruidRelsTest method test_isScanOrMapping_mapping.

@Test
public void test_isScanOrMapping_mapping() {
    final Project project = mockMappingProject(ImmutableList.of(1, 0), 2);
    final DruidRel<?> rel = mockDruidRel(DruidQueryRel.class, PartialDruidQuery.Stage.SELECT_PROJECT, null, project, null);
    Assert.assertTrue(DruidRels.isScanOrMapping(rel, true));
    Assert.assertTrue(DruidRels.isScanOrMapping(rel, false));
    EasyMock.verify(rel, rel.getPartialDruidQuery(), project);
}
Also used : Project(org.apache.calcite.rel.core.Project) Test(org.junit.Test)

Aggregations

Project (org.apache.calcite.rel.core.Project)143 RexNode (org.apache.calcite.rex.RexNode)77 RelNode (org.apache.calcite.rel.RelNode)71 ArrayList (java.util.ArrayList)51 LogicalProject (org.apache.calcite.rel.logical.LogicalProject)35 RexBuilder (org.apache.calcite.rex.RexBuilder)28 RelDataType (org.apache.calcite.rel.type.RelDataType)26 Test (org.junit.Test)23 Aggregate (org.apache.calcite.rel.core.Aggregate)22 Filter (org.apache.calcite.rel.core.Filter)22 Join (org.apache.calcite.rel.core.Join)22 List (java.util.List)20 RexLiteral (org.apache.calcite.rex.RexLiteral)19 AggregateCall (org.apache.calcite.rel.core.AggregateCall)18 Sort (org.apache.calcite.rel.core.Sort)18 RelBuilder (org.apache.calcite.tools.RelBuilder)17 ImmutableBitSet (org.apache.calcite.util.ImmutableBitSet)16 HiveProject (org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveProject)16 Collectors (java.util.stream.Collectors)15 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)15