org.apache.calcite.sql2rel.InitializerExpressionFactory Java Examples

The following examples show how to use org.apache.calcite.sql2rel.InitializerExpressionFactory. 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: RelOptTableImpl.java    From Bats with Apache License 2.0 6 votes vote down vote up
/** Helper for {@link #getColumnStrategies()}. */
public static List<ColumnStrategy> columnStrategies(final RelOptTable table) {
    final int fieldCount = table.getRowType().getFieldCount();
    final InitializerExpressionFactory ief = Util.first(table.unwrap(InitializerExpressionFactory.class),
            NullInitializerExpressionFactory.INSTANCE);
    return new AbstractList<ColumnStrategy>() {
        @Override
        public int size() {
            return fieldCount;
        }

        @Override
        public ColumnStrategy get(int index) {
            return ief.generationStrategy(table, index);
        }
    };
}
 
Example #2
Source File: RelOptTableImpl.java    From calcite with Apache License 2.0 6 votes vote down vote up
/** Helper for {@link #getColumnStrategies()}. */
public static List<ColumnStrategy> columnStrategies(final RelOptTable table) {
  final int fieldCount = table.getRowType().getFieldCount();
  final InitializerExpressionFactory ief =
      Util.first(table.unwrap(InitializerExpressionFactory.class),
          NullInitializerExpressionFactory.INSTANCE);
  return new AbstractList<ColumnStrategy>() {
    public int size() {
      return fieldCount;
    }

    public ColumnStrategy get(int index) {
      return ief.generationStrategy(table, index);
    }
  };
}
 
Example #3
Source File: Prepare.java    From calcite with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
public boolean columnHasDefaultValue(RelDataType rowType, int ordinal,
    InitializerContext initializerContext) {
  // This method is no longer used
  final Table table = this.unwrap(Table.class);
  if (table != null && table instanceof Wrapper) {
    final InitializerExpressionFactory initializerExpressionFactory =
        ((Wrapper) table).unwrap(InitializerExpressionFactory.class);
    if (initializerExpressionFactory != null) {
      return initializerExpressionFactory
          .newColumnDefaultValue(this, ordinal, initializerContext)
          .getType().getSqlTypeName() != SqlTypeName.NULL;
    }
  }
  if (ordinal >= rowType.getFieldList().size()) {
    return true;
  }
  return !rowType.getFieldList().get(ordinal).getType().isNullable();
}
 
Example #4
Source File: MockCatalogReader.java    From calcite with Apache License 2.0 6 votes vote down vote up
/**
 * Copy constructor.
 */
protected MockTable(MockCatalogReader catalogReader, boolean stream,
    boolean temporal, double rowCount,
    List<Map.Entry<String, RelDataType>> columnList, List<Integer> keyList,
    RelDataType rowType, List<RelCollation> collationList, List<String> names,
    Set<String> monotonicColumnSet, StructKind kind, ColumnResolver resolver,
    InitializerExpressionFactory initializerFactory) {
  this.catalogReader = catalogReader;
  this.stream = stream;
  this.temporal = temporal;
  this.rowCount = rowCount;
  this.rowType = rowType;
  this.collationList = collationList;
  this.names = names;
  this.kind = kind;
  this.resolver = resolver;
  this.initializerFactory = initializerFactory;
  for (String name : monotonicColumnSet) {
    addMonotonic(name);
  }
}
 
Example #5
Source File: MutableArrayTable.java    From calcite with Apache License 2.0 5 votes vote down vote up
/** Creates a MutableArrayTable.
 *
 * @param name Name of table within its schema
 * @param protoStoredRowType Prototype of row type of stored columns (all
 *     columns except virtual columns)
 * @param protoRowType Prototype of row type (all columns)
 * @param initializerExpressionFactory How columns are populated
 */
MutableArrayTable(String name, RelProtoDataType protoStoredRowType,
    RelProtoDataType protoRowType,
    InitializerExpressionFactory initializerExpressionFactory) {
  super(name);
  this.protoStoredRowType = Objects.requireNonNull(protoStoredRowType);
  this.protoRowType = Objects.requireNonNull(protoRowType);
  this.initializerExpressionFactory =
      Objects.requireNonNull(initializerExpressionFactory);
}
 
Example #6
Source File: MockCatalogReader.java    From calcite with Apache License 2.0 5 votes vote down vote up
public MockTable(MockCatalogReader catalogReader, String catalogName,
    String schemaName, String name, boolean stream, boolean temporal,
    double rowCount, ColumnResolver resolver,
    InitializerExpressionFactory initializerFactory) {
  this(catalogReader, ImmutableList.of(catalogName, schemaName, name),
      stream, temporal, rowCount, resolver, initializerFactory);
}
 
Example #7
Source File: MockCatalogReader.java    From calcite with Apache License 2.0 5 votes vote down vote up
private MockTable(MockCatalogReader catalogReader, List<String> names,
    boolean stream, boolean temporal, double rowCount,
    ColumnResolver resolver,
    InitializerExpressionFactory initializerFactory) {
  this.catalogReader = catalogReader;
  this.stream = stream;
  this.temporal = temporal;
  this.rowCount = rowCount;
  this.names = names;
  this.resolver = resolver;
  this.initializerFactory = initializerFactory;
}
 
Example #8
Source File: MockCatalogReader.java    From calcite with Apache License 2.0 5 votes vote down vote up
public static MockTable create(MockCatalogReader catalogReader,
    MockSchema schema, String name, boolean stream, double rowCount,
    ColumnResolver resolver,
    InitializerExpressionFactory initializerExpressionFactory,
    boolean temporal) {
  MockTable table =
      new MockTable(catalogReader, schema.getCatalogName(), schema.name,
          name, stream, temporal, rowCount, resolver,
          initializerExpressionFactory);
  schema.addTable(name);
  return table;
}
 
Example #9
Source File: MockCatalogReader.java    From calcite with Apache License 2.0 5 votes vote down vote up
private MockModifiableViewRelOptTable(MockModifiableViewTable modifiableViewTable,
    MockCatalogReader catalogReader, String catalogName, String schemaName, String name,
    boolean stream, double rowCount, ColumnResolver resolver,
    InitializerExpressionFactory initializerExpressionFactory) {
  super(catalogReader, ImmutableList.of(catalogName, schemaName, name),
      stream, false, rowCount, resolver, initializerExpressionFactory);
  this.modifiableViewTable = modifiableViewTable;
}
 
Example #10
Source File: MockCatalogReader.java    From calcite with Apache License 2.0 5 votes vote down vote up
/**
 * Copy constructor.
 */
private MockModifiableViewRelOptTable(MockModifiableViewTable modifiableViewTable,
    MockCatalogReader catalogReader, boolean stream, double rowCount,
    List<Map.Entry<String, RelDataType>> columnList, List<Integer> keyList,
    RelDataType rowType, List<RelCollation> collationList, List<String> names,
    Set<String> monotonicColumnSet, StructKind kind, ColumnResolver resolver,
    InitializerExpressionFactory initializerFactory) {
  super(catalogReader, stream, false, rowCount, columnList, keyList,
      rowType, collationList, names,
      monotonicColumnSet, kind, resolver, initializerFactory);
  this.modifiableViewTable = modifiableViewTable;
}
 
Example #11
Source File: MockCatalogReader.java    From calcite with Apache License 2.0 5 votes vote down vote up
public static MockModifiableViewRelOptTable create(MockModifiableViewTable modifiableViewTable,
    MockCatalogReader catalogReader, String catalogName, String schemaName, String name,
    boolean stream, double rowCount, ColumnResolver resolver) {
  final Table underlying = modifiableViewTable.unwrap(Table.class);
  final InitializerExpressionFactory initializerExpressionFactory =
      underlying instanceof Wrapper
          ? ((Wrapper) underlying).unwrap(InitializerExpressionFactory.class)
          : NullInitializerExpressionFactory.INSTANCE;
  return new MockModifiableViewRelOptTable(modifiableViewTable,
      catalogReader, catalogName, schemaName, name, stream, rowCount,
      resolver, Util.first(initializerExpressionFactory,
      NullInitializerExpressionFactory.INSTANCE));
}
 
Example #12
Source File: MockCatalogReader.java    From calcite with Apache License 2.0 5 votes vote down vote up
private MockRelViewTable(ViewTable viewTable,
    MockCatalogReader catalogReader, String catalogName, String schemaName, String name,
    boolean stream, double rowCount, ColumnResolver resolver,
    InitializerExpressionFactory initializerExpressionFactory) {
  super(catalogReader, ImmutableList.of(catalogName, schemaName, name),
      stream, false, rowCount, resolver, initializerExpressionFactory);
  this.viewTable = viewTable;
}
 
Example #13
Source File: MockCatalogReader.java    From calcite with Apache License 2.0 5 votes vote down vote up
public static MockRelViewTable create(ViewTable viewTable,
    MockCatalogReader catalogReader, String catalogName, String schemaName, String name,
    boolean stream, double rowCount, ColumnResolver resolver) {
  Table underlying = viewTable.unwrap(Table.class);
  InitializerExpressionFactory initializerExpressionFactory =
      underlying instanceof Wrapper
          ? ((Wrapper) underlying).unwrap(InitializerExpressionFactory.class)
          : NullInitializerExpressionFactory.INSTANCE;
  return new MockRelViewTable(viewTable,
      catalogReader, catalogName, schemaName, name, stream, rowCount,
      resolver, Util.first(initializerExpressionFactory,
      NullInitializerExpressionFactory.INSTANCE));
}
 
Example #14
Source File: MockCatalogReader.java    From calcite with Apache License 2.0 5 votes vote down vote up
MockViewTable(MockCatalogReader catalogReader, String catalogName,
    String schemaName, String name, boolean stream, double rowCount,
    MockTable fromTable, ImmutableIntList mapping, ColumnResolver resolver,
    InitializerExpressionFactory initializerFactory) {
  super(catalogReader, catalogName, schemaName, name, stream, false,
      rowCount, resolver, initializerFactory);
  this.fromTable = fromTable;
  this.table = fromTable.unwrap(Table.class);
  this.mapping = mapping;
}