Java Code Examples for java.sql.Types#FLOAT

The following examples show how to use java.sql.Types#FLOAT . 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: EnumType.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private boolean isNumericType(int jdbcTypeCode) {
	switch ( jdbcTypeCode ) {
		case Types.INTEGER:
		case Types.NUMERIC:
		case Types.SMALLINT:
		case Types.TINYINT:
		case Types.BIGINT:
		case Types.DECIMAL:
		case Types.DOUBLE:
		case Types.FLOAT: {
			return true;
		}
		default:
			return false;
	}
}
 
Example 2
Source File: BaseJDBCTestCase.java    From kareldb with Apache License 2.0 6 votes vote down vote up
/**
 * Compares two JDBC types to see if they are equivalent.
 * DECIMAL and NUMERIC and DOUBLE and FLOAT are considered
 * equivalent.
 *
 * @param expectedType Expected jdbctype from java.sql.Types
 * @param type         Actual type from metadata
 */
public static void assertEquivalentDataType(int expectedType, int type) {
    if (expectedType == type)
        return;
    if (expectedType == Types.DECIMAL &&
        type == Types.NUMERIC)
        return;
    if (expectedType == Types.NUMERIC &&
        type == Types.DECIMAL)
        return;
    if (expectedType == Types.DOUBLE &&
        type == Types.FLOAT)
        return;
    if (expectedType == Types.FLOAT &&
        type == Types.DOUBLE)
        return;
    fail("types:" + expectedType + " and " + type + " are not equivalent");

}
 
Example 3
Source File: HiveTypes.java    From aliyun-maxcompute-data-collectors with Apache License 2.0 5 votes vote down vote up
/**
 * Given JDBC SQL types coming from another database, what is the best
 * mapping to a Hive-specific type?
 */
public static String toHiveType(int sqlType) {

    switch (sqlType) {
        case Types.INTEGER:
        case Types.SMALLINT:
            return "INT";
        case Types.VARCHAR:
        case Types.CHAR:
        case Types.LONGVARCHAR:
        case Types.NVARCHAR:
        case Types.NCHAR:
        case Types.LONGNVARCHAR:
        case Types.DATE:
        case Types.TIME:
        case Types.TIMESTAMP:
        case Types.CLOB:
            return "STRING";
        case Types.NUMERIC:
        case Types.DECIMAL:
        case Types.FLOAT:
        case Types.DOUBLE:
        case Types.REAL:
            return "DOUBLE";
        case Types.BIT:
        case Types.BOOLEAN:
            return "BOOLEAN";
        case Types.TINYINT:
            return "TINYINT";
        case Types.BIGINT:
            return "BIGINT";
        default:
      // TODO(aaron): Support BINARY, VARBINARY, LONGVARBINARY, DISTINCT,
      // BLOB, ARRAY, STRUCT, REF, JAVA_OBJECT.
      return null;
    }
}
 
Example 4
Source File: JDBCAdapter.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Class<?> getColumnClass(int column) {
    int type;
    try {
        type = metaData.getColumnType(column + 1);
    } catch (SQLException e) {
        return super.getColumnClass(column);
    }

    switch (type) {
        case Types.CHAR:
        case Types.VARCHAR:
        case Types.LONGVARCHAR:
            return String.class;

        case Types.BIT:
            return Boolean.class;

        case Types.TINYINT:
        case Types.SMALLINT:
        case Types.INTEGER:
            return Integer.class;

        case Types.BIGINT:
            return Long.class;

        case Types.FLOAT:
        case Types.DOUBLE:
            return Double.class;

        case Types.DATE:
            return java.sql.Date.class;

        default:
            return Object.class;
    }
}
 
Example 5
Source File: JDBCAdapter.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public String dbRepresentation(int column, Object value) {
    int type;

    if (value == null) {
        return "null";
    }

    try {
        type = metaData.getColumnType(column + 1);
    } catch (SQLException e) {
        return value.toString();
    }

    switch (type) {
        case Types.INTEGER:
        case Types.DOUBLE:
        case Types.FLOAT:
            return value.toString();
        case Types.BIT:
            return ((Boolean) value).booleanValue() ? "1" : "0";
        case Types.DATE:
            return value.toString(); // This will need some conversion.
        default:
            return "\"" + value.toString() + "\"";
    }

}
 
Example 6
Source File: Column.java    From openemm with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Clear the value (set to an empty or zero value)
 */
