org.apache.calcite.rel.core.TableModify Java Examples

The following examples show how to use org.apache.calcite.rel.core.TableModify. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JdbcRules.java    From calcite with Apache License 2.0 6 votes vote down vote up
@Override public RelNode convert(RelNode rel) {
  final TableModify modify =
      (TableModify) rel;
  final ModifiableTable modifiableTable =
      modify.getTable().unwrap(ModifiableTable.class);
  if (modifiableTable == null) {
    return null;
  }
  final RelTraitSet traitSet =
      modify.getTraitSet().replace(out);
  return new JdbcTableModify(
      modify.getCluster(), traitSet,
      modify.getTable(),
      modify.getCatalogReader(),
      convert(modify.getInput(), traitSet),
      modify.getOperation(),
      modify.getUpdateColumnList(),
      modify.getSourceExpressionList(),
      modify.isFlattened());
}
 
Example #2
Source File: JdbcRelBuilder.java    From calcite-sql-rewriter with Apache License 2.0 6 votes vote down vote up
public JdbcRelBuilder insertCopying(
		LogicalTableModify original,
		Table table
) {
	List<String> name = JdbcTableUtils.getQualifiedName(original.getTable(), table);

	push(new LogicalTableModify(
			cluster,
			original.getTraitSet(),
			relOptSchema.getTableForMember(name),
			original.getCatalogReader(),
			peek(),
			TableModify.Operation.INSERT,
			null,
			null,
			original.isFlattened()
	));
	return this;
}
 
Example #3
Source File: SamzaSqlApplicationConfig.java    From samza with Apache License 2.0 6 votes vote down vote up
private static void populateSystemStreams(RelNode relNode, List<String> inputSystemStreams,
    List<String> outputSystemStreams) {
  if (relNode instanceof TableModify) {
    outputSystemStreams.add(getSystemStreamName(relNode));
  } else {
    if (relNode instanceof BiRel) {
      BiRel biRelNode = (BiRel) relNode;
      populateSystemStreams(biRelNode.getLeft(), inputSystemStreams, outputSystemStreams);
      populateSystemStreams(biRelNode.getRight(), inputSystemStreams, outputSystemStreams);
    } else {
      if (relNode.getTable() != null) {
        inputSystemStreams.add(getSystemStreamName(relNode));
      }
    }
  }
  List<RelNode> relNodes = relNode.getInputs();
  if (relNodes == null || relNodes.isEmpty()) {
    return;
  }
  relNodes.forEach(node -> populateSystemStreams(node, inputSystemStreams, outputSystemStreams));
}
 
Example #4
Source File: ApexRelNode.java    From attic-apex-malhar with Apache License 2.0 6 votes vote down vote up
@Override
public RelInfo visit(RelContext context, RelNode node, List<RelInfo> inputStreams)
{
  /**
   * Only INSERT is allowed as it representation destination for DAG processing. Other types like UPDATE, DELETE,
   * MERGE does not represent the same.
   */

  TableModify modify = (TableModify)node;
  Preconditions.checkArgument(modify.isInsert(), "Only INSERT allowed for table modify");

  ApexSQLTable table = modify.getTable().unwrap(ApexSQLTable.class);

  Endpoint endpoint = table.getEndpoint();
  return endpoint.populateOutputDAG(context.dag, context.typeFactory);
}
 
