/** * Convert the specified value with the desired floating point type. * * @param value the value to be converted; may not be null * @param schema the schema for the current value type; may not be null * @param error any previous error that should be included in an exception message; may be null * @return the double value after conversion; never null * @throws DataException if the value could not be converted to a double */ protected static double asDouble(Object value, Schema schema, Throwable error) { try { if (value instanceof Number) { Number number = (Number) value; return number.doubleValue(); } if (value instanceof String) { return new BigDecimal(value.toString()).doubleValue(); } } catch (NumberFormatException e) { error = e; // fall through } return asLong(value, schema, error); }
return asLong(value, fromSchema, null) == 0L ? Boolean.FALSE : Boolean.TRUE; case INT8: if (value instanceof Byte) { return value; return (byte) asLong(value, fromSchema, null); case INT16: if (value instanceof Short) { return value; return (short) asLong(value, fromSchema, null); case INT32: if (Date.LOGICAL_NAME.equals(toSchema.name())) { long numeric = asLong(value, fromSchema, null); return Date.toLogical(toSchema, (int) numeric); long numeric = asLong(value, fromSchema, null); return Time.toLogical(toSchema, (int) numeric); return (int) asLong(value, fromSchema, null); case INT64: if (Timestamp.LOGICAL_NAME.equals(toSchema.name())) { long numeric = asLong(value, fromSchema, null); return Timestamp.toLogical(toSchema, numeric); return asLong(value, fromSchema, null); case FLOAT32: