Java Code Examples for org.apache.calcite.rel.logical.LogicalTableModify#create()
The following examples show how to use
org.apache.calcite.rel.logical.LogicalTableModify#create() .
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: RelWriterTest.java From calcite with Apache License 2.0 | 6 votes |
@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 2
Source File: Table.java From kareldb with Apache License 2.0 | 5 votes |
@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 3
Source File: AbstractModifiableTable.java From calcite with Apache License 2.0 | 5 votes |
@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 4
Source File: RelStructuredTypeFlattener.java From calcite with Apache License 2.0 | 5 votes |
public void rewriteRel(LogicalTableModify rel) { LogicalTableModify newRel = LogicalTableModify.create( rel.getTable(), rel.getCatalogReader(), getNewForOldRel(rel.getInput()), rel.getOperation(), rel.getUpdateColumnList(), rel.getSourceExpressionList(), true); setNewForOldRel(rel, newRel); }
Example 5
Source File: ListTransientTable.java From calcite with Apache License 2.0 | 5 votes |
@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 6
Source File: FrameworksTest.java From calcite with Apache License 2.0 | 5 votes |
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 7
Source File: RelWriterTest.java From calcite with Apache License 2.0 | 5 votes |
@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 8
Source File: RelWriterTest.java From calcite with Apache License 2.0 | 5 votes |
@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 9
Source File: RelStructuredTypeFlattener.java From Bats with Apache License 2.0 | 4 votes |
public void rewriteRel(LogicalTableModify rel) { LogicalTableModify newRel = LogicalTableModify.create(rel.getTable(), rel.getCatalogReader(), getNewForOldRel(rel.getInput()), rel.getOperation(), rel.getUpdateColumnList(), rel.getSourceExpressionList(), true); setNewForOldRel(rel, newRel); }
Example 10
Source File: CalcitePlanner.java From herddb with Apache License 2.0 | 4 votes |
@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 11
Source File: RelWriterTest.java From calcite with Apache License 2.0 | 4 votes |
@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)); }