sb.append(((ByteObjectInspector) poi).get(o)); break; sb.append(((IntObjectInspector) poi).get(o)); break; sb.append(((LongObjectInspector) poi).get(o)); break; sb.append(((FloatObjectInspector) poi).get(o)); break; sb.append(((DoubleObjectInspector) poi).get(o)); break; byte[] b = ((BinaryObjectInspector) oi).getPrimitiveJavaObject(o); Text txt = new Text(); txt.set(b, 0, b.length); ((HiveCharObjectInspector) poi).getPrimitiveJavaObject(o).toString()); appendWithQuotes(sb, s); break; throw new RuntimeException("Unknown primitive type: " + poi.getPrimitiveCategory());
case CHAR: if (inputOI.preferWritable()) { t.set(((HiveCharObjectInspector) inputOI).getPrimitiveWritableObject(input) .getStrippedValue()); } else { t.set(((HiveCharObjectInspector) inputOI).getPrimitiveJavaObject(input).getStrippedValue()); t.set(((HiveVarcharObjectInspector) inputOI).getPrimitiveWritableObject(input) .toString()); } else { t.set(((HiveVarcharObjectInspector) inputOI).getPrimitiveJavaObject(input).toString()); case BINARY: BinaryObjectInspector binaryOI = (BinaryObjectInspector) inputOI; if (binaryOI.preferWritable()) { BytesWritable bytes = binaryOI.getPrimitiveWritableObject(input); t.set(bytes.getBytes(), 0, bytes.getLength()); } else { t.set(binaryOI.getPrimitiveJavaObject(input));
int v1 = ((ByteObjectInspector) poi1).get(o1); int v2 = ((ByteObjectInspector) poi2).get(o2); return v1 - v2; int v1 = ((IntObjectInspector) poi1).get(o1); int v2 = ((IntObjectInspector) poi2).get(o2); return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0); long v1 = ((LongObjectInspector) poi1).get(o1); long v2 = ((LongObjectInspector) poi2).get(o2); return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0); float v1 = ((FloatObjectInspector) poi1).get(o1); float v2 = ((FloatObjectInspector) poi2).get(o2); double v1 = ((DoubleObjectInspector) poi1).get(o1); double v2 = ((DoubleObjectInspector) poi2).get(o2); HiveCharWritable t1 = ((HiveCharObjectInspector)poi1).getPrimitiveWritableObject(o1); HiveCharWritable t2 = ((HiveCharObjectInspector)poi2).getPrimitiveWritableObject(o2); return t1.compareTo(t2); BytesWritable bw1 = ((BinaryObjectInspector) poi1).getPrimitiveWritableObject(o1); BytesWritable bw2 = ((BinaryObjectInspector) poi2).getPrimitiveWritableObject(o2); return bw1.compareTo(bw2);
return null; } else if (inspector instanceof HiveVarcharObjectInspector) { if (((HiveVarcharObjectInspector) inspector).preferWritable()) { return ((HiveVarcharObjectInspector) inspector).getPrimitiveWritableObject(hiveObj) .getHiveVarchar().getValue(); } else { return ((HiveVarcharObjectInspector) inspector).getPrimitiveJavaObject(hiveObj) .getValue(); if (((HiveCharObjectInspector) inspector).preferWritable()) { return ((HiveCharObjectInspector) inspector).getPrimitiveWritableObject(hiveObj) .getHiveChar().getValue(); } else { return ((HiveCharObjectInspector) inspector).getPrimitiveJavaObject(hiveObj) .getValue(); if (((BinaryObjectInspector) inspector).preferWritable()) { return ((BinaryObjectInspector) inspector).getPrimitiveWritableObject(hiveObj).getBytes(); } else { return ((BinaryObjectInspector) inspector).getPrimitiveJavaObject(hiveObj); return ((PrimitiveObjectInspector) inspector).getPrimitiveJavaObject(hiveObj); } else if (inspector instanceof StructObjectInspector) {
public static BytesWritable getBinary(Object o, PrimitiveObjectInspector oi) { if (null == o) { return null; } switch (oi.getPrimitiveCategory()) { case VOID: return null; case STRING: Text text = ((StringObjectInspector) oi).getPrimitiveWritableObject(o); return getBinaryFromText(text); case CHAR: // char to binary conversion: include trailing spaces? return getBinaryFromText( ((HiveCharObjectInspector) oi).getPrimitiveWritableObject(o).getPaddedValue()); case VARCHAR: return getBinaryFromText( ((HiveVarcharObjectInspector) oi).getPrimitiveWritableObject(o).getTextValue()); case BINARY: return ((BinaryObjectInspector) oi).getPrimitiveWritableObject(o); default: throw new RuntimeException("Cannot convert to Binary from: " + oi.getTypeName()); } }
private static void unpackDoubleStats(ObjectInspector oi, Object o, String fName, ColumnStatisticsObj statsObj) throws UnsupportedDoubleException { if (fName.equals("countnulls")) { long v = ((LongObjectInspector) oi).get(o); statsObj.getStatsData().getDoubleStats().setNumNulls(v); } else if (fName.equals("numdistinctvalues")) { long v = ((LongObjectInspector) oi).get(o); statsObj.getStatsData().getDoubleStats().setNumDVs(v); } else if (fName.equals("max")) { double d = ((DoubleObjectInspector) oi).get(o); if (Double.isInfinite(d) || Double.isNaN(d)) { throw new UnsupportedDoubleException(); } statsObj.getStatsData().getDoubleStats().setHighValue(d); } else if (fName.equals("min")) { double d = ((DoubleObjectInspector) oi).get(o); if (Double.isInfinite(d) || Double.isNaN(d)) { throw new UnsupportedDoubleException(); } statsObj.getStatsData().getDoubleStats().setLowValue(d); } else if (fName.equals("ndvbitvector")) { PrimitiveObjectInspector poi = (PrimitiveObjectInspector) oi; byte[] buf = ((BinaryObjectInspector) poi).getPrimitiveJavaObject(o); statsObj.getStatsData().getDoubleStats().setBitVectors(buf); ; } }
private static void unpackLongStats(ObjectInspector oi, Object o, String fName, ColumnStatisticsObj statsObj) { if (fName.equals("countnulls")) { long v = ((LongObjectInspector) oi).get(o); statsObj.getStatsData().getLongStats().setNumNulls(v); } else if (fName.equals("numdistinctvalues")) { long v = ((LongObjectInspector) oi).get(o); statsObj.getStatsData().getLongStats().setNumDVs(v); } else if (fName.equals("max")) { long v = ((LongObjectInspector) oi).get(o); statsObj.getStatsData().getLongStats().setHighValue(v); } else if (fName.equals("min")) { long v = ((LongObjectInspector) oi).get(o); statsObj.getStatsData().getLongStats().setLowValue(v); } else if (fName.equals("ndvbitvector")) { PrimitiveObjectInspector poi = (PrimitiveObjectInspector) oi; byte[] buf = ((BinaryObjectInspector) poi).getPrimitiveJavaObject(o); statsObj.getStatsData().getLongStats().setBitVectors(buf); ; } }
case PRIMITIVE: PrimitiveObjectInspector oi = (PrimitiveObjectInspector) objInspector; if (oi.getPrimitiveCategory() == PrimitiveCategory.BINARY) { BytesWritable bw = ((BinaryObjectInspector) oi).getPrimitiveWritableObject(obj); byte[] toWrite = new byte[bw.getLength()]; System.arraycopy(bw.getBytes(), 0, toWrite, 0, bw.getLength());
/** * @param obj * @param objInsp * @return */ private String getByteString(Object obj, PrimitiveObjectInspector objInsp) { switch (objInsp.getPrimitiveCategory()) { case STRING: StringObjectInspector strInspector = (StringObjectInspector) objInsp; return strInspector.getPrimitiveJavaObject(obj); case BINARY: BinaryObjectInspector binInspector = (BinaryObjectInspector) objInsp; return new String(binInspector.getPrimitiveJavaObject(obj)); /// XXX TODO interpret other types, like ints or doubled default: return null; } }
@Override public void write(Object value) { byte[] vBinary = inspector.getPrimitiveJavaObject(value); recordConsumer.addBinary(Binary.fromByteArray(vBinary)); } }
@Override void serialize(RandomAccessOutput byteStream, Object obj, ObjectInspector objInspector, boolean skipLengthPrefix, BooleanRef warnedOnceNullMapKey) { BinaryObjectInspector baoi = (BinaryObjectInspector) objInspector; BytesWritable bw = baoi.getPrimitiveWritableObject(obj); int length = bw.getLength(); if(!skipLengthPrefix){ LazyBinaryUtils.writeVInt(byteStream, length); } else { if (length == 0){ throw new RuntimeException("LazyBinaryColumnarSerde cannot serialize a non-null zero " + "length binary field. Consider using either LazyBinarySerde or ColumnarSerde."); } } byteStream.write(bw.getBytes(),0,length); } }
byte bt = ((ByteObjectInspector) oi).get(o); dos.writeByte(bt); break; int i = ((IntObjectInspector) oi).get(o); dos.writeInt(i); break; long l = ((LongObjectInspector) oi).get(o); dos.writeLong(l); break; float f = ((FloatObjectInspector) oi).get(o); dos.writeFloat(f); break; double d = ((DoubleObjectInspector) oi).get(o); dos.writeDouble(d); break; BytesWritable bw = ((BinaryObjectInspector) oi).getPrimitiveWritableObject(o); out.write(bw.getBytes(), 0, bw.getLength()); break;
public static BytesWritable getBinary(Object o, PrimitiveObjectInspector oi) { if (null == o) { return null; } switch (oi.getPrimitiveCategory()) { case VOID: return null; case STRING: Text text = ((StringObjectInspector) oi).getPrimitiveWritableObject(o); return getBinaryFromText(text); case CHAR: // char to binary conversion: include trailing spaces? return getBinaryFromText( ((HiveCharObjectInspector) oi).getPrimitiveWritableObject(o).getPaddedValue()); case VARCHAR: return getBinaryFromText( ((HiveVarcharObjectInspector) oi).getPrimitiveWritableObject(o).getTextValue()); case BINARY: return ((BinaryObjectInspector) oi).getPrimitiveWritableObject(o); default: throw new RuntimeException("Cannot convert to Binary from: " + oi.getTypeName()); } }
private static void unpackStringStats(ObjectInspector oi, Object o, String fName, ColumnStatisticsObj statsObj) { if (fName.equals("countnulls")) { long v = ((LongObjectInspector) oi).get(o); statsObj.getStatsData().getStringStats().setNumNulls(v); } else if (fName.equals("numdistinctvalues")) { long v = ((LongObjectInspector) oi).get(o); statsObj.getStatsData().getStringStats().setNumDVs(v); } else if (fName.equals("avglength")) { double d = ((DoubleObjectInspector) oi).get(o); statsObj.getStatsData().getStringStats().setAvgColLen(d); } else if (fName.equals("maxlength")) { long v = ((LongObjectInspector) oi).get(o); statsObj.getStatsData().getStringStats().setMaxColLen(v); } else if (fName.equals("ndvbitvector")) { PrimitiveObjectInspector poi = (PrimitiveObjectInspector) oi; byte[] buf = ((BinaryObjectInspector) poi).getPrimitiveJavaObject(o); statsObj.getStatsData().getStringStats().setBitVectors(buf); ; } }
if (myagg.maxLength < maxLengthFieldOI.get(partialValue)) { myagg.maxLength = maxLengthFieldOI.get(partialValue); myagg.sumLength += sumLengthFieldOI.get(partialValue); byte[] buf = ndvFieldOI.getPrimitiveJavaObject(partialValue);
@Override public void write(Object value) { byte[] vBinary = inspector.getPrimitiveJavaObject(value); recordConsumer.addBinary(Binary.fromByteArray(vBinary)); } }
public Object binaryEvaluate(DeferredObject[] arguments) throws HiveException { int len = 0; for (int idx = 0; idx < arguments.length; ++idx) { bw[idx] = ((BinaryObjectInspector)argumentOIs[idx]) .getPrimitiveWritableObject(arguments[idx].get()); if (bw[idx] == null){ return null; } len += bw[idx].getLength(); } byte[] out = new byte[len]; int curLen = 0; // Need to iterate twice since BytesWritable doesn't support append. for (BytesWritable bytes : bw){ System.arraycopy(bytes.getBytes(), 0, out, curLen, bytes.getLength()); curLen += bytes.getLength(); } return new BytesWritable(out); }
sb.append(((ByteObjectInspector) poi).get(o)); break; sb.append(((IntObjectInspector) poi).get(o)); break; sb.append(((LongObjectInspector) poi).get(o)); break; sb.append(((FloatObjectInspector) poi).get(o)); break; sb.append(((DoubleObjectInspector) poi).get(o)); break; sb.append('"'); sb.append(escapeString(((HiveCharObjectInspector) poi) .getPrimitiveJavaObject(o).toString())); sb.append('"'); break; BytesWritable bw = ((BinaryObjectInspector) oi).getPrimitiveWritableObject(o); Text txt = new Text(); txt.set(bw.getBytes(), 0, bw.getLength()); + poi.getPrimitiveCategory());
case CHAR: if (inputOI.preferWritable()) { t.set(((HiveCharObjectInspector) inputOI).getPrimitiveWritableObject(input) .getStrippedValue()); } else { t.set(((HiveCharObjectInspector) inputOI).getPrimitiveJavaObject(input).getStrippedValue()); t.set(((HiveVarcharObjectInspector) inputOI).getPrimitiveWritableObject(input) .toString()); } else { t.set(((HiveVarcharObjectInspector) inputOI).getPrimitiveJavaObject(input).toString()); case BINARY: BinaryObjectInspector binaryOI = (BinaryObjectInspector) inputOI; if (binaryOI.preferWritable()) { BytesWritable bytes = binaryOI.getPrimitiveWritableObject(input); t.set(bytes.getBytes(), 0, bytes.getLength()); } else { t.set(binaryOI.getPrimitiveJavaObject(input));
public static BytesWritable getBinary(Object o, PrimitiveObjectInspector oi) { if (null == o) { return null; } switch (oi.getPrimitiveCategory()) { case VOID: return null; case STRING: Text text = ((StringObjectInspector) oi).getPrimitiveWritableObject(o); return getBinaryFromText(text); case CHAR: // char to binary conversion: include trailing spaces? return getBinaryFromText( ((HiveCharObjectInspector) oi).getPrimitiveWritableObject(o).getPaddedValue()); case VARCHAR: return getBinaryFromText( ((HiveVarcharObjectInspector) oi).getPrimitiveWritableObject(o).getTextValue()); case BINARY: return ((BinaryObjectInspector) oi).getPrimitiveWritableObject(o); default: throw new RuntimeException("Cannot convert to Binary from: " + oi.getTypeName()); } }