public void clr () {
	value = null;
	isnull = true;
	switch (type) {
	default:
		break;
	case Types.DECIMAL:
	case Types.NUMERIC:
	case Types.DOUBLE:
	case Types.FLOAT:
	case Types.REAL:
		ival = 0;
		fval = 0.0;
		break;
	case Types.BIGINT:
	case Types.INTEGER:
	case Types.SMALLINT:
	case Types.TINYINT:
		ival = 0;
		break;
	case Types.CHAR:
	case Types.VARCHAR:
	case Types.BLOB:
	case Types.CLOB:
		sval = null;
		break;
	case Types.DATE:
	case Types.TIME:
	case Types.TIMESTAMP:
		dval = null;
		break;
	}
}
 
Example 7
Source File: JdbcTypeUtil.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
public static Class<?> jdbcType2javaType(int jdbcType) {
    switch (jdbcType) {
        case Types.BIT:
        case Types.BOOLEAN:
            // return Boolean.class;
        case Types.TINYINT:
            return Byte.TYPE;
        case Types.SMALLINT:
            return Short.class;
        case Types.INTEGER:
            return Integer.class;
        case Types.BIGINT:
            return Long.class;
        case Types.DECIMAL:
        case Types.NUMERIC:
            return BigDecimal.class;
        case Types.REAL:
            return Float.class;
        case Types.FLOAT:
        case Types.DOUBLE:
            return Double.class;
        case Types.CHAR:
        case Types.VARCHAR:
        case Types.LONGVARCHAR:
            return String.class;
        case Types.BINARY:
        case Types.VARBINARY:
        case Types.LONGVARBINARY:
        case Types.BLOB:
            return byte[].class;
        case Types.DATE:
            return java.sql.Date.class;
        case Types.TIME:
            return Time.class;
        case Types.TIMESTAMP:
            return Timestamp.class;
        default:
            return String.class;
    }
}
 
Example 8
Source File: DataTypeUtilities.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Is the data type signed.
 * 
 * @param dtd
 *          data type descriptor
 */
public static boolean isSigned(DataTypeDescriptor dtd) {
  int typeId = dtd.getTypeId().getJDBCTypeId();

  return (typeId == Types.INTEGER || typeId == Types.FLOAT
      || typeId == Types.DECIMAL || typeId == Types.SMALLINT
      || typeId == Types.BIGINT || typeId == Types.TINYINT
      || typeId == Types.NUMERIC || typeId == Types.REAL || typeId == Types.DOUBLE);
}
 
Example 9
Source File: RowSetMetaDataTests.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name = "columnClassNames")
private Object[][] columnClassNames() {
    return new Object[][]{
        {Types.CHAR, "java.lang.String"},
        {Types.NCHAR, "java.lang.String"},
        {Types.VARCHAR, "java.lang.String"},
        {Types.NVARCHAR, "java.lang.String"},
        {Types.LONGVARCHAR, "java.lang.String"},
        {Types.LONGNVARCHAR, "java.lang.String"},
        {Types.NUMERIC, "java.math.BigDecimal"},
        {Types.DECIMAL, "java.math.BigDecimal"},
        {Types.BIT, "java.lang.Boolean"},
        {Types.TINYINT, "java.lang.Byte"},
        {Types.SMALLINT, "java.lang.Short"},
        {Types.INTEGER, "java.lang.Integer"},
        {Types.FLOAT, "java.lang.Double"},
        {Types.DOUBLE, "java.lang.Double"},
        {Types.BINARY, "byte[]"},
        {Types.VARBINARY, "byte[]"},
        {Types.LONGVARBINARY, "byte[]"},
        {Types.DATE, "java.sql.Date"},
        {Types.TIME, "java.sql.Time"},
        {Types.TIMESTAMP, "java.sql.Timestamp"},
        {Types.CLOB, "java.sql.Clob"},
        {Types.BLOB, "java.sql.Blob"}

    };

}
 
