switch (type) { case BINARY: return ((DataByteArray) pigObj).get();
to.bytes(dba.get(), dba.size()); return;
break; case DataType.BYTEARRAY: generator.writeBinary(((DataByteArray) object).get()); break;
byte[] bytes = ((DataByteArray)o).get();
byte[] bytes = ((DataByteArray)o).get();
@Override public BytesWritable getPrimitiveWritableObject(Object o) { return o == null ? null : (o instanceof DataByteArray ? new BytesWritable(((DataByteArray) o).get()) : new BytesWritable((byte[]) o)); }
private static Object toStringType(Object value) { if (value instanceof String) { return value; } else if (value instanceof DataByteArray) { byte[] buf = ((DataByteArray)value).get(); // mostly there is no need to copy. return ByteBuffer.wrap(Arrays.copyOf(buf, buf.length)); } return null; }
/** * Append given byte array to the internal byte array. * @param b byte array who's contents to append. The contents of the byte array are * copied. */ public DataByteArray append(DataByteArray b) { byte[] ba = (b == null) ? null : b.get(); return append(ba, 0, ba == null ? 0 : ba.length); }
/** * For testing only, do not use directly. */ public void setFilter(DataByteArray dba) throws IOException { DataInputStream dis = new DataInputStream(new ByteArrayInputStream(dba.get())); filter = new BloomFilter(); filter.readFields(dis); }
public static BloomFilter bloomIn(DataByteArray b) throws IOException { DataInputStream dis = new DataInputStream(new ByteArrayInputStream(b.get())); BloomFilter f = new BloomFilter(); f.readFields(dis); return f; }
private DisambiguationAuthorOut readInputData(Tuple t, int dataIndex){ DisambiguationAuthorOut dco = null; try{ dco = DisambiguationAuthorOut.parseFrom(((DataByteArray)t.get(dataIndex)).get()); }catch(Exception e){ //this exception is handled in the method updateAuthorList(...) LOGGER.warn("this exception is handled in the method updateAuthorList(...)", e); } return dco; } }
@Override protected Writable toWritable(DataByteArray value) throws IOException { Preconditions.checkNotNull(writable, "Writable is null"); byte[] bytes = value.get(); ibuf.reset(bytes, bytes.length); writable.readFields(ibuf); return writable; } }
@Override public Tuple exec(Tuple input) throws ExecException { try { DataByteArray protoMetadata = (DataByteArray) input.get(0); Method parseFromMethod = protobufClass.getMethod("parseFrom", byte[].class); Message metadata = (Message) parseFromMethod.invoke(null, protoMetadata.get()); return ProtoBytearrayToTuple.messageToTuple(metadata); } catch (Exception ex) { throw new ExecException(ex); } }
@Override public Builder execute(Tuple t, int dataIndex, Builder dwb) throws IOException { DocumentSimilarityInfo dco = null; try{ dco = DocumentSimilarityInfo.parseFrom(((DataByteArray)t.get(dataIndex)).get()); }catch(Exception e){ LOGGER.warn("No document-similarity output for the document {}", t.get(0), e); return dwb; } return buildDocumentMetadata(dwb, dco); }
@Override public Builder execute(Tuple t, int dataIndex, Builder dwb) throws ExecException, InvalidProtocolBufferException { KeywordsList kl = null; try{ kl = KeywordsList.parseFrom(((DataByteArray)t.get(dataIndex)).get()); }catch(NullPointerException ex){ LOGGER.warn("No keyword output for the document {}", t.get(0), ex); return dwb; } return buildDocumentMetadata(dwb, kl); }
public DocumentWrapper.Builder mainBlockParsing(Tuple t) throws ExecException, InvalidProtocolBufferException{ docId = (String) t.get(2*mainGroupIndex); DataByteArray proto = (DataByteArray) t.get(2*mainGroupIndex+1); return DocumentWrapper.newBuilder(DocumentWrapper.parseFrom(proto.get())); } }
@Override public Tuple exec(Tuple input) throws IOException { if (input == null || input.size() < 1) return null; try { DataByteArray bytes = (DataByteArray) input.get(0); M value = thriftConverter.fromBytes(bytes.get()); return value == null ? null : thriftToPig.getPigTuple(value); } catch (IOException e) { return null; } }
@Override public void putNext(Tuple t) throws IOException { DataByteArray data = null; if (t == null || t.size() < 1 || (data = (DataByteArray) t.get(0)) == null) { // TODO(Andy Schlaikjer): Signal error return; } writable.set(data.get()); writeRecord(null, writable); } }
@Override public Tuple exec(Tuple input) throws IOException { DataByteArray dba = (DataByteArray) input.get(0); DocumentMetadata metadata = DocumentWrapper.parseFrom(dba.get()) .getDocumentMetadata(); Tuple output = TupleFactory.getInstance().newTuple( fieldNumberMap.size()); output = addDocumentMetatdataFields(metadata, output); return output; }
@Override public Tuple exec(Tuple tuple) throws IOException { DataByteArray dba = (DataByteArray) tuple.get(1); DocumentProtos.DocumentWrapper docWrapper = DocumentProtos.DocumentWrapper.parseFrom(dba.get()); String id = docWrapper.getDocumentMetadata().getKey(); String title = docWrapper.getDocumentMetadata().getBasicMetadata().getTitle(0).getText(); Tuple retTuple = TupleFactory.getInstance().newTuple(Arrays.asList(id, title)); return retTuple; } }