/** * @return name of this type */ public String getName() { return toString(); }
sb.append(typeName.name()); boolean printPrecision = (precision != PRECISION_NOT_SPECIFIED); boolean printScale = (scale != SCALE_NOT_SPECIFIED); if (typeName.getDefaultPrecision() > -1) { printPrecision = true; if (typeName.getDefaultScale() > -1) { printScale = true;
< SqlTypeName.INTERVAL_YEAR_MONTH.getMinPrecision()) || (qualifier.getStartPrecision() > SqlTypeName.INTERVAL_YEAR_MONTH.getMaxPrecision())) { startPrecisionOutOfRange = true; } else if ( (qualifier.getFractionalSecondPrecision() < SqlTypeName.INTERVAL_YEAR_MONTH.getMinScale()) || (qualifier.getFractionalSecondPrecision() > SqlTypeName.INTERVAL_YEAR_MONTH.getMaxScale())) { fractionalSecondPrecisionOutOfRange = true; < SqlTypeName.INTERVAL_DAY_TIME.getMinPrecision()) || (qualifier.getStartPrecision() > SqlTypeName.INTERVAL_DAY_TIME.getMaxPrecision())) { startPrecisionOutOfRange = true; } else if ( (qualifier.getFractionalSecondPrecision() < SqlTypeName.INTERVAL_DAY_TIME.getMinScale()) || (qualifier.getFractionalSecondPrecision() > SqlTypeName.INTERVAL_DAY_TIME.getMaxScale())) { fractionalSecondPrecisionOutOfRange = true;
private static Type getType( String string ) { for( int i = 0; i < SqlTypeName.values().length; i++ ) { SqlTypeName typeName = SqlTypeName.values()[ i ]; String typeNameRegex = String.format( "^%s([\\s(].*|)$", typeName.toString() ); boolean matches = string.toUpperCase().matches( typeNameRegex ); boolean isNullable = !string.toUpperCase().contains( "NOT NULL" ); if( matches ) return getJavaTypeFor( typeName, isNullable ); } throw new IllegalStateException( "type not found for: " + string ); }
private RelDataType zzz(int dataType, int precision, int scale) { SqlTypeName sqlTypeName = SqlTypeName.getNameForJdbcType(dataType); if (precision >= 0 && scale >= 0 && sqlTypeName.allowsPrecScale(true, true)) { return typeFactory.createSqlType(sqlTypeName, precision, scale); } else if (precision >= 0 && sqlTypeName.allowsPrecNoScale()) { return typeFactory.createSqlType(sqlTypeName, precision); } else { assert sqlTypeName.allowsNoPrecNoScale(); return typeFactory.createSqlType(sqlTypeName); } }
if (this.isYearMonth()) { this.startPrecision = SqlTypeName.INTERVAL_YEAR_MONTH.getDefaultPrecision(); } else { this.startPrecision = SqlTypeName.INTERVAL_DAY_TIME.getDefaultPrecision(); if (this.isYearMonth()) { this.fractionalSecondPrecision = SqlTypeName.INTERVAL_YEAR_MONTH.getDefaultScale(); } else { this.fractionalSecondPrecision = SqlTypeName.INTERVAL_DAY_TIME.getDefaultScale();
SqlTypeName.INTERVAL_YEAR_MONTH.getMinPrecision() == 1); assertTrue( SqlTypeName.INTERVAL_DAY_TIME.getMinPrecision() == 1); assertTrue( SqlTypeName.INTERVAL_YEAR_MONTH.getMaxPrecision() == 10); assertTrue( SqlTypeName.INTERVAL_DAY_TIME.getMaxPrecision() == 10); assertTrue( SqlTypeName.INTERVAL_YEAR_MONTH.getDefaultPrecision() == 2); assertTrue( SqlTypeName.INTERVAL_DAY_TIME.getDefaultPrecision() == 2); assertTrue( SqlTypeName.INTERVAL_YEAR_MONTH.getMinScale() == 1); assertTrue( SqlTypeName.INTERVAL_DAY_TIME.getMinScale() == 1); assertTrue( SqlTypeName.INTERVAL_YEAR_MONTH.getMaxScale() == 9); assertTrue( SqlTypeName.INTERVAL_DAY_TIME.getMaxScale() == 9); assertTrue( SqlTypeName.INTERVAL_YEAR_MONTH.getDefaultScale() == 6); assertTrue( SqlTypeName.INTERVAL_DAY_TIME.getDefaultScale() == 6);
@Test public void testBit() { SqlTypeName tn = SqlTypeName.getNameForJdbcType(Types.BIT); assertEquals( "BIT did not map to BOOLEAN", SqlTypeName.BOOLEAN, tn); }
String name = typeName.getSimple(); SqlTypeName sqlTypeName = SqlTypeName.get(name); assert sqlTypeName.allowsPrecScale(true, true); type = typeFactory.createSqlType(sqlTypeName, precision, scale); } else if (precision >= 0) { assert sqlTypeName.allowsPrecNoScale(); type = typeFactory.createSqlType(sqlTypeName, precision); } else { assert sqlTypeName.allowsNoPrecNoScale(); type = typeFactory.createSqlType(sqlTypeName); SqlTypeName.get(collectionName);
private Object toJson(RelDataType node) { if (node.isStruct()) { final List<Object> list = jsonBuilder.list(); for (RelDataTypeField field : node.getFieldList()) { list.add(toJson(field)); } return list; } else { final Map<String, Object> map = jsonBuilder.map(); map.put("type", node.getSqlTypeName().name()); map.put("nullable", node.isNullable()); if (node.getSqlTypeName().allowsPrec()) { map.put("precision", node.getPrecision()); } if (node.getSqlTypeName().allowsScale()) { map.put("scale", node.getScale()); } return map; } }
int rightPrec) { String name = typeName.getSimple(); if (SqlTypeName.get(name) != null) { SqlTypeName sqlTypeName = SqlTypeName.get(name); if (sqlTypeName.allowsPrec() && (precision >= 0)) { final SqlWriter.Frame frame = writer.startList(SqlWriter.FrameTypeEnum.FUN_CALL, "(", ")"); writer.print(precision); if (sqlTypeName.allowsScale() && (scale >= 0)) { writer.sep(",", true); writer.print(scale);
boolean beyond) int precision = typeName.allowsPrec() ? this.getPrecision() : -1; int scale = typeName.allowsScale() ? this.getScale() : -1; return typeName.getLimit( sign, limit,
public RelDataType createSqlType(SqlTypeName typeName) { if (typeName.allowsPrec()) { return createSqlType(typeName, typeName.getDefaultPrecision()); } assertBasic(typeName); RelDataType newType = new BasicSqlType(typeName); return canonize(newType); }
public RelDataType createSqlType( SqlTypeName typeName, int precision) { if (typeName.allowsScale()) { return createSqlType(typeName, precision, typeName.getDefaultScale()); } assertBasic(typeName); assert (precision >= 0) || (precision == RelDataType.PRECISION_NOT_SPECIFIED); RelDataType newType = new BasicSqlType(typeName, precision); newType = SqlTypeUtil.addCharsetAndCollation(newType, this); return canonize(newType); }
public MetaColumn apply(RelDataTypeField a0) { final int precision = a0.getType().getSqlTypeName().allowsPrec() && !(a0.getType() instanceof RelDataTypeFactoryImpl.JavaType) ? a0.getType().getPrecision() : -1; return new MetaColumn( table.tableCat, table.tableSchem, table.tableName, a0.getName(), a0.getType().getSqlTypeName().getJdbcOrdinal(), a0.getType().getFullTypeString(), precision, a0.getType().getSqlTypeName().allowsScale() ? a0.getType().getScale() : null, 10, a0.getType().isNullable() ? DatabaseMetaData.columnNullable : DatabaseMetaData.columnNoNulls, precision, a0.getIndex() + 1, a0.getType().isNullable() ? "YES" : "NO"); } }
if (!typeName.allowsPrec() && !resultTypeName.allowsPrec()) {
SqlTypeName.INTERVAL_YEAR_MONTH.getMinPrecision() == 1); assertTrue( SqlTypeName.INTERVAL_DAY_TIME.getMinPrecision() == 1); assertTrue( SqlTypeName.INTERVAL_YEAR_MONTH.getMaxPrecision() == 10); assertTrue( SqlTypeName.INTERVAL_DAY_TIME.getMaxPrecision() == 10); assertTrue( SqlTypeName.INTERVAL_YEAR_MONTH.getDefaultPrecision() == 2); assertTrue( SqlTypeName.INTERVAL_DAY_TIME.getDefaultPrecision() == 2); assertTrue( SqlTypeName.INTERVAL_YEAR_MONTH.getMinScale() == 1); assertTrue( SqlTypeName.INTERVAL_DAY_TIME.getMinScale() == 1); assertTrue( SqlTypeName.INTERVAL_YEAR_MONTH.getMaxScale() == 9); assertTrue( SqlTypeName.INTERVAL_DAY_TIME.getMaxScale() == 9); assertTrue( SqlTypeName.INTERVAL_YEAR_MONTH.getDefaultScale() == 6); assertTrue( SqlTypeName.INTERVAL_DAY_TIME.getDefaultScale() == 6);
@Test public void testSmallint() { SqlTypeName tn = SqlTypeName.getNameForJdbcType(Types.SMALLINT); assertEquals( "SMALLINT did not map to SMALLINT", SqlTypeName.SMALLINT, tn); }
private RelDataType sqlType(RelDataTypeFactory typeFactory, int dataType, int precision, int scale, String typeString) { SqlTypeName sqlTypeName = SqlTypeName.getNameForJdbcType(dataType); switch (sqlTypeName) { case ARRAY: RelDataType component = null; if (typeString != null && typeString.endsWith(" ARRAY")) { // E.g. hsqldb gives "INTEGER ARRAY", so we deduce the component type // "INTEGER". final String remaining = typeString.substring(0, typeString.length() - " ARRAY".length()); component = parseTypeString(typeFactory, remaining); } if (component == null) { component = typeFactory.createSqlType(SqlTypeName.ANY); } return typeFactory.createArrayType(component, -1); } if (precision >= 0 && scale >= 0 && sqlTypeName.allowsPrecScale(true, true)) { return typeFactory.createSqlType(sqlTypeName, precision, scale); } else if (precision >= 0 && sqlTypeName.allowsPrecNoScale()) { return typeFactory.createSqlType(sqlTypeName, precision); } else { assert sqlTypeName.allowsNoPrecNoScale(); return typeFactory.createSqlType(sqlTypeName); } }
if (this.isYearMonth()) { this.startPrecision = SqlTypeName.INTERVAL_YEAR_MONTH.getDefaultPrecision(); } else { this.startPrecision = SqlTypeName.INTERVAL_DAY_TIME.getDefaultPrecision(); if (this.isYearMonth()) { this.fractionalSecondPrecision = SqlTypeName.INTERVAL_YEAR_MONTH.getDefaultScale(); } else { this.fractionalSecondPrecision = SqlTypeName.INTERVAL_DAY_TIME.getDefaultScale();