Example 10
Source File: AbstractJdbcPOJOOutputOperator.java    From attic-apex-malhar with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
protected void setStatementParameters(PreparedStatement statement, Object tuple) throws SQLException
{
  final int size = columnDataTypes.size();
  for (int i = 0; i < size; i++) {
    final int type = columnDataTypes.get(i);
    ActiveFieldInfo activeFieldInfo = columnFieldGetters.get(i);
    switch (type) {
      case (Types.CHAR):
      case (Types.VARCHAR):
        statement.setString(i + 1, ((Getter<Object, String>)activeFieldInfo.setterOrGetter).get(tuple));
        break;

      case (Types.BOOLEAN):
        statement.setBoolean(i + 1, ((GetterBoolean<Object>)activeFieldInfo.setterOrGetter).get(tuple));
        break;

      case (Types.TINYINT):
        statement.setByte(i + 1, ((PojoUtils.GetterByte<Object>)activeFieldInfo.setterOrGetter).get(tuple));
        break;

      case (Types.SMALLINT):
        statement.setShort(i + 1, ((GetterShort<Object>)activeFieldInfo.setterOrGetter).get(tuple));
        break;

      case (Types.INTEGER):
        statement.setInt(i + 1, ((GetterInt<Object>)activeFieldInfo.setterOrGetter).get(tuple));
        break;

      case (Types.BIGINT):
        statement.setLong(i + 1, ((GetterLong<Object>)activeFieldInfo.setterOrGetter).get(tuple));
        break;

      case (Types.FLOAT):
        statement.setFloat(i + 1, ((GetterFloat<Object>)activeFieldInfo.setterOrGetter).get(tuple));
        break;

      case (Types.DOUBLE):
        statement.setDouble(i + 1, ((GetterDouble<Object>)activeFieldInfo.setterOrGetter).get(tuple));
        break;

      case Types.DECIMAL:
        statement.setBigDecimal(i + 1, ((Getter<Object, BigDecimal>)activeFieldInfo.setterOrGetter).get(tuple));
        break;

      case Types.TIMESTAMP:
        statement.setTimestamp(i + 1, ((Getter<Object, Timestamp>)activeFieldInfo.setterOrGetter).get(tuple));
        break;

      case Types.TIME:
        statement.setTime(i + 1, ((Getter<Object, Time>)activeFieldInfo.setterOrGetter).get(tuple));
        break;

      case Types.DATE:
        statement.setDate(i + 1, ((Getter<Object, Date>)activeFieldInfo.setterOrGetter).get(tuple));
        break;

      default:
        handleUnknownDataType(type, tuple, activeFieldInfo);
        break;
    }
  }
}
 
Example 11
Source File: PFloat.java    From phoenix with Apache License 2.0 4 votes vote down vote up
private PFloat() {
  super("FLOAT", Types.FLOAT, Float.class, new FloatCodec(), 6);
}
 
Example 12
Source File: JavaSqlConversion.java    From aceql-http with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static String fromJavaToSql(int javaType) {
String sqlType = null;

if (javaType == Types.CHAR) {
    sqlType = AceQLTypes.CHAR;
} else if (javaType == Types.VARCHAR) {
    sqlType = AceQLTypes.VARCHAR;
} else if (javaType == Types.LONGVARCHAR) {
    sqlType = AceQLTypes.LONGVARCHAR;
} else if (javaType == Types.NUMERIC) {
    sqlType = AceQLTypes.NUMERIC;
} else if (javaType == Types.BIT) {
    sqlType = AceQLTypes.BIT;
} else if (javaType == Types.NUMERIC) {
    sqlType = AceQLTypes.NUMERIC;
} else if (javaType == Types.DECIMAL) {
    sqlType = AceQLTypes.DECIMAL;
} else if (javaType == Types.TINYINT) {
    sqlType = AceQLTypes.TINYINT;
} else if (javaType == Types.SMALLINT) {
    sqlType = AceQLTypes.SMALLINT;
} else if (javaType == Types.INTEGER) {
    sqlType = AceQLTypes.INTEGER;
} else if (javaType == Types.BIGINT) {
    sqlType = AceQLTypes.BIGINT;
} else if (javaType == Types.REAL) {
    sqlType = AceQLTypes.REAL;
} else if (javaType == Types.FLOAT) {
    sqlType = AceQLTypes.FLOAT;
} else if (javaType == Types.DOUBLE) {
    sqlType = AceQLTypes.DOUBLE_PRECISION;
} else if (javaType == Types.DATE) {
    sqlType = AceQLTypes.DATE;
} else if (javaType == Types.TIME) {
    sqlType = AceQLTypes.TIME;
} else if (javaType == Types.TIMESTAMP) {
    sqlType = AceQLTypes.TIMESTAMP;
} else if (javaType == Types.BINARY) {
    sqlType = AceQLTypes.BINARY;
} else if (javaType == Types.VARBINARY) {
    sqlType = AceQLTypes.VARBINARY;
} else if (javaType == Types.LONGVARBINARY) {
    sqlType = AceQLTypes.LONGVARBINARY;
} else if (javaType == Types.BLOB) {
    sqlType = AceQLTypes.BLOB;
} else if (javaType == Types.CLOB) {
    sqlType = AceQLTypes.CLOB;
} else {
    return "UNKNOWN";
}
return sqlType;
   }
 
