org.apache.calcite.sql2rel.InitializerContext Java Examples
The following examples show how to use
org.apache.calcite.sql2rel.InitializerContext.
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: Prepare.java From calcite with Apache License 2.0 | 6 votes |
@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 #2
Source File: EmpInitializerExpressionFactory.java From calcite with Apache License 2.0 | 6 votes |
@Override public RexNode newColumnDefaultValue(RelOptTable table, int iColumn, InitializerContext context) { final RexBuilder rexBuilder = context.getRexBuilder(); final RelDataTypeFactory typeFactory = rexBuilder.getTypeFactory(); switch (iColumn) { case 0: return rexBuilder.makeExactLiteral(new BigDecimal(123), typeFactory.createSqlType(SqlTypeName.INTEGER)); case 1: return rexBuilder.makeLiteral("Bob"); case 5: return rexBuilder.makeExactLiteral(new BigDecimal(555), typeFactory.createSqlType(SqlTypeName.INTEGER)); default: return super.newColumnDefaultValue(table, iColumn, context); } }
Example #3
Source File: ModifiableViewTable.java From Bats with Apache License 2.0 | 5 votes |
@Override public RexNode newColumnDefaultValue(RelOptTable table, int iColumn, InitializerContext context) { final ModifiableViewTable viewTable = table.unwrap(ModifiableViewTable.class); assert iColumn < viewTable.columnMapping.size(); final RexBuilder rexBuilder = context.getRexBuilder(); final RelDataTypeFactory typeFactory = rexBuilder.getTypeFactory(); final RelDataType viewType = viewTable.getRowType(typeFactory); final RelDataType iType = viewType.getFieldList().get(iColumn).getType(); // 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 rexBuilder.ensureType(iType, viewConstraint, true); } // 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) { final RexNode tableConstraint = initializerExpressionFactory.newColumnDefaultValue(table, iColumn, context); return rexBuilder.ensureType(iType, tableConstraint, true); } } // Otherwise Sql type of NULL. return super.newColumnDefaultValue(table, iColumn, context); }
Example #4
Source File: ModifiableViewTable.java From calcite with Apache License 2.0 | 5 votes |
@Override public RexNode newColumnDefaultValue(RelOptTable table, int iColumn, InitializerContext context) { final ModifiableViewTable viewTable = table.unwrap(ModifiableViewTable.class); assert iColumn < viewTable.columnMapping.size(); final RexBuilder rexBuilder = context.getRexBuilder(); final RelDataTypeFactory typeFactory = rexBuilder.getTypeFactory(); final RelDataType viewType = viewTable.getRowType(typeFactory); final RelDataType iType = viewType.getFieldList().get(iColumn).getType(); // 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 rexBuilder.ensureType(iType, viewConstraint, true); } // 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) { final RexNode tableConstraint = initializerExpressionFactory.newColumnDefaultValue(table, iColumn, context); return rexBuilder.ensureType(iType, tableConstraint, true); } } // Otherwise Sql type of NULL. return super.newColumnDefaultValue(table, iColumn, context); }
Example #5
Source File: CountingFactory.java From calcite with Apache License 2.0 | 5 votes |
@Override public RexNode newColumnDefaultValue(RelOptTable table, int iColumn, InitializerContext context) { THREAD_CALL_COUNT.get().incrementAndGet(); final RelDataTypeField field = table.getRowType().getFieldList().get(iColumn); if (defaultColumns.contains(field.getName())) { final RexBuilder rexBuilder = context.getRexBuilder(); return rexBuilder.makeExactLiteral(BigDecimal.ONE); } return super.newColumnDefaultValue(table, iColumn, context); }
Example #6
Source File: CountingFactory.java From calcite with Apache License 2.0 | 5 votes |
@Override public RexNode newAttributeInitializer(RelDataType type, SqlFunction constructor, int iAttribute, List<RexNode> constructorArgs, InitializerContext context) { THREAD_CALL_COUNT.get().incrementAndGet(); return super.newAttributeInitializer(type, constructor, iAttribute, constructorArgs, context); }
Example #7
Source File: VirtualColumnsExpressionFactory.java From calcite with Apache License 2.0 | 5 votes |
@Override public RexNode newColumnDefaultValue( RelOptTable table, int iColumn, InitializerContext context) { if (iColumn == 4) { final SqlNode node = context.parseExpression(SqlParser.Config.DEFAULT, "A + 1"); // Actually we should validate the node with physical schema, // here full table schema(includes the virtual columns) also works // because the expression "A + 1" does not reference any virtual column. final SqlNode validated = context.validateExpression(table.getRowType(), node); return context.convertExpression(validated); } else { return super.newColumnDefaultValue(table, iColumn, context); } }
Example #8
Source File: ModifiableViewTable.java From Bats with Apache License 2.0 | 4 votes |
@Override public RexNode newAttributeInitializer(RelDataType type, SqlFunction constructor, int iAttribute, List<RexNode> constructorArgs, InitializerContext context) { throw new UnsupportedOperationException("Not implemented - unknown requirements"); }
Example #9
Source File: DremioPrepareTable.java From dremio-oss with Apache License 2.0 | 4 votes |
@Override public boolean columnHasDefaultValue(RelDataType rowType, int ordinal, InitializerContext initializerContext) { return false; }
Example #10
Source File: TestSQLAnalyzer.java From dremio-oss with Apache License 2.0 | 4 votes |
@Override public boolean columnHasDefaultValue(RelDataType rowType, int ordinal, InitializerContext initializerContext) { return false; }
Example #11
Source File: SqlValidatorTable.java From calcite with Apache License 2.0 | 4 votes |
/** * Returns whether the ordinal column has a default value. */ @Deprecated // to be removed before 2.0 boolean columnHasDefaultValue(RelDataType rowType, int ordinal, InitializerContext initializerContext);
Example #12
Source File: ModifiableViewTable.java From calcite with Apache License 2.0 | 4 votes |
@Override public RexNode newAttributeInitializer(RelDataType type, SqlFunction constructor, int iAttribute, List<RexNode> constructorArgs, InitializerContext context) { throw new UnsupportedOperationException("Not implemented - unknown requirements"); }
Example #13
Source File: FlinkPreparingTableBase.java From flink with Apache License 2.0 | 2 votes |
/** * Obtains whether the ordinal column has a default value, which is not supported now. * * @param rowType Row type of field * @param ordinal Index of the given column * @param initializerContext Context for * {@link org.apache.calcite.sql2rel.InitializerExpressionFactory} * @return true if the column has a default value */ public boolean columnHasDefaultValue(RelDataType rowType, int ordinal, InitializerContext initializerContext) { return false; }