Example #5
Source File: RelWriterTest.java    From calcite with Apache License 2.0 6 votes vote down vote up
@Test void testTableModifyInsert() {
  final FrameworkConfig config = RelBuilderTest.config().build();
  final RelBuilder builder = RelBuilder.create(config);
  RelNode project = builder
      .scan("EMP")
      .project(builder.fields(), ImmutableList.of(), true)
      .build();
  LogicalTableModify modify = LogicalTableModify.create(
      project.getInput(0).getTable(),
      (Prepare.CatalogReader) project.getInput(0).getTable().getRelOptSchema(),
      project,
      TableModify.Operation.INSERT,
      null,
      null,
      false);
  String relJson = RelOptUtil.dumpPlan("", modify,
      SqlExplainFormat.JSON, SqlExplainLevel.EXPPLAN_ATTRIBUTES);
  String s = deserializeAndDumpToTextFormat(getSchema(modify), relJson);
  final String expected = ""
      + "LogicalTableModify(table=[[scott, EMP]], operation=[INSERT], flattened=[false])\n"
      + "  LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], "
      + "COMM=[$6], DEPTNO=[$7])\n"
      + "    LogicalTableScan(table=[[scott, EMP]])\n";
  assertThat(s, isLinux(expected));
}
 
Example #6
Source File: TableAccessMap.java    From Bats with Apache License 2.0 5 votes vote down vote up
public void visit(
    RelNode p,
    int ordinal,
    RelNode parent) {
  super.visit(p, ordinal, parent);
  RelOptTable table = p.getTable();
  if (table == null) {
    return;
  }
  Mode newAccess;

  // FIXME jvs 1-Feb-2006:  Don't rely on object type here;
  // eventually someone is going to write a rule which transforms
  // to something which doesn't inherit TableModify,
  // and this will break.  Need to make this explicit in
  // the RelNode interface.
  if (p instanceof TableModify) {
    newAccess = Mode.WRITE_ACCESS;
  } else {
    newAccess = Mode.READ_ACCESS;
  }
  List<String> key = getQualifiedName(table);
  Mode oldAccess = accessMap.get(key);
  if ((oldAccess != null) && (oldAccess != newAccess)) {
    newAccess = Mode.READWRITE_ACCESS;
  }
  accessMap.put(key, newAccess);
}
 
Example #7
Source File: JdbcTable.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Override public TableModify toModificationRel(RelOptCluster cluster,
    RelOptTable table, CatalogReader catalogReader, RelNode input,
    Operation operation, List<String> updateColumnList,
    List<RexNode> sourceExpressionList, boolean flattened) {
  jdbcSchema.convention.register(cluster.getPlanner());

  return new LogicalTableModify(cluster, cluster.traitSetOf(Convention.NONE),
      table, catalogReader, input, operation, updateColumnList,
      sourceExpressionList, flattened);
}
 
Example #8
Source File: ModifiableTable.java    From calcite with Apache License 2.0 5 votes vote down vote up
/** Creates a relational expression that modifies this table. */
TableModify toModificationRel(
    RelOptCluster cluster,
    RelOptTable table,
    Prepare.CatalogReader catalogReader,
    RelNode child,
    TableModify.Operation operation,
    List<String> updateColumnList,
    List<RexNode> sourceExpressionList,
    boolean flattened);
 
Example #9
Source File: ListTransientTable.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Override public TableModify toModificationRel(
    RelOptCluster cluster,
    RelOptTable table,
    Prepare.CatalogReader catalogReader,
    RelNode child,
    TableModify.Operation operation,
    List<String> updateColumnList,
    List<RexNode> sourceExpressionList,
    boolean flattened) {
  return LogicalTableModify.create(table, catalogReader, child, operation,
      updateColumnList, sourceExpressionList, flattened);
}
 
Example #10
Source File: TableAccessMap.java    From calcite with Apache License 2.0 5 votes vote down vote up
public void visit(
    RelNode p,
    int ordinal,
    RelNode parent) {
  super.visit(p, ordinal, parent);
  RelOptTable table = p.getTable();
  if (table == null) {
    return;
  }
  Mode newAccess;

  // FIXME jvs 1-Feb-2006:  Don't rely on object type here;
  // eventually someone is going to write a rule which transforms
  // to something which doesn't inherit TableModify,
  // and this will break.  Need to make this explicit in
  // the RelNode interface.
  if (p instanceof TableModify) {
    newAccess = Mode.WRITE_ACCESS;
  } else {
    newAccess = Mode.READ_ACCESS;
  }
  List<String> key = getQualifiedName(table);
  Mode oldAccess = accessMap.get(key);
  if ((oldAccess != null) && (oldAccess != newAccess)) {
    newAccess = Mode.READWRITE_ACCESS;
  }
  accessMap.put(key, newAccess);
}
 
Example #11
Source File: FrameworksTest.java    From calcite with Apache License 2.0 5 votes vote down vote up
public TableModify toModificationRel(RelOptCluster cluster,
    RelOptTable table, Prepare.CatalogReader catalogReader, RelNode child,
    TableModify.Operation operation, List<String> updateColumnList,
    List<RexNode> sourceExpressionList, boolean flattened) {
  return LogicalTableModify.create(table, catalogReader, child, operation,
      updateColumnList, sourceExpressionList, flattened);
}
 
Example #12
Source File: AbstractModifiableTable.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Override public TableModify toModificationRel(
    RelOptCluster cluster,
    RelOptTable table,
    Prepare.CatalogReader catalogReader,
    RelNode child,
    TableModify.Operation operation,
    List<String> updateColumnList,
    List<RexNode> sourceExpressionList,
    boolean flattened) {
  return LogicalTableModify.create(table, catalogReader, child, operation,
      updateColumnList, sourceExpressionList, flattened);
}
 
Example #13
Source File: RelMetadataTest.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Test void testNodeTypeCountTableModify() {
  final String sql = "insert into emp select * from emp";
  final Map<Class<? extends RelNode>, Integer> expected = new HashMap<>();
  expected.put(TableScan.class, 1);
  expected.put(TableModify.class, 1);
  expected.put(Project.class, 1);
  checkNodeTypeCount(sql, expected);
}
 
Example #14
Source File: RelToSqlConverter.java    From quark with Apache License 2.0 5 votes vote down vote up
public Result visitChild(int i, RelNode e) {
  if (e instanceof Union) {
    return visitUnion((Union) e);
  } else if (e instanceof Join) {
    return visitJoin((Join) e);
  } else if (e instanceof Filter) {
    return visitFilter((Filter) e);
  } else if (e instanceof Project) {
    return visitProject((Project) e);
  } else if (e instanceof Aggregate) {
    return visitAggregate((Aggregate) e);
  } else if (e instanceof TableScan) {
    return visitTableScan((TableScan) e);
  } else if (e instanceof Intersect) {
    return visitIntersect((Intersect) e);
  } else if (e instanceof Minus) {
    return visitMinus((Minus) e);
  } else if (e instanceof Calc) {
    return visitCalc((Calc) e);
  } else if (e instanceof Sort) {
    return visitSort((Sort) e);
  } else if (e instanceof TableModify) {
    return visitTableModify((TableModify) e);
  } else if (e instanceof Limit) {
    return visitLimit((Limit) e);
  } else {
    throw new AssertionError("Need to Implement for " + e.getClass().getName()); // TODO:
  }
}
 
Example #15
Source File: RelWriterTest.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Test void testTableModifyUpdate() {
  final FrameworkConfig config = RelBuilderTest.config().build();
  final RelBuilder builder = RelBuilder.create(config);
  RelNode filter = builder
      .scan("EMP")
      .filter(
          builder.call(
              SqlStdOperatorTable.EQUALS,
              builder.field("JOB"),
              builder.literal("c")))
      .build();
  LogicalTableModify modify = LogicalTableModify.create(
      filter.getInput(0).getTable(),
      (Prepare.CatalogReader) filter.getInput(0).getTable().getRelOptSchema(),
      filter,
      TableModify.Operation.UPDATE,
      ImmutableList.of("ENAME"),
      ImmutableList.of(builder.literal("a")),
      false);
  String relJson = RelOptUtil.dumpPlan("", modify,
      SqlExplainFormat.JSON, SqlExplainLevel.EXPPLAN_ATTRIBUTES);
  String s = deserializeAndDumpToTextFormat(getSchema(modify), relJson);
  final String expected = ""
      + "LogicalTableModify(table=[[scott, EMP]], operation=[UPDATE], updateColumnList=[[ENAME]],"
      + " sourceExpressionList=[['a']], flattened=[false])\n"
      + "  LogicalFilter(condition=[=($2, 'c')])\n"
      + "    LogicalTableScan(table=[[scott, EMP]])\n";
  assertThat(s, isLinux(expected));
}
 
Example #16
Source File: PostOrderRelNodeVisitor.java    From streamline with Apache License 2.0 5 votes vote down vote up
public final T traverse(RelNode n) throws Exception {
  List<T> inputStreams = new ArrayList<>();
  for (RelNode input : n.getInputs()) {
    inputStreams.add(traverse(input));
  }

  if (n instanceof Aggregate) {
    return visitAggregate((Aggregate) n, inputStreams);
  } else if (n instanceof Calc) {
    return visitCalc((Calc) n, inputStreams);
  } else if (n instanceof Collect) {
    return visitCollect((Collect) n, inputStreams);
  } else if (n instanceof Correlate) {
    return visitCorrelate((Correlate) n, inputStreams);
  } else if (n instanceof Delta) {
    return visitDelta((Delta) n, inputStreams);
  } else if (n instanceof Exchange) {
    return visitExchange((Exchange) n, inputStreams);
  } else if (n instanceof Project) {
    return visitProject((Project) n, inputStreams);
  } else if (n instanceof Filter) {
    return visitFilter((Filter) n, inputStreams);
  } else if (n instanceof Sample) {
    return visitSample((Sample) n, inputStreams);
  } else if (n instanceof Sort) {
    return visitSort((Sort) n, inputStreams);
  } else if (n instanceof TableModify) {
    return visitTableModify((TableModify) n, inputStreams);
  } else if (n instanceof TableScan) {
    return visitTableScan((TableScan) n, inputStreams);
  } else if (n instanceof Uncollect) {
    return visitUncollect((Uncollect) n, inputStreams);
  } else if (n instanceof Window) {
    return visitWindow((Window) n, inputStreams);
  } else if (n instanceof Join) {
    return visitJoin((Join) n, inputStreams);
  } else {
    return defaultValue(n, inputStreams);
  }
}
 
Example #17
Source File: RelWriterTest.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Test void testTableModifyDelete() {
  final FrameworkConfig config = RelBuilderTest.config().build();
  final RelBuilder builder = RelBuilder.create(config);
  RelNode filter = builder
      .scan("EMP")
      .filter(
          builder.call(
              SqlStdOperatorTable.EQUALS,
              builder.field("JOB"),
              builder.literal("c")))
      .build();
  LogicalTableModify modify = LogicalTableModify.create(
      filter.getInput(0).getTable(),
      (Prepare.CatalogReader) filter.getInput(0).getTable().getRelOptSchema(),
      filter,
      TableModify.Operation.DELETE,
      null,
      null,
      false);
  String relJson = RelOptUtil.dumpPlan("", modify,
      SqlExplainFormat.JSON, SqlExplainLevel.EXPPLAN_ATTRIBUTES);
  String s = deserializeAndDumpToTextFormat(getSchema(modify), relJson);
  final String expected = ""
      + "LogicalTableModify(table=[[scott, EMP]], operation=[DELETE], flattened=[false])\n"
      + "  LogicalFilter(condition=[=($2, 'c')])\n"
      + "    LogicalTableScan(table=[[scott, EMP]])\n";
  assertThat(s, isLinux(expected));
}
 