Example 13
Source File: GfxdCBArgForSynchPrms.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public String getColumnClassName(int column) throws SQLException {
  if (column > 0 && column <= this.numParams) {
    if (this.dtds != null) {
      return this.dtds[column - 1].getTypeId().getResultSetMetaDataTypeName();
    }
    else {
      switch (this.sqlParamTypes[column - 1]) {
        case Types.BIT:
        case Types.BOOLEAN:
          return "java.lang.Boolean";
        case Types.TINYINT:
          return "java.lang.Integer";
        case Types.SMALLINT:
          return "java.lang.Integer";
        case Types.INTEGER:
          return "java.lang.Integer";
        case Types.BIGINT:
          return "java.lang.Long";
        case Types.FLOAT:
        case Types.REAL:
          return "java.lang.Float";
        case Types.DOUBLE:
          return "java.lang.Double";
        case Types.NUMERIC:
        case Types.DECIMAL:
          return "java.math.BigDecimal";
        case Types.CHAR:
        case Types.VARCHAR:
        case Types.LONGVARCHAR:
          return "java.lang.String";
        case Types.DATE:
          return "java.sql.Date";
        case Types.TIME:
          return "java.sql.Time";
        case Types.TIMESTAMP:
          return "java.sql.Timestamp";
        case Types.BINARY:
        case Types.VARBINARY:
        case Types.LONGVARBINARY:
          return "byte[]";
        case BLOB:
          return "java.sql.Blob";
        case CLOB:
          return "java.sql.Clob";
        case SQLXML:
          return "com.pivotal.gemfirexd.internal.iapi.types.XML";
        case JSON:
          return "com.pivotal.gemfirexd.internal.iapi.types.JSON";
        case JAVA_OBJECT:
          final DataValueDescriptor dvd = this.params[column - 1];
          if (dvd != null) {
            try {
              final Object o = dvd.getObject();
              if (o != null) {
                return o.getClass().getName();
              }
            } catch (StandardException se) {
              throw Util.generateCsSQLException(se);
            }
          }
          return "NULL UDT";
        default:
          throw Util.generateCsSQLException(SQLState.UNSUPPORTED_TYPE);
      }
    }
  }
  else {
    throw Util.generateCsSQLException(SQLState.COLUMN_NOT_FOUND,
        Integer.valueOf(column));
  }
}
 
Example 14
Source File: TypeFloat.java    From antsdb with GNU Lesser General Public License v3.0 4 votes vote down vote up
public TypeFloat(String name) {
    super(name, 0, 0, Types.FLOAT, Float.class, Value.TYPE_NUMBER, Weight.FLOAT);
}
 
Example 15
Source File: ExportAbstract.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
protected void doAllTheWork() throws Exception {

	ResultSet rs = null;
	try {
    	rs = resultSetForEntity();
    	if (rs != null) {
			ResultSetMetaData rsmeta = rs.getMetaData();
			int ncols = rsmeta.getColumnCount();
			boolean[] isNumeric = new boolean[ncols];
			boolean[] isLargeChar = new boolean[ncols];
			boolean[] isLargeBinary = new boolean[ncols];
			for (int i = 0; i < ncols; i++) {
				int ctype = rsmeta.getColumnType(i+1);
				if (ctype == Types.BIGINT || ctype == Types.DECIMAL || ctype == Types.DOUBLE ||
						ctype == Types.FLOAT ||ctype == Types.INTEGER || ctype == Types.NUMERIC ||
						ctype == Types.REAL ||ctype == Types.SMALLINT || ctype == Types.TINYINT)
    				isNumeric[i] = true;
				else 
					isNumeric[i] = false;
					
				if (ctype == Types.CLOB || ctype == JDBC40Translation.JSON)
					isLargeChar[i] = true;
				else 
					isLargeChar[i]= false;
				
				if (ctype == Types.BLOB) 
					isLargeBinary[i] = true;
				else 
					isLargeBinary[i] = false;
			}


			exportWriteData = getExportWriteData();
			exportWriteData.writeColumnDefinitionOptionally(
						exportResultSetForObject.getColumnDefinition(),
						exportResultSetForObject.getColumnTypes());
			exportWriteData.setColumnLengths(controlFileReader.getColumnWidths());

       		// get one row at a time and write it to the output file
            String[] oneRow = getOneRowAtATime(rs, 
                                               isLargeBinary, 
                                               isLargeChar);
       		while (oneRow != null) {
         		exportWriteData.writeData(oneRow, isNumeric);
                oneRow = getOneRowAtATime(rs, isLargeBinary, isLargeChar);
       		}
		}
	} finally {
		//cleanup work after no more rows
		if (exportWriteData != null)
			exportWriteData.noMoreRows();
		if (rs != null)
			rs.close();
    }
  }
 
