Java Code Examples for org.apache.calcite.prepare.Prepare#CatalogReader

The following examples show how to use org.apache.calcite.prepare.Prepare#CatalogReader . 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: 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 2
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 3
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 4
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 5
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 6
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 7
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 8
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 9
Source File: TableModify.java    From calcite with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a TableModify by parsing serialized output.
 */
protected TableModify(RelInput input) {
  this(input.getCluster(),
      input.getTraitSet(),
      input.getTable("table"),
      (Prepare.CatalogReader) input.getTable("table").getRelOptSchema(),
      input.getInput(),
      input.getEnum("operation", Operation.class),
      input.getStringList("updateColumnList"),
      input.getExpressionList("sourceExpressionList"),
      input.getBoolean("flattened", false));
}
 
Example 10
Source File: TableModify.java    From calcite with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a {@code TableModify}.
 *
 * <p>The UPDATE operation has format like this:
 * <blockquote>
 *   <pre>UPDATE table SET iden1 = exp1, ident2 = exp2  WHERE condition</pre>
 * </blockquote>
 *
 * @param cluster    Cluster this relational expression belongs to
 * @param traitSet   Traits of this relational expression
 * @param table      Target table to modify
 * @param catalogReader accessor to the table metadata.
 * @param input      Sub-query or filter condition
 * @param operation  Modify operation (INSERT, UPDATE, DELETE)
 * @param updateColumnList List of column identifiers to be updated
 *           (e.g. ident1, ident2); null if not UPDATE
 * @param sourceExpressionList List of value expressions to be set
 *           (e.g. exp1, exp2); null if not UPDATE
 * @param flattened Whether set flattens the input row type
 */
protected TableModify(
    RelOptCluster cluster,
    RelTraitSet traitSet,
    RelOptTable table,
    Prepare.CatalogReader catalogReader,
    RelNode input,
    Operation operation,
    List<String> updateColumnList,
    List<RexNode> sourceExpressionList,
    boolean flattened) {
  super(cluster, traitSet, input);
  this.table = table;
  this.catalogReader = catalogReader;
  this.operation = operation;
  this.updateColumnList = updateColumnList;
  this.sourceExpressionList = sourceExpressionList;
  if (operation == Operation.UPDATE) {
    Objects.requireNonNull(updateColumnList);
    Objects.requireNonNull(sourceExpressionList);
    Preconditions.checkArgument(sourceExpressionList.size()
        == updateColumnList.size());
  } else {
    if (operation == Operation.MERGE) {
      Objects.requireNonNull(updateColumnList);
    } else {
      Preconditions.checkArgument(updateColumnList == null);
    }
    Preconditions.checkArgument(sourceExpressionList == null);
  }
  if (table.getRelOptSchema() != null) {
    cluster.getPlanner().registerSchema(table.getRelOptSchema());
  }
  this.flattened = flattened;
}
 
Example 11
Source File: LogicalTableModify.java    From calcite with Apache License 2.0 5 votes vote down vote up
/** Creates a LogicalTableModify. */
public static LogicalTableModify create(RelOptTable table,
    Prepare.CatalogReader schema, RelNode input,
    Operation operation, List<String> updateColumnList,
    List<RexNode> sourceExpressionList, boolean flattened) {
  final RelOptCluster cluster = input.getCluster();
  final RelTraitSet traitSet = cluster.traitSetOf(Convention.NONE);
  return new LogicalTableModify(cluster, traitSet, table, schema, input,
      operation, updateColumnList, sourceExpressionList, flattened);
}
 
Example 12
Source File: LogicalTableModify.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Deprecated // to be removed before 2.0
public LogicalTableModify(RelOptCluster cluster, RelOptTable table,
    Prepare.CatalogReader schema, RelNode input, Operation operation,
    List<String> updateColumnList, boolean flattened) {
  this(cluster,
      cluster.traitSetOf(Convention.NONE),
      table,
      schema,
      input,
      operation,
      updateColumnList,
      null,
      flattened);
}
 
Example 13
Source File: LogicalTableModify.java    From calcite with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a LogicalTableModify.
 *
 * <p>Use {@link #create} unless you know what you're doing.
 */
public LogicalTableModify(RelOptCluster cluster, RelTraitSet traitSet,
    RelOptTable table, Prepare.CatalogReader schema, RelNode input,
    Operation operation, List<String> updateColumnList,
    List<RexNode> sourceExpressionList, boolean flattened) {
  super(cluster, traitSet, table, schema, input, operation, updateColumnList,
      sourceExpressionList, flattened);
}
 
Example 14
Source File: MutableTableModify.java    From calcite with Apache License 2.0 5 votes vote down vote up
private MutableTableModify(RelDataType rowType, MutableRel input,
    RelOptTable table, Prepare.CatalogReader catalogReader,
    Operation operation, List<String> updateColumnList,
    List<RexNode> sourceExpressionList, boolean flattened) {
  super(MutableRelType.TABLE_MODIFY, rowType, input);
  this.table = table;
  this.catalogReader = catalogReader;
  this.operation = operation;
  this.updateColumnList = updateColumnList;
  this.sourceExpressionList = sourceExpressionList;
  this.flattened = flattened;
}
 
Example 15
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 16
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);
}
 
Example 17
Source File: TableModify.java    From calcite with Apache License 2.0 4 votes vote down vote up
public Prepare.CatalogReader getCatalogReader() {
  return catalogReader;
}
 
Example 18
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 19
Source File: TestSQLAnalyzer.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
@Override
public Prepare.CatalogReader withSchemaPath(List<String> schemaPath) {
  ImmutableList<String> immutableSchemaPath = ImmutableList.copyOf(schemaPath);
  return new MockCatalogReader(typeFactory, caseSensitive,
      ImmutableList.<ImmutableList<String>> copyOf(Iterables.concat(this.schemaPaths, ImmutableList.of(immutableSchemaPath))));
}
 
Example 20
Source File: SqlToRelTestBase.java    From calcite with Apache License 2.0 2 votes vote down vote up
/**
 * Factory method for a
 * {@link org.apache.calcite.prepare.Prepare.CatalogReader}.
 */
Prepare.CatalogReader createCatalogReader(
    RelDataTypeFactory typeFactory);