break; case DataType.CHARARRAY: tuple.set(i, DataType.toString(object)); break; case DataType.DOUBLE:
/** * Force a data object to a String, if possible. Any simple (atomic) type * can be forced to a String including ByteArray. Complex types cannot be * forced to a String. This isn't particularly efficient, so if you * already <b>know</b> that the object you have is a String you * should just cast it. Unlike {@link #toString(Object, byte)} this * method will first determine the type of o and then do the cast. * Use {@link #toString(Object, byte)} if you already know the type. * @param o object to cast * @return The object as a String. * @throws ExecException if the type can't be forced to a String. */ public static String toString(Object o) throws ExecException { return toString(o, findType(o)); }
public DateTime exec(Tuple input) throws IOException { if (input == null || input.size() < 1 || input.get(0) == null) { return null; } DateTimeFormatter dtf = DateTimeFormat.forPattern(DataType .toString(input.get(1))); DateTimeZone dtz = DateTimeZone.forOffsetMillis(DateTimeZone.forID( DataType.toString(input.get(2))).getOffset(null)); return dtf.withZone(dtz).parseDateTime(DataType.toString(input.get(0))); }
public DateTime exec(Tuple input) throws IOException { if (input == null || input.size() < 1 || input.get(0) == null) { return null; } String dtStr = DataType.toString(input.get(0)); //DateTimeZone dtz = extractDateTimeZone(dtStr); //The timezone in the customized format is not predictable DateTimeFormatter dtf = DateTimeFormat.forPattern(DataType .toString(input.get(1))); //if (dtz == null) { return dtf.parseDateTime(dtStr); //} else { // return dtf.withZone(dtz).parseDateTime(dtStr); //} }
public DateTime exec(Tuple input) throws IOException { if (input == null || input.size() < 1 || input.get(0) == null) { return null; } String dtStr = DataType.toString(input.get(0)); return ToDate.extractDateTime(dtStr); }
/** * Write a tuple to the data store. * * @param t the tuple to store. * @throws java.io.IOException if an exception occurs during the write */ @Override public void putNext(Tuple t) throws IOException { try { Classifier r; try { DataInputStream in = new DataInputStream(new ByteArrayInputStream(((DataByteArray) t.get(1)).get())); r = PolymorphicWritable.read(in, Classifier.class); in.close(); } catch (IOException e) { throw new ImpossibleStateError("Can't have error in BAIS", e); } //noinspection unchecked output.write(new Text(DataType.toString(t.get(0))), r); } catch (InterruptedException e) { throw new ImpossibleStateError("Interrupted operation ... don't know what to do", e); } } }
public String exec(Tuple input) throws IOException { if (input == null || input.size() < 1 || input.get(0) == null) { return null; } if (input.size() == 1) { return DataType.toDateTime(input.get(0)).toString(); } else if (input.size() == 2) { DateTimeFormatter dtf = DateTimeFormat.forPattern(DataType.toString(input.get(1))); return DataType.toDateTime(input.get(0)).toString(dtf); } else { return null; } }
private TypedObject getTypedObject(Object data, FieldDetail detail) throws ExecException { if (data == null) { return null; } byte type = detail.type; switch (type) { case DataType.BOOLEAN: return TypeSystem.asTypedObject(DataType.toBoolean(data, type)); case DataType.INTEGER: case DataType.LONG: return TypeSystem.asTypedObject(DataType.toLong(data, type)); case DataType.FLOAT: case DataType.DOUBLE: return TypeSystem.asTypedObject(DataType.toDouble(data, type)); case DataType.DATETIME: return TypeSystem.asTypedObject(new Timestamp(DataType.toDateTime(data, type).getMillis())); case DataType.BYTE: case DataType.BYTEARRAY: case DataType.CHARARRAY: return TypeSystem.asTypedObject(DataType.toString(data, type)); case DataType.BIGINTEGER: case DataType.BIGDECIMAL: return TypeSystem.asTypedObject(DataType.toBigDecimal(data, type)); default: //TUPLE, BAG, MAP, INTERNALMAP, GENERIC_WRITABLECOMPARABLE, ERROR, UNKNOWN, NULL and anything else return null; } }
break; case DataType.CHARARRAY: tuple.set(i, DataType.toString(object)); break; case DataType.DOUBLE: