org.apache.calcite.schema.ColumnStrategy Java Examples
The following examples show how to use
org.apache.calcite.schema.ColumnStrategy.
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: ModifiableViewTable.java From Bats with Apache License 2.0 | 6 votes |
@Override public ColumnStrategy generationStrategy(RelOptTable table, int iColumn) { final ModifiableViewTable viewTable = table.unwrap(ModifiableViewTable.class); assert iColumn < viewTable.columnMapping.size(); // Use the view constraint to generate the default value if the column is // constrained. final int mappedOrdinal = viewTable.columnMapping.get(iColumn); final RexNode viewConstraint = projectMap.get(mappedOrdinal); if (viewConstraint != null) { return ColumnStrategy.DEFAULT; } // Otherwise use the default value of the underlying table. final Table schemaTable = viewTable.getTable(); if (schemaTable instanceof Wrapper) { final InitializerExpressionFactory initializerExpressionFactory = ((Wrapper) schemaTable).unwrap(InitializerExpressionFactory.class); if (initializerExpressionFactory != null) { return initializerExpressionFactory.generationStrategy(table, iColumn); } } return super.generationStrategy(table, iColumn); }
Example #2
Source File: SqlAlterTableExtension.java From kareldb with Apache License 2.0 | 6 votes |
private void addStrategy(List<io.kareldb.schema.ColumnStrategy> strategies, ColumnStrategy strategy, SqlNode expression) { switch (strategy) { case NULLABLE: strategies.add(io.kareldb.schema.ColumnStrategy.NULL_STRATEGY); break; case NOT_NULLABLE: strategies.add(io.kareldb.schema.ColumnStrategy.NOT_NULL_STRATEGY); break; case DEFAULT: if (expression instanceof SqlLiteral) { strategies.add(new DefaultStrategy(((SqlLiteral) expression).getValue())); } else { strategies.add(io.kareldb.schema.ColumnStrategy.NOT_NULL_STRATEGY); } break; default: strategies.add(io.kareldb.schema.ColumnStrategy.NOT_NULL_STRATEGY); break; } }
Example #3
Source File: ModifiableViewTable.java From calcite with Apache License 2.0 | 6 votes |
@Override public ColumnStrategy generationStrategy(RelOptTable table, int iColumn) { final ModifiableViewTable viewTable = table.unwrap(ModifiableViewTable.class); assert iColumn < viewTable.columnMapping.size(); // Use the view constraint to generate the default value if the column is // constrained. final int mappedOrdinal = viewTable.columnMapping.get(iColumn); final RexNode viewConstraint = projectMap.get(mappedOrdinal); if (viewConstraint != null) { return ColumnStrategy.DEFAULT; } // Otherwise use the default value of the underlying table. final Table schemaTable = viewTable.getTable(); if (schemaTable instanceof Wrapper) { final InitializerExpressionFactory initializerExpressionFactory = ((Wrapper) schemaTable).unwrap(InitializerExpressionFactory.class); if (initializerExpressionFactory != null) { return initializerExpressionFactory.generationStrategy(table, iColumn); } } return super.generationStrategy(table, iColumn); }
Example #4
Source File: SqlCreateTableExtension.java From kareldb with Apache License 2.0 | 6 votes |
private void addStrategy(List<io.kareldb.schema.ColumnStrategy> strategies, ColumnStrategy strategy, SqlNode expression) { switch (strategy) { case NULLABLE: strategies.add(io.kareldb.schema.ColumnStrategy.NULL_STRATEGY); break; case NOT_NULLABLE: strategies.add(io.kareldb.schema.ColumnStrategy.NOT_NULL_STRATEGY); break; case DEFAULT: if (expression instanceof SqlLiteral) { strategies.add(new DefaultStrategy(((SqlLiteral) expression).getValue())); } else { strategies.add(io.kareldb.schema.ColumnStrategy.NOT_NULL_STRATEGY); } break; default: strategies.add(io.kareldb.schema.ColumnStrategy.NOT_NULL_STRATEGY); break; } }
Example #5
Source File: RelOptTableImpl.java From calcite with Apache License 2.0 | 6 votes |
/** Returns the row type of a table after any {@link ColumnStrategy#VIRTUAL} * columns have been removed. This is the type of the records that are * actually stored. */ public static RelDataType realRowType(RelOptTable table) { final RelDataType rowType = table.getRowType(); final List<ColumnStrategy> strategies = columnStrategies(table); if (!strategies.contains(ColumnStrategy.VIRTUAL)) { return rowType; } final RelDataTypeFactory.Builder builder = table.getRelOptSchema().getTypeFactory().builder(); for (RelDataTypeField field : rowType.getFieldList()) { if (strategies.get(field.getIndex()) != ColumnStrategy.VIRTUAL) { builder.add(field); } } return builder.build(); }
Example #6
Source File: RelOptTableImpl.java From calcite with Apache License 2.0 | 6 votes |
/** 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 #7
Source File: ServerDdlExecutor.java From calcite with Apache License 2.0 | 5 votes |
private ColumnDef(SqlNode expr, RelDataType type, ColumnStrategy strategy) { this.expr = expr; this.type = type; this.strategy = Objects.requireNonNull(strategy); Preconditions.checkArgument( strategy == ColumnStrategy.NULLABLE || strategy == ColumnStrategy.NOT_NULLABLE || expr != null); }
Example #8
Source File: EmpInitializerExpressionFactory.java From calcite with Apache License 2.0 | 5 votes |
@Override public ColumnStrategy generationStrategy(RelOptTable table, int iColumn) { switch (iColumn) { case 0: case 1: case 5: return ColumnStrategy.DEFAULT; default: return super.generationStrategy(table, iColumn); } }
Example #9
Source File: VirtualColumnsExpressionFactory.java From calcite with Apache License 2.0 | 5 votes |
@Override public ColumnStrategy generationStrategy(RelOptTable table, int iColumn) { switch (iColumn) { case 3: return ColumnStrategy.STORED; case 4: return ColumnStrategy.VIRTUAL; default: return super.generationStrategy(table, iColumn); } }
Example #10
Source File: CountingFactory.java From calcite with Apache License 2.0 | 5 votes |
@Override public ColumnStrategy generationStrategy(RelOptTable table, int iColumn) { final RelDataTypeField field = table.getRowType().getFieldList().get(iColumn); if (defaultColumns.contains(field.getName())) { return ColumnStrategy.DEFAULT; } return super.generationStrategy(table, iColumn); }
Example #11
Source File: SqlColumnDeclaration.java From calcite with Apache License 2.0 | 5 votes |
/** Creates a SqlColumnDeclaration; use {@link SqlDdlNodes#column}. */ SqlColumnDeclaration(SqlParserPos pos, SqlIdentifier name, SqlDataTypeSpec dataType, SqlNode expression, ColumnStrategy strategy) { super(pos); this.name = name; this.dataType = dataType; this.expression = expression; this.strategy = strategy; }
Example #12
Source File: RelOptTableImpl.java From calcite with Apache License 2.0 | 5 votes |
/** Converts the ordinal of a field into the ordinal of a stored field. * That is, it subtracts the number of virtual fields that come before it. */ public static int realOrdinal(final RelOptTable table, int i) { List<ColumnStrategy> strategies = table.getColumnStrategies(); int n = 0; for (int j = 0; j < i; j++) { switch (strategies.get(j)) { case VIRTUAL: ++n; } } return i - n; }
Example #13
Source File: SqlColumnDeclaration.java From dremio-oss with Apache License 2.0 | 5 votes |
/** * Creates a SqlColumnDeclaration. */ public SqlColumnDeclaration(SqlParserPos pos, SqlIdentifier name, SqlDataTypeSpec dataType, SqlNode expression) { super(pos); this.name = name; this.dataType = dataType; this.expression = expression; this.strategy = ColumnStrategy.NULLABLE; }
Example #14
Source File: SqlAlterTableExtension.java From kareldb with Apache License 2.0 | 5 votes |
private ColumnDef(SqlNode expr, RelDataType type, ColumnStrategy strategy) { this.expr = expr; this.type = type; this.strategy = Objects.requireNonNull(strategy); Preconditions.checkArgument( strategy == ColumnStrategy.NULLABLE || strategy == ColumnStrategy.NOT_NULLABLE || expr != null); }
Example #15
Source File: SqlCreateTableExtension.java From kareldb with Apache License 2.0 | 5 votes |
private ColumnDef(SqlNode expr, RelDataType type, ColumnStrategy strategy) { this.expr = expr; this.type = type; this.strategy = Objects.requireNonNull(strategy); Preconditions.checkArgument( strategy == ColumnStrategy.NULLABLE || strategy == ColumnStrategy.NOT_NULLABLE || expr != null); }
Example #16
Source File: NullInitializerExpressionFactory.java From calcite with Apache License 2.0 | 4 votes |
public ColumnStrategy generationStrategy(RelOptTable table, int iColumn) { return table.getRowType().getFieldList().get(iColumn).getType().isNullable() ? ColumnStrategy.NULLABLE : ColumnStrategy.NOT_NULLABLE; }
Example #17
Source File: NullInitializerExpressionFactory.java From Bats with Apache License 2.0 | 4 votes |
public ColumnStrategy generationStrategy(RelOptTable table, int iColumn) { return table.getRowType().getFieldList().get(iColumn).getType().isNullable() ? ColumnStrategy.NULLABLE : ColumnStrategy.NOT_NULLABLE; }
Example #18
Source File: RelOptAbstractTable.java From Bats with Apache License 2.0 | 4 votes |
public List<ColumnStrategy> getColumnStrategies() { return RelOptTableImpl.columnStrategies(this); }
Example #19
Source File: SqlToRelTestBase.java From calcite with Apache License 2.0 | 4 votes |
public List<ColumnStrategy> getColumnStrategies() { return parent.getColumnStrategies(); }
Example #20
Source File: SqlToRelTestBase.java From calcite with Apache License 2.0 | 4 votes |
public List<ColumnStrategy> getColumnStrategies() { throw new UnsupportedOperationException(); }
Example #21
Source File: RelOptAbstractTable.java From calcite with Apache License 2.0 | 4 votes |
public List<ColumnStrategy> getColumnStrategies() { return RelOptTableImpl.columnStrategies(this); }
Example #22
Source File: SqlDdlNodes.java From calcite with Apache License 2.0 | 4 votes |
/** Creates a column declaration. */ public static SqlNode column(SqlParserPos pos, SqlIdentifier name, SqlDataTypeSpec dataType, SqlNode expression, ColumnStrategy strategy) { return new SqlColumnDeclaration(pos, name, dataType, expression, strategy); }
Example #23
Source File: SqlAlterTableExtension.java From kareldb with Apache License 2.0 | 4 votes |
static ColumnDef of(SqlNode expr, RelDataType type, ColumnStrategy strategy) { return new ColumnDef(expr, type, strategy); }
Example #24
Source File: RelOptTableWrapper.java From dremio-oss with Apache License 2.0 | 4 votes |
@Override public List<ColumnStrategy> getColumnStrategies() { return relOptTable.getColumnStrategies(); }
Example #25
Source File: Prepare.java From calcite with Apache License 2.0 | 4 votes |
public List<ColumnStrategy> getColumnStrategies() { return RelOptTableImpl.columnStrategies(AbstractPreparingTable.this); }
Example #26
Source File: SqlCreateTableExtension.java From kareldb with Apache License 2.0 | 4 votes |
static ColumnDef of(SqlNode expr, RelDataType type, ColumnStrategy strategy) { return new ColumnDef(expr, type, strategy); }
Example #27
Source File: DremioPrepareTable.java From dremio-oss with Apache License 2.0 | 4 votes |
@Override public List<ColumnStrategy> getColumnStrategies() { return ImmutableList.of(); }
Example #28
Source File: ServerDdlExecutor.java From calcite with Apache License 2.0 | 4 votes |
static ColumnDef of(SqlNode expr, RelDataType type, ColumnStrategy strategy) { return new ColumnDef(expr, type, strategy); }
Example #29
Source File: TestSQLAnalyzer.java From dremio-oss with Apache License 2.0 | 4 votes |
@Override public List<ColumnStrategy> getColumnStrategies() { return ImmutableList.of(); }
Example #30
Source File: RelOptNamespaceTable.java From dremio-oss with Apache License 2.0 | 4 votes |
@Override public List<ColumnStrategy> getColumnStrategies() { return ImmutableList.of(); }