org.apache.calcite.prepare.Prepare Java Examples

The following examples show how to use org.apache.calcite.prepare.Prepare. 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: FlinkCalciteCatalogReaderTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetFlinkPreparingTableBase() {
	// Mock CatalogSchemaTable.
	TableSchema schema = TableSchema.builder().build();
	CatalogSchemaTable mockTable = new CatalogSchemaTable(
		ObjectIdentifier.of("a", "b", "c"),
		CatalogManager.TableLookupResult.permanent(ConnectorCatalogTable.source(
			new TestTableSource(true, schema),
			true), schema),
		FlinkStatistic.UNKNOWN(),
		null,
		true);

	rootSchemaPlus.add(tableMockName, mockTable);
	Prepare.PreparingTable preparingTable = catalogReader
		.getTable(Collections.singletonList(tableMockName));
	assertTrue(preparingTable instanceof FlinkPreparingTableBase);
}
 
Example #2
Source File: SqlValidatorUtil.java    From calcite with Apache License 2.0 6 votes vote down vote up
private static RelOptTable getRelOptTable(
    TableNamespace tableNamespace,
    Prepare.CatalogReader catalogReader,
    String datasetName,
    boolean[] usedDataset,
    List<RelDataTypeField> extendedFields) {
  final List<String> names = tableNamespace.getTable().getQualifiedName();
  RelOptTable table;
  if (datasetName != null
      && catalogReader instanceof RelOptSchemaWithSampling) {
    final RelOptSchemaWithSampling reader =
        (RelOptSchemaWithSampling) catalogReader;
    table = reader.getTableForMember(names, datasetName, usedDataset);
  } else {
    // Schema does not support substitution. Ignore the data set, if any.
    table = catalogReader.getTableForMember(names);
  }
  if (!extendedFields.isEmpty()) {
    table = table.extend(extendedFields);
  }
  return table;
}
 
Example #3
Source File: JdbcRules.java    From calcite with Apache License 2.0 6 votes vote down vote up
public JdbcTableModify(RelOptCluster cluster,
    RelTraitSet traitSet,
    RelOptTable table,
    Prepare.CatalogReader catalogReader,
    RelNode input,
    Operation operation,
    List<String> updateColumnList,
    List<RexNode> sourceExpressionList,
    boolean flattened) {
  super(cluster, traitSet, table, catalogReader, input, operation,
      updateColumnList, sourceExpressionList, flattened);
  assert input.getConvention() instanceof JdbcConvention;
  assert getConvention() instanceof JdbcConvention;
  final ModifiableTable modifiableTable =
      table.unwrap(ModifiableTable.class);
  if (modifiableTable == null) {
    throw new AssertionError(); // TODO: user error in validator
  }
  this.expression = table.getExpression(Queryable.class);
  if (expression == null) {
    throw new AssertionError(); // TODO: user error in validator
  }
}
 
Example #4
Source File: MaterializationTest.java    From calcite with Apache License 2.0 6 votes vote down vote up
@Test void testViewMaterialization() {
  try (TryThreadLocal.Memo ignored = Prepare.THREAD_TRIM.push(true)) {
    MaterializationService.setThreadLocal();
    String materialize = "select \"depts\".\"name\"\n"
        + "from \"depts\"\n"
        + "join \"emps\" on (\"emps\".\"deptno\" = \"depts\".\"deptno\")";
    String query = "select \"depts\".\"name\"\n"
        + "from \"depts\"\n"
        + "join \"emps\" on (\"emps\".\"deptno\" = \"depts\".\"deptno\")";

    CalciteAssert.that()
        .withMaterializations(HR_FKUK_MODEL, true, "matview", materialize)
        .query(query)
        .enableMaterializations(true)
        .explainMatches(
            "", CalciteAssert.checkResultContains(
            "EnumerableValues(tuples=[[{ 'noname' }]])")).returnsValue("noname");
  }
}
 
Example #5
Source File: MaterializationTest.java    From calcite with Apache License 2.0 6 votes vote down vote up
@Test void testTableModify() {
  final String m = "select \"deptno\", \"empid\", \"name\""
      + "from \"emps\" where \"deptno\" = 10";
  final String q = "upsert into \"dependents\""
      + "select \"empid\" + 1 as x, \"name\""
      + "from \"emps\" where \"deptno\" = 10";

  final List<List<List<String>>> substitutedNames = new ArrayList<>();
  try (TryThreadLocal.Memo ignored = Prepare.THREAD_TRIM.push(true)) {
    MaterializationService.setThreadLocal();
    CalciteAssert.that()
        .withMaterializations(HR_FKUK_MODEL,
            "m0", m)
        .query(q)
        .withHook(Hook.SUB, (Consumer<RelNode>) r ->
            substitutedNames.add(new TableNameVisitor().run(r)))
        .enableMaterializations(true)
        .explainContains("hr, m0");
  } catch (Exception e) {
    // Table "dependents" not modifiable.
  }
  assertThat(substitutedNames, is(list3(new String[][][]{{{"hr", "m0"}}})));
}
 