Example 16
Source File: TypesTranslator.java    From sql-layer with GNU Affero General Public License v3.0 4 votes vote down vote up
public Class<?> jdbcClass(TInstance type) {
    TClass tclass = TInstance.tClass(type);
    if (tclass == null)
        return Object.class;
    int jdbcType = tclass.jdbcType();
    switch (jdbcType) {
    case Types.DECIMAL:
    case Types.NUMERIC:
        return BigDecimal.class;
    case Types.BOOLEAN:
        return Boolean.class;
    case Types.TINYINT:
        return Byte.class;
    case Types.BINARY:
    case Types.BIT:
    case Types.LONGVARBINARY:
    case Types.VARBINARY:
    case Types.BLOB:
        return byte[].class;
    case Types.DATE:
        return java.sql.Date.class;
    case Types.DOUBLE:
        return Double.class;
    case Types.FLOAT:
    case Types.REAL:
        return Float.class;
    case Types.INTEGER:
        return Integer.class;
    case Types.BIGINT:
        return Long.class;
    case Types.SMALLINT:
        return Short.class;
    case Types.CHAR:
    case Types.LONGNVARCHAR:
    case Types.LONGVARCHAR:
    case Types.NCHAR:
    case Types.NVARCHAR:
    case Types.VARCHAR:
    case Types.CLOB:
        return String.class;
    case Types.TIME:
        return java.sql.Time.class;
    case Types.TIMESTAMP:
        return java.sql.Timestamp.class;

    /*
    case Types.ARRAY:
        return java.sql.Array.class;
    case Types.BLOB:
        return java.sql.Blob.class;
    case Types.CLOB:
        return java.sql.Clob.class;
    case Types.NCLOB:
        return java.sql.NClob.class;
    case Types.REF:
        return java.sql.Ref.class;
    case Types.ROWID:
        return java.sql.RowId.class;
    case Types.SQLXML:
        return java.sql.SQLXML.class;
    */

    case Types.NULL:
    case Types.DATALINK:
    case Types.DISTINCT:
    case Types.JAVA_OBJECT:
    case Types.OTHER:
    case Types.STRUCT:
    default:
        break;
    }
    if (tclass == AkResultSet.INSTANCE)
        return java.sql.ResultSet.class;
    return Object.class;
}
 
Example 17
Source File: ConvertJSONToSQL.java    From nifi with Apache License 2.0 4 votes vote down vote up
/**
 *  Try to create correct SQL String representation of value.
 *
 */