Example #18
Source File: ModifiableTable.java    From Bats with Apache License 2.0 5 votes vote down vote up
/** Creates a relational expression that modifies this table. */
TableModify toModificationRel(
    RelOptCluster cluster,
    RelOptTable table,
    CatalogReader catalogReader,
    RelNode child,
    TableModify.Operation operation,
    List<String> updateColumnList,
    List<RexNode> sourceExpressionList,
    boolean flattened);
 
Example #19
Source File: Table.java    From kareldb with Apache License 2.0 5 votes vote down vote up
@Override
public TableModify toModificationRel(
    RelOptCluster cluster,
    RelOptTable table,
    Prepare.CatalogReader catalogReader,
    RelNode child,
    TableModify.Operation operation,
    List<String> updateColumnList,
    List<RexNode> sourceExpressionList,
    boolean flattened) {
    return LogicalTableModify.create(table, catalogReader, child, operation,
        updateColumnList, sourceExpressionList, flattened);
}
 
Example #20
Source File: RelWriterTest.java    From calcite with Apache License 2.0 4 votes vote down vote up
@Test void testTableModifyMerge() {
  final FrameworkConfig config = RelBuilderTest.config().build();
  final RelBuilder builder = RelBuilder.create(config);
  RelNode deptScan = builder.scan("DEPT").build();
  RelNode empScan = builder.scan("EMP").build();
  builder.push(deptScan);
  builder.push(empScan);
  RelNode project = builder
      .join(JoinRelType.LEFT,
          builder.call(
              SqlStdOperatorTable.EQUALS,
              builder.field(2, 0, "DEPTNO"),
              builder.field(2, 1, "DEPTNO")))
      .project(
          builder.literal(0),
          builder.literal("x"),
          builder.literal("x"),
          builder.literal(0),
          builder.literal("20200501 10:00:00"),
          builder.literal(0),
          builder.literal(0),
          builder.literal(0),
          builder.literal("false"),
          builder.field(1, 0, 2),
          builder.field(1, 0, 3),
          builder.field(1, 0, 4),
          builder.field(1, 0, 5),
          builder.field(1, 0, 6),
          builder.field(1, 0, 7),
          builder.field(1, 0, 8),
          builder.field(1, 0, 9),
          builder.field(1, 0, 10),
          builder.literal("a"))
      .build();
  // for sql:
  // merge into emp using dept on emp.deptno = dept.deptno
  // when matched then update set job = 'a'
  // when not matched then insert values(0, 'x', 'x', 0, '20200501 10:00:00', 0, 0, 0, 0)
  LogicalTableModify modify = LogicalTableModify.create(
      empScan.getTable(),
      (Prepare.CatalogReader) empScan.getTable().getRelOptSchema(),
      project,
      TableModify.Operation.MERGE,
      ImmutableList.of("ENAME"),
      null,
      false);
  String relJson = RelOptUtil.dumpPlan("", modify,
      SqlExplainFormat.JSON, SqlExplainLevel.EXPPLAN_ATTRIBUTES);
  String s = deserializeAndDumpToTextFormat(getSchema(modify), relJson);
  final String expected = ""
      + "LogicalTableModify(table=[[scott, EMP]], operation=[MERGE], "
      + "updateColumnList=[[ENAME]], flattened=[false])\n"
      + "  LogicalProject($f0=[0], $f1=['x'], $f2=['x'], $f3=[0], $f4=['20200501 10:00:00'], "
      + "$f5=[0], $f6=[0], $f7=[0], $f8=['false'], LOC=[$2], EMPNO=[$3], ENAME=[$4], JOB=[$5], "
      + "MGR=[$6], HIREDATE=[$7], SAL=[$8], COMM=[$9], DEPTNO=[$10], $f18=['a'])\n"
      + "    LogicalJoin(condition=[=($0, $10)], joinType=[left])\n"
      + "      LogicalTableScan(table=[[scott, DEPT]])\n"
      + "      LogicalTableScan(table=[[scott, EMP]])\n";
  assertThat(s, isLinux(expected));
}
 
