public static Object getObjectFromString ( VoltType type , String value ) throws ParseException { Object ret = null ; switch ( type ) { // NOTE: All runtime integer parameters are actually Longs,so we will have problems // if we actually try to convert the object to one of the smaller numeric sizes // -------------------------------- // INTEGERS // -------------------------------- case TINYINT : //ret = Byte.valueOf(value); //break; case SMALLINT : //ret = Short.valueOf(value); //break; case INTEGER : //ret = Integer.valueOf(value); //break; case BIGINT : ret = Long . valueOf ( value ) ; break ; // -------------------------------- // FLOATS // -------------------------------- case FLOAT : ret = Double . valueOf ( value ) ; break ; // -------------------------------- // STRINGS // -------------------------------- case STRING : ret = value ; break ; case DECIMAL : case VARBINARY : if ( value != null ) { throw new RuntimeException ( "Only NULL default values for DECIMAL " + "and VARBINARY columns are supported right now" ) ; } break ; // -------------------------------- // TIMESTAMP // -------------------------------- case TIMESTAMP : { // Support either long values (microseconds since epoch) or timestamp strings. try { // Try to parse it as a long first. ret = new TimestampType ( Long . parseLong ( value ) ) ; } catch ( NumberFormatException e ) { // It failed to parse as a long - parse it as a timestamp string. Date date = new SimpleDateFormat ( "EEE MMM dd HH:mm:ss zzz yyyy" ) . parse ( value ) ; ret = new TimestampType ( date . getTime ( ) * 1000 ) ; } break ; } // -------------------------------- // INVALID // -------------------------------- default : LOG . severe ( "ERROR: Unable to get object from string for invalid ValueType '" + type + "'" ) ; } return ( ret ) ; }
Returns a casted object of the input value string based on the given type