Java Code Examples for org.apache.calcite.sql2rel.InitializerContext#getRexBuilder()

The following examples show how to use org.apache.calcite.sql2rel.InitializerContext#getRexBuilder() . 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: EmpInitializerExpressionFactory.java    From calcite with Apache License 2.0 6 votes vote down vote up
@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 2
Source File: CountingFactory.java    From calcite with Apache License 2.0 5 votes vote down vote up
@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);
}