protected static String createSqlStringValue(final JsonNode fieldNode, final Integer colSize, final int sqlType) {
    String fieldValue = fieldNode.asText();

    switch (sqlType) {

    // only "true" is considered true, everything else is false
    case Types.BOOLEAN:
        fieldValue = Boolean.valueOf(fieldValue).toString();
        break;

    // Don't truncate numeric types.
    case Types.BIT:
    case Types.TINYINT:
    case Types.SMALLINT:
    case Types.INTEGER:
    case Types.BIGINT:
    case Types.REAL:
    case Types.FLOAT:
    case Types.DOUBLE:
    case Types.DECIMAL:
    case Types.NUMERIC:
        if (fieldNode.isBoolean()) {
            // Convert boolean to number representation for databases those don't support boolean type.
            fieldValue = fieldNode.asBoolean() ? "1" : "0";
        }
        break;

    // Don't truncate DATE, TIME and TIMESTAMP types. We assume date and time is already correct in long representation.
    // Specifically, milliseconds since January 1, 1970, 00:00:00 GMT
    // However, for TIMESTAMP, PutSQL accepts optional timestamp format via FlowFile attribute.
    // See PutSQL.setParameter method and NIFI-3430 for detail.
    // Alternatively, user can use JSONTreeReader and PutDatabaseRecord to handle date format more efficiently.
    case Types.DATE:
    case Types.TIME:
    case Types.TIMESTAMP:
        break;

    // Truncate string data types only.
    case Types.CHAR:
    case Types.VARCHAR:
    case Types.LONGVARCHAR:
    case Types.NCHAR:
    case Types.NVARCHAR:
    case Types.LONGNVARCHAR:
        if (colSize != null && fieldValue.length() > colSize) {
            fieldValue = fieldValue.substring(0, colSize);
        }
        break;
    }

    return fieldValue;
}
 
Example 18
Source File: Diff.java    From jsqsh with Apache License 2.0 4 votes vote down vote up
private Object[] getRow(ResultSet set)
    throws SQLException {
    
    ResultSetMetaData meta = set.getMetaData();
    int ncols = meta.getColumnCount();
    Object []values = new Object[ncols];
    for (int c = 1; c <= ncols; c++) {
        
        int type = meta.getColumnType(c);
        switch (type) {
            
            case Types.NUMERIC:
            case Types.DECIMAL:
                values[c - 1] = set.getBigDecimal(c);
                break;
                
            case Types.BINARY:
            case Types.VARBINARY:
            case Types.LONGVARBINARY:
                ByteFormatter f = new ByteFormatter(
                    meta.getColumnDisplaySize(c));
                values[c - 1] = f.format(set.getObject(c));
                break;
                
            case Types.BLOB:
                BlobFormatter b = new BlobFormatter();
                values[c - 1] = b.format(set.getObject(c));
                break;
                
            case Types.CLOB:
                ClobFormatter cf= new ClobFormatter();
                values[c - 1] = cf.format(set.getObject(c));
                break;
                
            case Types.BOOLEAN:
                values[c - 1] = set.getBoolean(c);
                break;
                
            case Types.CHAR:
            case Types.VARCHAR:
            /* case Types.NVARCHAR:*/
            /* case Types.LONGNVARCHAR: */
            case Types.LONGVARCHAR:
            /* case Types.NCHAR: */
                values[c - 1] = set.getString(c);
                break;
                
            case Types.DATE:
            case Types.TIME:
            case Types.TIMESTAMP:
                values[c - 1] = set.getObject(c);
                break;
                
            case Types.DOUBLE:
            case Types.FLOAT:
            case Types.REAL:
                values[c - 1] = set.getDouble(c);
                break;
               
            case Types.BIT:
            case Types.TINYINT:
            case Types.SMALLINT:
            case Types.INTEGER:
            case Types.BIGINT:
                values[c - 1] = new Long(set.getLong(c));
                break;
                
            default:
                System.err.println("WARNING: I do not understand "
                    + "datatype #" + type + " ("
                    + meta.getColumnTypeName(c) + ") in column #"
                    + c + ". No comparison will be performed.");
                values[c - 1] = set.getObject(c);
                break;
        }
        
        if (set.wasNull()) {
            
            values[c - 1] = "NULL";
        }
    }
    
    return values;
}
 
