/** * Initializes a layout builder with no reference layout. * * @param schemaTable Table to resolve Avro schemas. * @throws IOException on I/O error. */ public TableLayoutBuilder(FijiSchemaTable schemaTable) throws IOException { mSchemaTable = schemaTable; mSchemaResolver = new SchemaTableAvroResolver(schemaTable); mDescBuilder = null; }
/** * Sets the Schema table used to resolve Avro schemas. * * <p> Also sets the Avro schema resolver. </p> * * @param schemaTable Schema table to resolve Avro schemas. * @return this CellSpec. */ public CellSpec setSchemaTable(final FijiSchemaTable schemaTable) { mSchemaTable = schemaTable; mAvroSchemaResolver = new SchemaTableAvroResolver(mSchemaTable); return this; }
/** * Compares two AvroSchema objects for equality within the context of the given SchemaTable. * * @param schemaTable SchemaTable with which to resolve schema UIDs. * @param first one AvroSchema object to compare for equality. * @param second another AvroSchema object to compare for equality. * @return whether the two objects represent the same Schema. * @throws IOException in case of an error reading from the SchemaTable. */ public static boolean avroSchemaEquals( final FijiSchemaTable schemaTable, final AvroSchema first, final AvroSchema second ) throws IOException { final AvroSchemaResolver resolver = new SchemaTableAvroResolver(schemaTable); return Objects.equal(resolver.apply(first), resolver.apply(second)); }
/** * 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)); }
/** * Get the Avro Schema for a given column marked FINAL in a given layout. This will either be * defined INLINE as a Schema JSON or it will be the only writer schema in the layout 1.3+ * Avro writers field. * * @param layout table layout from which to get the Schema for the given column. * @param column column for which to get the Schema. * @return Avro Schema of the given column. * @throws NoSuchColumnException in case the column does not exist. */ private static Schema getSchemaForFinalColumn(FijiTableLayout layout, FijiColumnName column) throws NoSuchColumnException { final List<AvroSchema> writers = layout.getCellSchema(column).getWriters(); if (null == writers) { return new Schema.Parser().parse(layout.getCellSchema(column).getValue()); } else { Preconditions.checkState(writers.size() == 1, "FINAL columns must have exactly one writer schema, found: " + writers); return new SchemaTableAvroResolver(layout.getSchemaTable()).apply(writers.get(0)); } }
final AvroSchemaResolver resolver = new SchemaTableAvroResolver(mFiji.getSchemaTable());
/** * Get the Avro Schema to use to decode cells. * * @param layout FijiTableLayout from which to get storage information. * @param spec Specification of the cell encoding. * @return the Avro Schema to use to decode cells. * @throws IOException in case the specified column does not exist. */ private static Schema getReaderSchema(FijiTableLayout layout, BoundColumnReaderSpec spec) throws IOException { switch (spec.getColumnReaderSpec().getAvroReaderSchemaType()) { case DEFAULT: { final CellSchema cellSchema = layout.getCellSchema(spec.getColumn()); final SchemaTableAvroResolver resolver = new SchemaTableAvroResolver(layout.getSchemaTable()); return resolver.apply(cellSchema.getDefaultReader()); } case EXPLICIT: return spec.getColumnReaderSpec().getAvroReaderSchema(); case WRITER: return null; default: throw new InternalFijiError( "Unknown AvroReaderSchemaType: " + spec.getColumnReaderSpec().getAvroReaderSchemaType()); } }
mSchemaResolver = new SchemaTableAvroResolver(mSchemaTable); mDescBuilder = TableLayoutDesc.newBuilder(tableLayoutDesc) .setReferenceLayout(tableLayoutDesc.getLayoutId())