/** * Initializes a new RawBytesCellDecoder. * * @param cellSpec Specification of the cell encoding. */ public RawBytesCellDecoder(CellSpec cellSpec) { Preconditions.checkNotNull(cellSpec); Preconditions.checkArgument( cellSpec.getCellSchema().getType() == SchemaType.RAW_BYTES); }
/** * Initializes a new RawBytesCellEncoder. * * @param cellSpec Specification of the cell to encode. * @throws IOException on I/O error. */ public RawBytesCellEncoder(final CellSpec cellSpec) throws IOException { mCellSpec = Preconditions.checkNotNull(cellSpec); Preconditions.checkArgument(cellSpec.getCellSchema().getType() == SchemaType.RAW_BYTES); }
/** * Initializes a ProtobufCellDecoder. * * @param cellSpec Specification of the cell encoding. * @throws IOException on I/O error. */ public ProtobufCellDecoder(CellSpec cellSpec) throws IOException { Preconditions.checkNotNull(cellSpec); Preconditions.checkArgument( cellSpec.getCellSchema().getType() == SchemaType.PROTOBUF); final String className = cellSpec.getCellSchema().getProtobufClassName(); try { mProtoClass = Class.forName(className).asSubclass(AbstractMessageLite.class); } catch (ClassNotFoundException cnfe) { throw new IOException(cnfe); } try { mParseFromMethod = mProtoClass.getMethod("parseFrom", byte[].class); } catch (NoSuchMethodException nsme) { throw new IOException(nsme); } }
/** * Gets the registered writer schemas associated with the provided cell specification. * * @param spec containing registered schemas. * @return the set of writer schemas registered for the provided cell. * Null if validation is disabled. * @throws IOException if there is an error looking up schemas. */ private static Set<Schema> getRegisteredWriters(final CellSpec spec) throws IOException { final List<AvroSchema> writerSchemas = spec.getCellSchema().getWriters(); if (writerSchemas == null) { return null; } final AvroSchemaResolver resolver = new SchemaTableAvroResolver(spec.getSchemaTable()); return Sets.newHashSet(Collections2.transform(writerSchemas, resolver)); }
Preconditions.checkArgument(cellSpec.getCellSchema().getType() == SchemaType.PROTOBUF); mProtobufFullName = cellSpec.getCellSchema().getProtobufFullName(); Preconditions.checkNotNull(mProtobufFullName); final String className = cellSpec.getCellSchema().getProtobufClassName(); Class<?> protoClass = null; try {
/** * Creates a schema encoder for the specified cell encoding. * * @param cellSpec Specification of the cell to encode. * @return a schema encoder for the specified cell encoding. * @throws IOException on I/O error. */ private SchemaEncoder createSchemaEncoder(final CellSpec cellSpec) throws IOException { switch (cellSpec.getCellSchema().getStorage()) { case HASH: return new SchemaHashEncoder(); case UID: return new SchemaIdEncoder(); case FINAL: return new FinalSchemaEncoder(); default: throw new RuntimeException( "Unexpected cell format: " + cellSpec.getCellSchema().getStorage()); } }
/** * Reports the Avro schema validation policy. * * @param cellSpec to get the Avro schema validation policy from. * @return the schema validation policy. */ private static AvroValidationPolicy getAvroValidationPolicy(final CellSpec cellSpec) { final String validationPolicy = System.getProperty(SCHEMA_VALIDATION_POLICY); if (validationPolicy != null) { try { return AvroValidationPolicy.valueOf(validationPolicy); } catch (IllegalArgumentException iae) { throw new FijiEncodingException( String.format("Unrecognized validation policy: %s", validationPolicy), iae); } } else { return cellSpec.getCellSchema().getAvroValidationPolicy(); } }
/** {@inheritDoc} */ @Override public FijiCellEncoder create(final CellSpec cellSpec) throws IOException { Preconditions.checkNotNull(cellSpec); switch (cellSpec.getCellSchema().getType()) { case INLINE: case AVRO: case CLASS: return new AvroCellEncoder(cellSpec); case COUNTER: return CounterCellEncoder.get(); case PROTOBUF: return new ProtobufCellEncoder(cellSpec); case RAW_BYTES: return new RawBytesCellEncoder(cellSpec); default: throw new RuntimeException("Unhandled cell encoding: " + cellSpec.getCellSchema().getType()); } } }
/** {@inheritDoc} */ @Override public <T> FijiCellDecoder<T> create(CellSpec cellSpec) throws IOException { Preconditions.checkNotNull(cellSpec); switch (cellSpec.getCellSchema().getType()) { case AVRO: case CLASS: case INLINE: return new GenericCellDecoder<T>(cellSpec); case RAW_BYTES: return new RawBytesCellDecoder(cellSpec); case PROTOBUF: return new ProtobufCellDecoder<T>(cellSpec); case COUNTER: // purposefully forget the type (long) param of cell decoders for counters. @SuppressWarnings("unchecked") final FijiCellDecoder<T> counterCellDecoder = (FijiCellDecoder<T>) CounterCellDecoder.get(); return counterCellDecoder; default: throw new InternalFijiError("Unhandled cell encoding: " + cellSpec.getCellSchema()); } }
/** {@inheritDoc} */ @Override public <T> FijiCellDecoder<T> create(CellSpec cellSpec) throws IOException { Preconditions.checkNotNull(cellSpec); switch (cellSpec.getCellSchema().getType()) { case AVRO: case CLASS: case INLINE: return new SpecificCellDecoder<T>(cellSpec); case PROTOBUF: return new ProtobufCellDecoder<T>(cellSpec); case RAW_BYTES: return new RawBytesCellDecoder(cellSpec); case COUNTER: // purposefully forget the type (long) param of cell decoders for counters. @SuppressWarnings("unchecked") final FijiCellDecoder<T> counterCellDecoder = (FijiCellDecoder<T>) CounterCellDecoder.get(); return counterCellDecoder; default: throw new InternalFijiError("Unhandled cell encoding: " + cellSpec.getCellSchema()); } }
/** * Creates a schema decoder. * * @param cellSpec Specification of the cell encoding. * @return a new schema decoder. * @throws IOException on I/O error. */ private static SchemaDecoder createSchemaDecoder(CellSpec cellSpec) throws IOException { switch (cellSpec.getCellSchema().getStorage()) { case HASH: return new SchemaHashDecoder(cellSpec.getSchemaTable()); case UID: return new SchemaIdDecoder(cellSpec.getSchemaTable()); case FINAL: return new FinalSchemaDecoder(cellSpec.getAvroSchema()); default: throw new InternalFijiError( "Unexpected cell storage in cell schema: " + cellSpec.getCellSchema()); } }
if (mCellSpec.getCellSchema().getStorage() == SchemaStorage.FINAL && !writerSchema.equals(mReaderSchema)) { throw new FijiEncodingException(