/** * Get the Avro validation policy for a given column. * * @param column the column for which to get the Avro validation policy. * @return the Avro validation policy for the given column. * @throws NoSuchColumnException in case the column does not exist. * @throws InvalidLayoutException in case a fully qualified column in a map family is specified. */ public AvroValidationPolicy getAvroValidationPolicy(final FijiColumnName column) throws NoSuchColumnException, InvalidLayoutException { return getColumnSchema(column).getAvroValidationPolicy(); }
/** * List (READER | WRITER | WRITTEN) schemas registered at a column. * * @param columnName whose schemas to list. * @param schemaRegistrationType of the schemas to list: (READER, WRITER, WRITTEN). * @return The list of schemas. * Returns empty list if schema validation was not previously enabled. * @throws IOException if the cellSchema of the column can not be acquired. */ public Collection<Schema> getRegisteredSchemas( final FijiColumnName columnName, final SchemaRegistrationType schemaRegistrationType) throws IOException { Preconditions.checkNotNull(columnName); Preconditions.checkNotNull(schemaRegistrationType); final List<AvroSchema> avroSchemas = getMutableRegisteredSchemaList(columnName, schemaRegistrationType); return Collections2.transform(avroSchemas, mSchemaResolver); }
/** * Lists the reader schemas registered for the specified column. * * @param columnName whose schemas to list. * @return The list of schemas. * Returns empty list if schema validation was not previously enabled. * @throws IOException if the cellSchema of the column can not be acquired. */ public Collection<Schema> getRegisteredReaders(final FijiColumnName columnName) throws IOException { return getRegisteredSchemas(columnName, SchemaRegistrationType.READER); }
/** {@inheritDoc} */ @Override public TableLayoutDesc apply(final FijiTableLayout refLayout) { Preconditions.checkNotNull(refLayout); try { final TableLayoutDesc refDesc = refLayout.getDesc(); return new TableLayoutBuilder(refDesc, fiji) .withLayoutId(nextLayoutId(refDesc.getLayoutId())) .withWriter(column, writerSchema) .withWritten(column, writerSchema) .build(); } catch (InvalidLayoutException ile) { LOG.error("Internal error while updating table layout in DEVELOPER mode: {}", ile); throw new InternalFijiError(ile); } catch (IOException ioe) { LOG.error("I/O error while updating table layout in DEVELOPER mode: {}", ioe); throw new FijiIOException(ioe); } } };
TableLayoutBuilder layoutBuilder = new TableLayoutBuilder(mSchemaTable); final TableLayoutDesc update = layoutBuilder.normalizeTableLayoutDesc( layoutUpdate, new LayoutOptions()
mDescBuilder = TableLayoutDesc.newBuilder(tableLayoutDesc) .setReferenceLayout(tableLayoutDesc.getLayoutId()) .setLayoutId(nextLayoutId(tableLayoutDesc.getLayoutId())); normalizeTableLayoutDesc( mDescBuilder, new LayoutOptions()
/** * Normalizes a table layout descriptor to use schema UIDs only. * * @param desc Table layout descriptor to normalize. * @param options Options describing the normalization to apply. * @return the normalized table layout descriptor. * @throws IOException on I/O error. */ public TableLayoutDesc normalizeTableLayoutDesc(TableLayoutDesc desc, LayoutOptions options) throws IOException { final TableLayoutDesc.Builder descBuilder = TableLayoutDesc.newBuilder(desc); normalizeTableLayoutDesc(descBuilder, options); return descBuilder.build(); }
normalizeAvroSchema(cellSchema.getDefaultReader(), options); normalizeAvroSchemaCollection(cellSchema.getReaders(), options); normalizeAvroSchemaCollection(cellSchema.getWriters(), options); normalizeAvroSchemaCollection(cellSchema.getWritten(), options);
/** * Normalizes a collection of AvroSchema to use schema UIDs only. * * @param avroSchemas Collection of AvroSchema to normalize. * @param options Options describing the normalization to apply. * @throws IOException on I/O error. */ private void normalizeAvroSchemaCollection( Collection<AvroSchema> avroSchemas, LayoutOptions options) throws IOException { for (AvroSchema avroSchema : avroSchemas) { normalizeAvroSchema(avroSchema, options); } }
final FamilyDesc soughtFd = getFamilyDesc(columnName);
final TableLayoutBuilder layoutBuilder = new TableLayoutBuilder(mSchemaTable); final TableLayoutDesc update = layoutBuilder.normalizeTableLayoutDesc( layoutUpdate, new LayoutOptions()
/** * Lists the writer schemas registered for the specified column. * * @param columnName whose schemas to list. * @return The list of schemas. * Returns empty list if schema validation was not previously enabled. * @throws IOException if the cellSchema of the column can not be acquired. */ public Collection<Schema> getRegisteredWriters(final FijiColumnName columnName) throws IOException { return getRegisteredSchemas(columnName, SchemaRegistrationType.WRITER); }
/** * Set the Avro validation policy for a given column in this table. * * @param column the column whose Avro validation policy will be set. * @param policy the AvroValidationPolicy to set for the given column. * @return this builder. * @throws InvalidLayoutException in case a fully qualified column in a map family is specified. * @throws NoSuchColumnException in case the specified column does not exist. */ public TableLayoutBuilder withAvroValidationPolicy( final FijiColumnName column, final AvroValidationPolicy policy) throws NoSuchColumnException, InvalidLayoutException { getColumnSchema(column).setAvroValidationPolicy(policy); return this; }
getMutableRegisteredSchemaList(columnName, schemaRegistrationType); final Iterator<AvroSchema> it = schemas.iterator(); while (it.hasNext()) {
/** * List the written schemas recorded for the specified column. * * @param columnName whose schemas to list. * @return The list of schemas. * Returns empty list if schema validation was not previously enabled. * @throws IOException if the cellSchema of the column can not be acquired. */ public Collection<Schema> getRegisteredWritten(final FijiColumnName columnName) throws IOException { return getRegisteredSchemas(columnName, SchemaRegistrationType.WRITTEN); }
/** * Returns a mutable list of registered schemas (READER, WRITER, WRITTEN) of the provided column. * * <p> * The list of schemas comes from a deeply nested record within the mutable table layout * descriptor. Therefore, mutating this list effectively mutates the table layout descriptor. * </p> * * @param columnName whose schema ids to list * @param schemaRegistrationType of the schemas to list: (READER, WRITER, WRITTEN). * @return The list of schema ids. * Returns empty list if schema validation was not previously enabled. * @throws NoSuchColumnException when column not found * @throws InvalidLayoutException if the column is final or non-AVRO */ private List<AvroSchema> getMutableRegisteredSchemaList( final FijiColumnName columnName, final SchemaRegistrationType schemaRegistrationType) throws NoSuchColumnException, InvalidLayoutException { Preconditions.checkNotNull(columnName); Preconditions.checkNotNull(schemaRegistrationType); final CellSchema cellSchema = getColumnSchema(columnName); // Avoid tracking schemas final or non-AVRO cells. if ((SchemaType.AVRO != cellSchema.getType()) || (SchemaStorage.FINAL == cellSchema.getStorage())) { throw new InvalidLayoutException("Final or non-AVRO column schema cannot be modified."); } final String fieldName = schemaRegistrationType.getCellSchemaFieldName(); return (List<AvroSchema>) Preconditions.checkNotNull(cellSchema.get(fieldName)); }
/** * Register a (READER | WRITER | WRITTEN) schema to a column. * * <p> The Schema is added even if it already exists. </p> * * @param columnName at which to register the schema. * @param schema to register. * @param schemaRegistrationType of the schema to register: (READER, WRITER, WRITTEN). * @throws IOException If the parameters are invalid. * @return this builder. */ private TableLayoutBuilder withSchema( final FijiColumnName columnName, final Schema schema, final SchemaRegistrationType schemaRegistrationType) throws IOException { Preconditions.checkNotNull(columnName); Preconditions.checkNotNull(schema); Preconditions.checkNotNull(schemaRegistrationType); final long schemaId = mSchemaTable.getOrCreateSchemaId(schema); final List<AvroSchema> schemas = getMutableRegisteredSchemaList(columnName, schemaRegistrationType); schemas.add(AvroSchema.newBuilder().setUid(schemaId).build()); return this; }