/** * Get this cell's encoding type. * * @return this cell's encoding type. */ public CellType getType() { if (mDecodedCell.getWriterSchema() == null) { return CellType.COUNTER; } else { return CellType.AVRO; } }
/** * Get the Avro Schema used to encode this cell, or null for non-Avro values. * * @return the Avro Schema used to encode this cell, or null for non-Avro values. */ public Schema getWriterSchema() { return mDecodedCell.getWriterSchema(); }
/** {@inheritDoc} */ @Override public int hashCode() { return Objects.hashCode(getWriterSchema(), getData()); }
/** * Rewrites a cell. * * <p> * This method is meant to be overloaded in case custom cell rewriting rules are necessary. * </p> * * @param cell Original value of the cell. * @return the new rewritten value of the cell, * or the original cell value if no translation rules apply. * @throws IOException on I/O error. * * @param <U> type of the input cell to rewrite. * @param <T> type to rewrite the input cell into. */ protected <T, U> DecodedCell<T> rewriteCell(final DecodedCell<U> cell) throws IOException { // Apply conversion rules as long as some rule matches: DecodedCell<U> rewritten = cell; while (true) { final Schema newSchema = mRules.get(rewritten.getWriterSchema()); if (newSchema == null) { // No rule apply, we are done. break; } else { rewritten = convertAvro(rewritten, newSchema); } } return (DecodedCell<T>) rewritten; }
/** * Determines whether the data contained in this DecodedCell is equivalent to another. The * data is equivalent if they have the same schema and the same data, regardless of location. * * @param obj The object to compare. * @return Whether this contains the same data as the other DecodedCell. */ @Override public boolean equals(Object obj) { if (!(obj instanceof DecodedCell<?>)) { return false; } final DecodedCell<?> other = (DecodedCell<?>) obj; if (!Objects.equal(this.getWriterSchema(), other.getWriterSchema())) { return false; } if (!Objects.equal(this.getReaderSchema(), other.getReaderSchema())) { return false; } Object data = getData(); Object otherData = other.getData(); // UTF8 strings don't compare well with other CharSequences: if ((data instanceof Utf8) ^ (otherData instanceof Utf8)) { data = data.toString(); otherData = otherData.toString(); } return data.equals(otherData); }
final DatumWriter<U> writer = new GenericDatumWriter<U>(original.getWriterSchema()); writer.write(original.getData(), encoder); encoder.flush(); new GenericDatumReader<T>(original.getWriterSchema(), schema); final T data = reader.read(null, decoder);
/** {@inheritDoc} */ @Override protected JsonNode toJsonNode() { final ObjectNode root = JsonNodeFactory.instance.objectNode(); root.put(FAMILY_NODE, mFamily); root.put(QUALIFIER_NODE, mQualifier); final ObjectNode value = root.with(VALUE_NODE); // Schema's documentation for toString says it is rendered as JSON. value.put(SCHEMA_NODE, mValue.getWriterSchema().toString()); try { value.put(DATA_NODE, ToJson.toAvroJsonString(mValue.getData(), mValue.getWriterSchema())); } catch (IOException ioe) { throw new FijiIOException(ioe); } return root; }