Example #21
Source File: JdbcRules.java    From calcite with Apache License 2.0 4 votes vote down vote up
/** Creates a JdbcTableModificationRule. */
private JdbcTableModificationRule(JdbcConvention out,
    RelBuilderFactory relBuilderFactory) {
  super(TableModify.class, (Predicate<RelNode>) r -> true,
      Convention.NONE, out, relBuilderFactory, "JdbcTableModificationRule");
}
 
Example #22
Source File: RelMdPredicates.java    From calcite with Apache License 2.0 4 votes vote down vote up
/**
 * Infers predicates for a TableModify.
 */
public RelOptPredicateList getPredicates(TableModify tableModify, RelMetadataQuery mq) {
  return mq.getPulledUpPredicates(tableModify.getInput());
}
 
Example #23
Source File: RelMdAllPredicates.java    From calcite with Apache License 2.0 4 votes vote down vote up
/**
 * Extract predicates for an TableModify.
 */
public RelOptPredicateList getAllPredicates(TableModify tableModify, RelMetadataQuery mq) {
  return mq.getAllPredicates(tableModify.getInput());
}
 
Example #24
Source File: RelMdRowCount.java    From calcite with Apache License 2.0 4 votes vote down vote up
public Double getRowCount(TableModify rel, RelMetadataQuery mq) {
  return mq.getRowCount(rel.getInput());
}
 
Example #25
Source File: RelMdColumnUniqueness.java    From calcite with Apache License 2.0 4 votes vote down vote up
public Boolean areColumnsUnique(TableModify rel, RelMetadataQuery mq,
    ImmutableBitSet columns, boolean ignoreNulls) {
  columns = decorateWithConstantColumnsFromPredicates(columns, rel, mq);
  return mq.areColumnsUnique(rel.getInput(), columns, ignoreNulls);
}
 
Example #26
Source File: RelMdMinRowCount.java    From calcite with Apache License 2.0 4 votes vote down vote up
public Double getMinRowCount(TableModify rel, RelMetadataQuery mq) {
  return mq.getMinRowCount(rel.getInput());
}
 
Example #27
Source File: RelMdExpressionLineage.java    From calcite with Apache License 2.0 4 votes vote down vote up
/**
 * Expression lineage from TableModify.
 */
public Set<RexNode> getExpressionLineage(TableModify rel, RelMetadataQuery mq,
    RexNode outputExpression) {
  return mq.getExpressionLineage(rel.getInput(), outputExpression);
}
 
Example #28
Source File: PrelTransformer.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
/**
 *  Given a relNode tree for SELECT statement, convert to Dremio Logical RelNode tree.
 * @param relNode
 * @return
 * @throws SqlUnsupportedException
 * @throws RelConversionException
 */
