/** * Constructs a type with nullablity. */ BasicSqlType createWithNullability(boolean nullable) { if (nullable == this.isNullable) { return this; } return new BasicSqlType(this.typeSystem, this.typeName, nullable, this.precision, this.scale, this.collation, this.wrappedCharset); }
/** * Constructs a type with charset and collation. * * <p>This must be a character type. */ BasicSqlType createWithCharsetAndCollation(Charset charset, SqlCollation collation) { Preconditions.checkArgument(SqlTypeUtil.inCharFamily(this)); return new BasicSqlType(this.typeSystem, this.typeName, this.isNullable, this.precision, this.scale, collation, SerializableCharset.forCharset(charset)); }
private RelOptTable createVirtualRelOptTable() { List<String> names = createVirtualTableName(); RelDataTypeSystem relDataTypeSystem = new VirtualTypeSystem(); RelDataTypeFieldImpl relDataTypeField = new RelDataTypeFieldImpl( "columnName", 0, new BasicSqlType(relDataTypeSystem, SqlTypeName.ANY)); List<RelDataTypeField> relDataTypeFieldList = new ArrayList<>(); relDataTypeFieldList.add(relDataTypeField); return RelOptTableImpl.create(null, new RelRecordType(relDataTypeFieldList), new VirtualTable(names.get(0)), names, null); }
public RelDataType createSqlType( SqlTypeName typeName, int precision, int scale) { assertBasic(typeName); assert (precision >= 0) || (precision == RelDataType.PRECISION_NOT_SPECIFIED); final int maxPrecision = typeSystem.getMaxPrecision(typeName); if (maxPrecision >= 0 && precision > maxPrecision) { precision = maxPrecision; } RelDataType newType = new BasicSqlType(typeSystem, typeName, precision, scale); newType = SqlTypeUtil.addCharsetAndCollation(newType, this); return canonize(newType); }
public RelDataType createSqlType( SqlTypeName typeName, int precision, int scale) { assertBasic(typeName); assert (precision >= 0) || (precision == RelDataType.PRECISION_NOT_SPECIFIED); final int maxPrecision = typeSystem.getMaxPrecision(typeName); if (maxPrecision >= 0 && precision > maxPrecision) { precision = maxPrecision; } RelDataType newType = new BasicSqlType(typeSystem, typeName, precision, scale); newType = SqlTypeUtil.addCharsetAndCollation(newType, this); return canonize(newType); }
public RelDataType createSqlType(SqlTypeName typeName) { if (typeName.allowsPrec()) { return createSqlType(typeName, typeSystem.getDefaultPrecision(typeName)); } assertBasic(typeName); RelDataType newType = new BasicSqlType(typeSystem, typeName); return canonize(newType); }
public RelDataType createSqlType(SqlTypeName typeName) { if (typeName.allowsPrec()) { return createSqlType(typeName, typeSystem.getDefaultPrecision(typeName)); } assertBasic(typeName); RelDataType newType = new BasicSqlType(typeSystem, typeName); return canonize(newType); }
public RelDataType createSqlType( SqlTypeName typeName, int precision) { final int maxPrecision = typeSystem.getMaxPrecision(typeName); if (maxPrecision >= 0 && precision > maxPrecision) { precision = maxPrecision; } if (typeName.allowsScale()) { return createSqlType(typeName, precision, typeName.getDefaultScale()); } assertBasic(typeName); assert (precision >= 0) || (precision == RelDataType.PRECISION_NOT_SPECIFIED); RelDataType newType = new BasicSqlType(typeSystem, typeName, precision); newType = SqlTypeUtil.addCharsetAndCollation(newType, this); return canonize(newType); }
public RelDataType createSqlType( SqlTypeName typeName, int precision) { final int maxPrecision = typeSystem.getMaxPrecision(typeName); if (maxPrecision >= 0 && precision > maxPrecision) { precision = maxPrecision; } if (typeName.allowsScale()) { return createSqlType(typeName, precision, typeName.getDefaultScale()); } assertBasic(typeName); assert (precision >= 0) || (precision == RelDataType.PRECISION_NOT_SPECIFIED); RelDataType newType = new BasicSqlType(typeSystem, typeName, precision); newType = SqlTypeUtil.addCharsetAndCollation(newType, this); return canonize(newType); }
@Test public void testNumericValuesRelRowTypeAdjustment() { final int INListLength = 20; // Build RowType & Tuples RelDataTypeField relDataType = new RelDataTypeFieldImpl("ROW_VALUE", 0, new BasicSqlType(RelDataTypeSystemImpl.REL_DATA_TYPE_SYSTEM, SqlTypeName.ANY)); RelDataType rowType = new RelRecordType(StructKind.FULLY_QUALIFIED, Arrays.asList(relDataType)); ImmutableList.Builder<ImmutableList<RexLiteral>> tuples = new ImmutableList.Builder<>(); for (int i = 0; i < INListLength; i++) { tuples.add(new ImmutableList.Builder<RexLiteral>().add(new RexBuilder(typeFactory).makeExactLiteral(new BigDecimal(i))).build()); } // Check original types. assertEquals(1, rowType.getFieldCount()); assertEquals(SqlTypeName.ANY, rowType.getFieldList().get(0).getType().getSqlTypeName()); // Construct ValuesRel final ValuesRel valuesRel = new ValuesRel(cluster, rowType, tuples.build(), traits); // Check the adjusted types. RelDataType adjustedRowType = valuesRel.getRowType(); assertEquals(1, adjustedRowType.getFieldCount()); assertEquals(SqlTypeName.INTEGER, adjustedRowType.getFieldList().get(0).getType().getSqlTypeName()); }
@Test public void testCharValuesRelRowTypeAdjustment() { final int INListLength = 20; // Build RowType & Tuples RelDataTypeField relDataType = new RelDataTypeFieldImpl("ROW_VALUE", 0, new BasicSqlType(RelDataTypeSystemImpl.REL_DATA_TYPE_SYSTEM, SqlTypeName.ANY)); RelDataType rowType = new RelRecordType(StructKind.FULLY_QUALIFIED, Arrays.asList(relDataType)); ImmutableList.Builder<ImmutableList<RexLiteral>> tuples = new ImmutableList.Builder<>(); for (int i = 0; i < INListLength; ++i) { tuples.add(new ImmutableList.Builder<RexLiteral>().add(new RexBuilder(typeFactory).makeLiteral(charLiteralBuilder(i))).build()); } // Check original types. assertEquals(1, rowType.getFieldCount()); assertEquals(SqlTypeName.ANY, rowType.getFieldList().get(0).getType().getSqlTypeName()); // Construct ValuesRel final ValuesRel valuesRel = new ValuesRel(cluster, rowType, tuples.build(), traits); // Check the adjusted types. RelDataType adjustedRowType = valuesRel.getRowType(); assertEquals(1, adjustedRowType.getFieldCount()); assertEquals(SqlTypeName.CHAR, adjustedRowType.getFieldList().get(0).getType().getSqlTypeName()); assertEquals(INListLength - 1, adjustedRowType.getFieldList().get(0).getType().getPrecision()); }