private Result write(Object object, ResourceFieldSchema field, Generator generator) { byte type = (field != null ? field.getType() : DataType.findType(object));
/** * Get the type name. * @param o Object to test. * @return type name, as a String. */ public static String findTypeName(Object o) { return findTypeName(findType(o)); }
public void write(PreparedStatement statement, List<ColumnInfo> columnMetadataList) throws SQLException { for (int i = 0; i < columnMetadataList.size(); i++) { Object o = values.get(i); byte type = (fieldSchemas == null) ? DataType.findType(o) : fieldSchemas[i].getType(); Object upsertValue = convertTypeSpecificValue(o, type, columnMetadataList.get(i).getSqlType()); if (upsertValue != null) { statement.setObject(i + 1, upsertValue, columnMetadataList.get(i).getSqlType()); } else { statement.setNull(i + 1, columnMetadataList.get(i).getSqlType()); } } statement.execute(); }
try { o = castBytes(o, targetPhoenixType); inferredPType = getType(o, DataType.findType(o)); } catch (IOException e) { throw new RuntimeException("Error while casting bytes for object " +o);
o = castBytes(o, targetPhoenixType); if (targetPhoenixType != PVarbinary.INSTANCE && targetPhoenixType != PBinary.INSTANCE) { inferredPType = getType(o, DataType.findType(o));
@Override public void putNext(Tuple t) throws IOException { ResourceFieldSchema[] fieldSchemas = (schema == null) ? null : schema.getFields(); PhoenixRecordWritable record = new PhoenixRecordWritable(this.columnInfo); try { for(int i=0; i<t.size(); i++) { Object value = t.get(i); if(value == null) { record.add(null); continue; } ColumnInfo cinfo = this.columnInfo.get(i); byte type = (fieldSchemas == null) ? DataType.findType(value) : fieldSchemas[i].getType(); PDataType pDataType = PDataType.fromTypeId(cinfo.getSqlType()); Object v = TypeUtil.castPigTypeToPhoenix(value, type, pDataType); record.add(v); } this.writer.write(null, record); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException(e); } catch (SQLException e) { LOG.error("Error on tuple {} .",t); throw new IOException(e); } }
assertEquals(DataType.LONG, DataType.findType(t.get(2))); assertEquals(DataType.TUPLE, DataType.findType(t.get(4))); Tuple doubleArrayTuple = (Tuple)t.get(4); assertEquals(2,doubleArrayTuple.size()); assertEquals(DataType.BIGDECIMAL, DataType.findType(t.get(0))); assertEquals(DataType.BIGINTEGER, DataType.findType(t.get(1)));
@Override public void writeDatum(DataOutput out, Object val) throws IOException { // Read the data type byte type = DataType.findType(val); writeDatum(out, val, type); }
/** * Determine whether the this data type is atomic. * @param o Object to determine type of. * @return true if dataType is bytearray, chararray, integer, long, * float, or boolean. */ public static boolean isAtomic(Object o) { return isAtomic(findType(o)); }
/** * Determine whether the object is complex or atomic. * @param o Object to determine type of. * @return true if dataType is bag, tuple, or map. */ public static boolean isComplex(Object o) { return isComplex(findType(o)); }
protected byte schemaToType(Object o, int i, ResourceFieldSchema[] fieldSchemas) { return (fieldSchemas == null) ? DataType.findType(o) : fieldSchemas[i] .getType(); }
protected byte schemaToType(Object o, ResourceFieldSchema fieldSchema) { return (fieldSchema == null) ? DataType.findType(o) : fieldSchema .getType(); }
/** * {@inheritDoc} */ @Override public byte getType(int fieldNum) throws ExecException { return DataType.findType(get(fieldNum)); }
/** * Determine whether the this object can have a schema. * @param o Object to determine if it has a schema * @return true if the type can have a valid schema (i.e., bag or tuple) */ public static boolean isSchemaType(Object o) { return isSchemaType(findType(o)); }
public static byte[] toBytes(Object o) throws ExecException { return toBytes(o, findType(o)); }
public static DateTime toDateTime(Object o) throws ExecException { return toDateTime(o, findType(o)); }
public static BigInteger toBigInteger(Object o) throws ExecException { return toBigInteger(o, findType(o)); }
Object GetUnequalValue(Object v) { byte type = DataType.findType(v); if (type == DataType.BAG || type == DataType.TUPLE || type == DataType.MAP) return null; Object zero = generateData(type, "0"); if (v.equals(zero)) return generateData(type, "1"); return zero; }
@Override public Schema outputSchema(Schema input) { if (invoker_ == null) return null; FieldSchema fs = new FieldSchema(null, DataType.findType(invoker_.getReturnType())); return new Schema(fs); } }
@Override public Schema outputSchema(Schema input) { if (invoker_ == null) return null; FieldSchema fs = new FieldSchema(null, DataType.findType(invoker_.getReturnType())); return new Schema(fs); } }