Example #6
Source File: MaterializationTest.java    From calcite with Apache License 2.0 6 votes vote down vote up
/** Test case for
 * <a href="https://issues.apache.org/jira/browse/CALCITE-761">[CALCITE-761]
 * Pre-populated materializations</a>. */
@Test void testPrePopulated() {
  String q = "select distinct \"deptno\" from \"emps\"";
  try (TryThreadLocal.Memo ignored = Prepare.THREAD_TRIM.push(true)) {
    MaterializationService.setThreadLocal();
    CalciteAssert.that()
        .withMaterializations(
            HR_FKUK_MODEL, builder -> {
              final Map<String, Object> map = builder.map();
              map.put("table", "locations");
              String sql = "select distinct `deptno` as `empid`, '' as `name`\n"
                  + "from `emps`";
              final String sql2 = sql.replace("`", "\"");
              map.put("sql", sql2);
              return ImmutableList.of(map);
            })
        .query(q)
        .enableMaterializations(true)
        .sameResultWithMaterializationsDisabled();
  }
}
 
Example #7
Source File: MaterializationTest.java    From calcite with Apache License 2.0 6 votes vote down vote up
@Test void testMultiMaterializationMultiUsage() {
  String q = "select *\n"
      + "from (select * from \"emps\" where \"empid\" < 300)\n"
      + "join (select \"deptno\", count(*) as c from \"emps\" group by \"deptno\") using (\"deptno\")";
  try (TryThreadLocal.Memo ignored = Prepare.THREAD_TRIM.push(true)) {
    MaterializationService.setThreadLocal();
    CalciteAssert.that()
        .withMaterializations(HR_FKUK_MODEL,
            "m0", "select \"deptno\", count(*) as c, sum(\"empid\") as s from \"emps\" group by \"deptno\"",
            "m1", "select * from \"emps\" where \"empid\" < 500")
        .query(q)
        .enableMaterializations(true)
        .explainContains("EnumerableTableScan(table=[[hr, m0]])")
        .explainContains("EnumerableTableScan(table=[[hr, m1]])")
        .sameResultWithMaterializationsDisabled();
  }
}
 
Example #8
Source File: MaterializationTest.java    From calcite with Apache License 2.0 6 votes vote down vote up
@Disabled("Creating mv for depts considering all its column throws exception")
@Test void testMultiMaterializationOnJoinQuery() {
  final String q = "select *\n"
      + "from \"emps\"\n"
      + "join \"depts\" using (\"deptno\") where \"empid\" < 300 "
      + "and \"depts\".\"deptno\" > 200";
  try (TryThreadLocal.Memo ignored = Prepare.THREAD_TRIM.push(true)) {
    MaterializationService.setThreadLocal();
    CalciteAssert.that()
        .withMaterializations(HR_FKUK_MODEL,
            "m0", "select * from \"emps\" where \"empid\" < 500",
            "m1", "select * from \"depts\" where \"deptno\" > 100")
        .query(q)
        .enableMaterializations(true)
        .explainContains("EnumerableTableScan(table=[[hr, m0]])")
        .explainContains("EnumerableTableScan(table=[[hr, m1]])")
        .sameResultWithMaterializationsDisabled();
  }
}
 
Example #9
Source File: FlinkCalciteCatalogReader.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public Prepare.PreparingTable getTable(List<String> names) {
	Prepare.PreparingTable originRelOptTable = super.getTable(names);
	if (originRelOptTable == null) {
		return null;
	} else {
		// Wrap as FlinkPreparingTableBase to use in query optimization.
		CatalogSchemaTable table = originRelOptTable.unwrap(CatalogSchemaTable.class);
		if (table != null) {
			return toPreparingTable(originRelOptTable.getRelOptSchema(),
				originRelOptTable.getQualifiedName(),
				originRelOptTable.getRowType(),
				table);
		} else {
			return originRelOptTable;
		}
	}
}
 