public static Rel convertToDrel(SqlHandlerConfig config, final RelNode relNode) throws SqlUnsupportedException, RelConversionException {

  try {
    final RelNode trimmed = trimFields(relNode, true, config.getContext().getPlannerSettings().isRelPlanningEnabled());
    final RelNode preLog = transform(config, PlannerType.HEP_AC, PlannerPhase.PRE_LOGICAL, trimmed, trimmed.getTraitSet(), true);

    final RelTraitSet logicalTraits = preLog.getTraitSet().plus(Rel.LOGICAL);
    final RelNode adjusted = transform(config, PlannerType.VOLCANO, PlannerPhase.LOGICAL, preLog, logicalTraits, true);

    final Catalog catalog = config.getContext().getCatalog();
    if (catalog instanceof CachingCatalog) {
      config.getObserver().tablesCollected(catalog.getAllRequestedTables());
    }

    final RelNode intermediateNode;
    if (config.getContext().getPlannerSettings().removeRowCountAdjustment()) {
      intermediateNode = adjusted.accept(new RelShuttleImpl() {
          @Override
          public RelNode visit(TableScan scan) {
            if (scan instanceof FilesystemScanDrel) {
              FilesystemScanDrel scanDrel = (FilesystemScanDrel) scan;
              return new FilesystemScanDrel(
                scanDrel.getCluster(),
                scanDrel.getTraitSet(),
                scanDrel.getTable(),
                scanDrel.getPluginId(),
                scanDrel.getTableMetadata(),
                scanDrel.getProjectedColumns(),
                1.0);
            }
            return super.visit(scan);
          }
        });
    } else {
      intermediateNode = adjusted;
    }

    RelNode postLogical;
    if (config.getContext().getPlannerSettings().isRelPlanningEnabled()) {
      final RelNode decorrelatedNode = DremioRelDecorrelator.decorrelateQuery(intermediateNode, DremioRelFactories.LOGICAL_BUILDER.create(intermediateNode.getCluster(), null), true, true);
      final RelNode jdbcPushDown = transform(config, PlannerType.HEP_AC, PlannerPhase.RELATIONAL_PLANNING, decorrelatedNode, decorrelatedNode.getTraitSet().plus(Rel.LOGICAL), true);
      postLogical = jdbcPushDown.accept(new ShortenJdbcColumnAliases()).accept(new ConvertJdbcLogicalToJdbcRel(DremioRelFactories.LOGICAL_BUILDER));
    } else {
      postLogical = intermediateNode;
    }

    // Do Join Planning.
    final RelNode preConvertedRelNode = transform(config, PlannerType.HEP_BOTTOM_UP, PlannerPhase.JOIN_PLANNING_MULTI_JOIN, postLogical, postLogical.getTraitSet(), true);
    final RelNode convertedRelNode = transform(config, PlannerType.HEP_BOTTOM_UP, PlannerPhase.JOIN_PLANNING_OPTIMIZATION, preConvertedRelNode, preConvertedRelNode.getTraitSet(), true);

    FlattenRelFinder flattenFinder = new FlattenRelFinder();
    final RelNode flattendPushed;
    if (flattenFinder.run(convertedRelNode)) {
      flattendPushed = transform(config, PlannerType.VOLCANO, PlannerPhase.FLATTEN_PUSHDOWN,
        convertedRelNode, convertedRelNode.getTraitSet(), true);
    } else {
      flattendPushed = convertedRelNode;
    }

    final Rel drel = (Rel) flattendPushed;

    if (drel instanceof TableModify) {
      throw new UnsupportedOperationException("TableModify " + drel);
    } else {
      final Optional<SubstitutionInfo> acceleration = findUsedMaterializations(config, drel);
      if (acceleration.isPresent()) {
        config.getObserver().planAccelerated(acceleration.get());
      }
      return drel;
    }
  } catch (RelOptPlanner.CannotPlanException ex) {
    logger.error(ex.getMessage(), ex);

    if(JoinUtils.checkCartesianJoin(relNode, Lists.<Integer>newArrayList(), Lists.<Integer>newArrayList(), Lists.<Boolean>newArrayList())) {
      throw new UnsupportedRelOperatorException("This query cannot be planned\u2014possibly due to use of an unsupported feature.");
    } else {
      throw ex;
    }
  }
}
 
Example #29
Source File: CalcitePlanner.java    From herddb with Apache License 2.0 4 votes vote down vote up
@Override
public TableModify toModificationRel(RelOptCluster cluster, RelOptTable table, Prepare.CatalogReader catalogReader, RelNode child, TableModify.Operation operation, List<String> updateColumnList, List<RexNode> sourceExpressionList, boolean flattened) {
    return LogicalTableModify.create(table, catalogReader, child, operation,
            updateColumnList, sourceExpressionList, flattened);
}
 
Example #30
Source File: PostOrderRelNodeVisitor.java    From streamline with Apache License 2.0 4 votes vote down vote up
public T visitTableModify(TableModify modify, List<T> inputStreams) throws Exception {
  return defaultValue(modify, inputStreams);
}