Example 19
Source File: StandardColumnMappings.java    From presto with Apache License 2.0 4 votes vote down vote up
public static Optional<ColumnMapping> jdbcTypeToPrestoType(ConnectorSession session, JdbcTypeHandle type)
{
    int columnSize = type.getColumnSize();
    switch (type.getJdbcType()) {
        case Types.BIT:
        case Types.BOOLEAN:
            return Optional.of(booleanColumnMapping());

        case Types.TINYINT:
            return Optional.of(tinyintColumnMapping());

        case Types.SMALLINT:
            return Optional.of(smallintColumnMapping());

        case Types.INTEGER:
            return Optional.of(integerColumnMapping());

        case Types.BIGINT:
            return Optional.of(bigintColumnMapping());

        case Types.REAL:
            return Optional.of(realColumnMapping());

        case Types.FLOAT:
        case Types.DOUBLE:
            return Optional.of(doubleColumnMapping());

        case Types.NUMERIC:
        case Types.DECIMAL:
            int decimalDigits = type.getDecimalDigits();
            int precision = columnSize + max(-decimalDigits, 0); // Map decimal(p, -s) (negative scale) to decimal(p+s, 0).
            if (precision > Decimals.MAX_PRECISION) {
                return Optional.empty();
            }
            return Optional.of(decimalColumnMapping(createDecimalType(precision, max(decimalDigits, 0)), UNNECESSARY));

        case Types.CHAR:
        case Types.NCHAR:
            // TODO this is wrong, we're going to construct malformed Slice representation if source > charLength
            int charLength = min(columnSize, CharType.MAX_LENGTH);
            return Optional.of(charColumnMapping(createCharType(charLength)));

        case Types.VARCHAR:
        case Types.NVARCHAR:
        case Types.LONGVARCHAR:
        case Types.LONGNVARCHAR:
            if (columnSize > VarcharType.MAX_LENGTH) {
                return Optional.of(varcharColumnMapping(createUnboundedVarcharType()));
            }
            return Optional.of(varcharColumnMapping(createVarcharType(columnSize)));

        case Types.BINARY:
        case Types.VARBINARY:
        case Types.LONGVARBINARY:
            return Optional.of(varbinaryColumnMapping());

        case Types.DATE:
            return Optional.of(dateColumnMapping());

        case Types.TIME:
            // TODO default to `timeColumnMapping`
            return Optional.of(timeColumnMappingUsingSqlTime(session));

        case Types.TIMESTAMP:
            // TODO default to `timestampColumnMapping`
            return Optional.of(timestampColumnMappingUsingSqlTimestamp(session));
    }
    return Optional.empty();
}
 
Example 20
Source File: Util.java    From spliceengine with GNU Affero General Public License v3.0 4 votes vote down vote up
public static String typeName(int jdbcType) {
	switch (jdbcType) {
		case Types.ARRAY: return TypeId.ARRAY_NAME;
		case Types.BIT 		:  return TypeId.BIT_NAME;
		case Types.BOOLEAN  : return TypeId.BOOLEAN_NAME;
		case Types.DATALINK: return TypeId.DATALINK_NAME;
		case Types.TINYINT 	:  return TypeId.TINYINT_NAME;
		case Types.SMALLINT	:  return TypeId.SMALLINT_NAME;
		case Types.INTEGER 	:  return TypeId.INTEGER_NAME;
		case Types.BIGINT 	:  return TypeId.LONGINT_NAME;

		case Types.FLOAT 	:  return TypeId.FLOAT_NAME;
		case Types.REAL 	:  return TypeId.REAL_NAME;
		case Types.DOUBLE 	:  return TypeId.DOUBLE_NAME;

		case Types.NUMERIC 	:  return TypeId.NUMERIC_NAME;
		case Types.DECIMAL	:  return TypeId.DECIMAL_NAME;

		case Types.CHAR		:  return TypeId.CHAR_NAME;
		case Types.VARCHAR 	:  return TypeId.VARCHAR_NAME;
		case Types.LONGVARCHAR 	:  return "LONGVARCHAR";
           case Types.CLOB     :  return TypeId.CLOB_NAME;

		case Types.DATE 		:  return TypeId.DATE_NAME;
		case Types.TIME 		:  return TypeId.TIME_NAME;
		case Types.TIMESTAMP 	:  return TypeId.TIMESTAMP_NAME;

		case Types.BINARY			:  return TypeId.BINARY_NAME;
		case Types.VARBINARY	 	:  return TypeId.VARBINARY_NAME;
		case Types.LONGVARBINARY 	:  return TypeId.LONGVARBINARY_NAME;
           case Types.BLOB             :  return TypeId.BLOB_NAME;

		case Types.OTHER		:  return "OTHER";
		case Types.JAVA_OBJECT	:  return "Types.JAVA_OBJECT";
		case Types.REF : return TypeId.REF_NAME;
		case JDBC40Translation.ROWID: return TypeId.ROWID_NAME;
		case Types.STRUCT: return TypeId.STRUCT_NAME;
		case StoredFormatIds.XML_TYPE_ID :  return TypeId.XML_NAME;
		case JDBC40Translation.SQLXML: return TypeId.SQLXML_NAME;
		default : return String.valueOf(jdbcType);
	}
}