Example #10
Source File: SqlToRelTestBase.java    From calcite with Apache License 2.0 6 votes vote down vote up
protected SqlToRelConverter createSqlToRelConverter(
    final SqlValidator validator,
    final Prepare.CatalogReader catalogReader,
    final RelDataTypeFactory typeFactory,
    final SqlToRelConverter.Config config) {
  final RexBuilder rexBuilder = new RexBuilder(typeFactory);
  RelOptCluster cluster =
      RelOptCluster.create(getPlanner(), rexBuilder);
  if (clusterFactory != null) {
    cluster = clusterFactory.apply(cluster);
  }
  RelOptTable.ViewExpander viewExpander =
      new MockViewExpander(validator, catalogReader, cluster, config);
  return new SqlToRelConverter(viewExpander, validator, catalogReader, cluster,
      StandardConvertletTable.INSTANCE, config);
}
 
Example #11
Source File: MockCatalogReader.java    From calcite with Apache License 2.0 6 votes vote down vote up
private static List<RelCollation> deduceMonotonicity(
    Prepare.PreparingTable table) {
  final List<RelCollation> collationList = new ArrayList<>();

  // Deduce which fields the table is sorted on.
  int i = -1;
  for (RelDataTypeField field : table.getRowType().getFieldList()) {
    ++i;
    final SqlMonotonicity monotonicity =
        table.getMonotonicity(field.getName());
    if (monotonicity != SqlMonotonicity.NOT_MONOTONIC) {
      final RelFieldCollation.Direction direction =
          monotonicity.isDecreasing()
              ? RelFieldCollation.Direction.DESCENDING
              : RelFieldCollation.Direction.ASCENDING;
      collationList.add(
          RelCollations.of(
              new RelFieldCollation(i, direction)));
    }
  }
  return collationList;
}
 
Example #12
Source File: SqlValidatorImpl.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
public void validateUpdate(SqlUpdate call) {
	final SqlValidatorNamespace targetNamespace = getNamespace(call);
	validateNamespace(targetNamespace, unknownType);
	final RelOptTable relOptTable = SqlValidatorUtil.getRelOptTable(
		targetNamespace, catalogReader.unwrap(Prepare.CatalogReader.class), null, null);
	final SqlValidatorTable table = relOptTable == null
		? targetNamespace.getTable()
		: relOptTable.unwrap(SqlValidatorTable.class);

	final RelDataType targetRowType =
		createTargetRowType(
			table,
			call.getTargetColumnList(),
			true);

	final SqlSelect select = call.getSourceSelect();
	validateSelect(select, targetRowType);

	final RelDataType sourceRowType = getNamespace(call).getRowType();
	checkTypeAssignment(sourceRowType, targetRowType, call);

	checkConstraint(table, call, targetRowType);

	validateAccess(call.getTargetTable(), table, SqlAccessEnum.UPDATE);
}
 
Example #13
Source File: FlinkCalciteCatalogReader.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public Prepare.PreparingTable getTable(List<String> names) {
	Prepare.PreparingTable originRelOptTable = super.getTable(names);
	if (originRelOptTable == null) {
		return null;
	} else {
		// Wrap FlinkTable as FlinkRelOptTable to use in query optimization.
		FlinkTable table = originRelOptTable.unwrap(FlinkTable.class);
		if (table != null) {
			return FlinkRelOptTable.create(
				originRelOptTable.getRelOptSchema(),
				originRelOptTable.getRowType(),
				originRelOptTable.getQualifiedName(),
				table);
		} else {
			return originRelOptTable;
		}
	}
}
 
Example #14
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 #15
Source File: SqlValidatorImpl.java    From flink with Apache License 2.0 6 votes vote down vote up
public void validateUpdate(SqlUpdate call) {
	final SqlValidatorNamespace targetNamespace = getNamespace(call);
	validateNamespace(targetNamespace, unknownType);
	final RelOptTable relOptTable = SqlValidatorUtil.getRelOptTable(
		targetNamespace, catalogReader.unwrap(Prepare.CatalogReader.class), null, null);
	final SqlValidatorTable table = relOptTable == null
		? targetNamespace.getTable()
		: relOptTable.unwrap(SqlValidatorTable.class);

	final RelDataType targetRowType =
		createTargetRowType(
			table,
			call.getTargetColumnList(),
			true);

	final SqlSelect select = call.getSourceSelect();
	validateSelect(select, targetRowType);

	final RelDataType sourceRowType = getNamespace(call).getRowType();
	checkTypeAssignment(sourceRowType, targetRowType, call);

	checkConstraint(table, call, targetRowType);

	validateAccess(call.getTargetTable(), table, SqlAccessEnum.UPDATE);
}
 
Example #16
Source File: MaterializationTest.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Test void testViewSchemaPath() {
  try (TryThreadLocal.Memo ignored = Prepare.THREAD_TRIM.push(true)) {
    MaterializationService.setThreadLocal();
    final String m = "select empno, deptno from emp";
    final String q = "select deptno from scott.emp";
    final List<String> path = ImmutableList.of("SCOTT");
    final JsonBuilder builder = new JsonBuilder();
    final String model = "{\n"
        + "  version: '1.0',\n"
        + "  defaultSchema: 'hr',\n"
        + "  schemas: [\n"
        + JdbcTest.SCOTT_SCHEMA
        + "  ,\n"
        + "    {\n"
        + "      materializations: [\n"
        + "        {\n"
        + "          table: 'm0',\n"
        + "          view: 'm0v',\n"
        + "          sql: " + builder.toJsonString(m) + ",\n"
        + "          viewSchemaPath: " + builder.toJsonString(path)
        + "        }\n"
        + "      ],\n"
        + "      type: 'custom',\n"
        + "      name: 'hr',\n"
        + "      factory: 'org.apache.calcite.adapter.java.ReflectiveSchema$Factory',\n"
        + "      operand: {\n"
        + "        class: 'org.apache.calcite.test.JdbcTest$HrSchema'\n"
        + "      }\n"
        + "    }\n"
        + "  ]\n"
        + "}\n";
    CalciteAssert.that()
        .withModel(model)
        .query(q)
        .enableMaterializations(true)
        .explainMatches("", CONTAINS_M0)
        .sameResultWithMaterializationsDisabled();
  }
}
 
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: 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 #19
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 #20
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 #21
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 #22
Source File: SqlToRelTestBase.java    From calcite with Apache License 2.0 5 votes vote down vote up
MockViewExpander(
    SqlValidator validator,
    Prepare.CatalogReader catalogReader,
    RelOptCluster cluster,
    SqlToRelConverter.Config config) {
  this.validator = validator;
  this.catalogReader = catalogReader;
  this.cluster = cluster;
  this.config = config;
}
 
Example #23
Source File: CoreQuidemTest.java    From calcite with Apache License 2.0 5 votes vote down vote up
/** Runs the dummy script "sql/dummy.iq", which is checked in empty but
 * which you may use as scratch space during development. */

// Do not disable this test; just remember not to commit changes to dummy.iq
public void testSqlDummy(String path) throws Exception {
  try (TryThreadLocal.Memo ignored = Prepare.THREAD_EXPAND.push(true)) {
    checkRun(path);
  }
}
 
Example #24
Source File: MaterializationTest.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Test void testMaterializationSubstitution() {
  String q = "select *\n"
      + "from (select * from \"emps\" where \"empid\" < 300)\n"
      + "join (select * from \"emps\" where \"empid\" < 200) using (\"empid\")";

  final String[][][] expectedNames = {
      {{"hr", "emps"}, {"hr", "m0"}},
      {{"hr", "emps"}, {"hr", "m1"}},
      {{"hr", "m0"}, {"hr", "emps"}},
      {{"hr", "m0"}, {"hr", "m0"}},
      {{"hr", "m0"}, {"hr", "m1"}},
      {{"hr", "m1"}, {"hr", "emps"}},
      {{"hr", "m1"}, {"hr", "m0"}},
      {{"hr", "m1"}, {"hr", "m1"}}};

  try (TryThreadLocal.Memo ignored = Prepare.THREAD_TRIM.push(true)) {
    MaterializationService.setThreadLocal();
    final List<List<List<String>>> substitutedNames = new ArrayList<>();
    CalciteAssert.that()
        .withMaterializations(HR_FKUK_MODEL,
            "m0", "select * from \"emps\" where \"empid\" < 300",
            "m1", "select * from \"emps\" where \"empid\" < 600")
        .query(q)
        .withHook(Hook.SUB, (Consumer<RelNode>) r ->
            substitutedNames.add(new TableNameVisitor().run(r)))
        .enableMaterializations(true)
        .sameResultWithMaterializationsDisabled();
    substitutedNames.sort(CASE_INSENSITIVE_LIST_LIST_COMPARATOR);
    assertThat(substitutedNames, is(list3(expectedNames)));
  }
}
 
Example #25
Source File: MaterializationTest.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Test void testMaterializationSubstitution2() {
  String q = "select *\n"
      + "from (select * from \"emps\" where \"empid\" < 300)\n"
      + "join (select * from \"emps\" where \"empid\" < 200) using (\"empid\")";

  final String[][][] expectedNames = {
      {{"hr", "emps"}, {"hr", "m0"}},
      {{"hr", "emps"}, {"hr", "m1"}},
      {{"hr", "emps"}, {"hr", "m2"}},
      {{"hr", "m0"}, {"hr", "emps"}},
      {{"hr", "m0"}, {"hr", "m0"}},
      {{"hr", "m0"}, {"hr", "m1"}},
      {{"hr", "m0"}, {"hr", "m2"}},
      {{"hr", "m1"}, {"hr", "emps"}},
      {{"hr", "m1"}, {"hr", "m0"}},
      {{"hr", "m1"}, {"hr", "m1"}},
      {{"hr", "m1"}, {"hr", "m2"}},
      {{"hr", "m2"}, {"hr", "emps"}},
      {{"hr", "m2"}, {"hr", "m0"}},
      {{"hr", "m2"}, {"hr", "m1"}},
      {{"hr", "m2"}, {"hr", "m2"}}};

  try (TryThreadLocal.Memo ignored = Prepare.THREAD_TRIM.push(true)) {
    MaterializationService.setThreadLocal();
    final List<List<List<String>>> substitutedNames = new ArrayList<>();
    CalciteAssert.that()
        .withMaterializations(HR_FKUK_MODEL,
            "m0", "select * from \"emps\" where \"empid\" < 300",
            "m1", "select * from \"emps\" where \"empid\" < 600",
            "m2", "select * from \"m1\"")
        .query(q)
        .withHook(Hook.SUB, (Consumer<RelNode>) r ->
            substitutedNames.add(new TableNameVisitor().run(r)))
        .enableMaterializations(true)
        .sameResultWithMaterializationsDisabled();
    substitutedNames.sort(CASE_INSENSITIVE_LIST_LIST_COMPARATOR);
    assertThat(substitutedNames, is(list3(expectedNames)));
  }
}
 
Example #26
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 #27
Source File: CoreQuidemTest.java    From calcite with Apache License 2.0 5 votes vote down vote up
/** Override settings for "sql/misc.iq". */
public void testSqlMisc(String path) throws Exception {
  switch (CalciteAssert.DB) {
  case ORACLE:
    // There are formatting differences (e.g. "4.000" vs "4") when using
    // Oracle as the JDBC data source.
    return;
  }
  try (TryThreadLocal.Memo ignored = Prepare.THREAD_EXPAND.push(true)) {
    checkRun(path);
  }
}
 
Example #28
Source File: SqlToRelTestBase.java    From calcite with Apache License 2.0 5 votes vote down vote up
public Prepare.CatalogReader createCatalogReader(
    RelDataTypeFactory typeFactory) {
  MockCatalogReader catalogReader;
  if (this.catalogReaderFactory != null) {
    catalogReader = catalogReaderFactory.create(typeFactory, true);
  } else {
    catalogReader = new MockCatalogReaderSimple(typeFactory, true);
  }
  return catalogReader.init();
}
 
Example #29
Source File: EnumerableTableModify.java    From calcite with Apache License 2.0 5 votes vote down vote up
public EnumerableTableModify(RelOptCluster cluster, RelTraitSet traits,
    RelOptTable table, Prepare.CatalogReader catalogReader, RelNode child,
    Operation operation, List<String> updateColumnList,
    List<RexNode> sourceExpressionList, boolean flattened) {
  super(cluster, traits, table, catalogReader, child, operation,
      updateColumnList, sourceExpressionList, flattened);
  assert child.getConvention() instanceof EnumerableConvention;
  assert getConvention() instanceof EnumerableConvention;
  final ModifiableTable modifiableTable =
      table.unwrap(ModifiableTable.class);
  if (modifiableTable == null) {
    throw new AssertionError(); // TODO: user error in validator
  }
}
 
Example #30
Source File: EnumerableTableModifyExtension.java    From kareldb with Apache License 2.0 5 votes vote down vote up
public EnumerableTableModifyExtension(RelOptCluster cluster, RelTraitSet traits,
                                      RelOptTable table, Prepare.CatalogReader catalogReader, RelNode child,
                                      Operation operation, List<String> updateColumnList,
                                      List<RexNode> sourceExpressionList, boolean flattened) {
    super(cluster, traits, table, catalogReader, child, operation,
        updateColumnList, sourceExpressionList, flattened);
}