/** * Produce an Avro schema object depending on what was set (string or UID). * * @param schemaTable is the schema table to use to fetch the Avro schema given a UID * @return the corresponding Avro schema. * @throws IOException if there is a problem fetching the schema from the schema table if the * UID is set. */ public Schema resolve(FijiSchemaTable schemaTable) throws IOException { if (mParsedSchema == null) { return schemaTable.getSchema(mSchemaUid); } else { return mParsedSchema; } }
/** * Restores all SchemaTable entries from the metadata backup. * * @param backup the deserialized backup of the metadata. * @param fiji the connected Fiji instance. * @throws IOException if there is an error communicating with HBase. */ public void restoreSchemas(MetadataBackup backup, Fiji fiji) throws IOException { // Restore all Schema table entries in the file. final FijiSchemaTable schemaTable = fiji.getSchemaTable(); LOG.info("Restoring schema table entries..."); schemaTable.fromBackup(backup.getSchemaTable()); LOG.info("Restored " + backup.getSchemaTable().getEntries().size() + " entries."); }
/** * Register a schema. * * @return Tool exit code. * @throws IOException in case of an error. */ private int registerSchema() throws IOException { final FijiSchemaTable table = mFiji.getSchemaTable(); final File file = new File(mRegisterFlag); final Schema schema = new Schema.Parser().parse(file); final long id = table.getOrCreateSchemaId(schema); final String hash = table.getSchemaHash(schema).toString(); if (isInteractive()) { getPrintStream().print("Schema ID for the given schema is: "); } getPrintStream().println(id); if (isInteractive()) { getPrintStream().print("Schema hash for the given schema is: "); } getPrintStream().println(hash); return SUCCESS; }
final Schema schemaFromId = mSchemaTable.getSchema(avroSchema.getUid()); if (!Objects.equal(schema, schemaFromId)) { throw new InvalidLayoutException(String.format( schema = mSchemaTable.getSchema(avroSchema.getUid()); final long schemaId = mSchemaTable.getOrCreateSchemaId(schema); avroSchema.setUid(schemaId); avroSchema.setJson(null);
final Schema schema = table.getSchema(mGetByIdFlag); Preconditions.checkArgument( schema != null, "No schema definition with ID: %s", mGetByIdFlag); getPrintStream().print("Schema hash of the given schema is: "); getPrintStream().println(table.getSchemaHash(schema)); if (mOutputFlag != null && !mOutputFlag.isEmpty()) {
/** {@inheritDoc} */ @Override public void encode(final Schema writerSchema) throws IOException { final long schemaId = mCellSpec.getSchemaTable().getOrCreateSchemaId(writerSchema); mByteArrayEncoder.writeFixed(ByteStreamArray.longToVarInt64(schemaId)); } }
.setLayoutVersion(fiji.getSystemTable().getDataVersion().toString()) .setSystemTable(fiji.getSystemTable().toBackup()) .setSchemaTable(fiji.getSchemaTable().toBackup()) .setMetaTable(fiji.getMetaTable().toBackup()) .build();
mSchemaTable.flush();
/** * Lookup a schema. * * @return Tool exit code. * @throws IOException in case of an error. */ private int lookupSchema() throws IOException { final FijiSchemaTable table = mFiji.getSchemaTable(); final File file = new File(mLookupFlag); final Schema schema = new Schema.Parser().parse(file); final SchemaEntry sEntry = table.getSchemaEntry(schema); final long id = sEntry.getId(); final BytesKey hash = sEntry.getHash(); if (isInteractive()) { getPrintStream().print("Schema ID for the given schema is: "); } getPrintStream().println(id); if (isInteractive()) { getPrintStream().print("Schema hash for the given schema is: "); } getPrintStream().println(hash); return SUCCESS; }
/** {@inheritDoc} */ @Override public void encode(final Schema writerSchema) throws IOException { final BytesKey schemaHash = mCellSpec.getSchemaTable().getOrCreateSchemaHash(writerSchema); mByteArrayEncoder.writeFixed(schemaHash.getBytes()); } }
/** * 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; }
.setLayoutVersion(fiji.getSystemTable().getDataVersion().toString()) .setSystemTable(fiji.getSystemTable().toBackup()) .setSchemaTable(fiji.getSchemaTable().toBackup()) .setMetaTable(fiji.getMetaTable().toBackup()) .build();
mSchemaTable.flush();
final FijiSchemaTable table = mFiji.getSchemaTable(); final BytesKey bytesKey = new BytesKey(ByteArrayFormatter.parseHex(mGetByHashFlag, ':')); final SchemaEntry sEntry = table.getSchemaEntry(bytesKey); final Schema schema = sEntry.getSchema();
/** {@inheritDoc} */ @Override public Schema decode(ByteStreamArray bstream) throws IOException { final long schemaId = bstream.readVarInt64(); final Schema schema = mSchemaTable.getSchema(schemaId); if (null == schema) { throw new IOException( String.format("Schema with ID %d not found in schema table.", schemaId)); } return schema; } }
/** {@inheritDoc} */ @Override public Long apply(AvroSchema avroSchema) { if (avroSchema.getJson() != null) { final Schema schema = new Schema.Parser().parse(avroSchema.getJson()); try { return mSchemaTable.getOrCreateSchemaId(schema); } catch (IOException ioe) { throw new FijiIOException(ioe); } } else if (avroSchema.getUid() != null) { return avroSchema.getUid(); } else { throw new FijiIOException( "AvroSchema neither has a schema UID nor a schema JSON descriptor."); } } }
/** * Restores all SchemaTable entries from the metadata backup. * * @param backup the deserialized backup of the metadata. * @param fiji the connected Fiji instance. * @throws java.io.IOException if there is an error communicating with HBase. */ public void restoreSchemas(MetadataBackup backup, Fiji fiji) throws IOException { // Restore all Schema table entries in the file. final FijiSchemaTable schemaTable = fiji.getSchemaTable(); LOG.info("Restoring schema table entries..."); schemaTable.fromBackup(backup.getSchemaTable()); LOG.info("Restored " + backup.getSchemaTable().getEntries().size() + " entries."); }
/** * List all schemas in the table. * * @return The Tool exit code. * @throws IOException in case of an error. */ private int list() throws IOException { final FijiSchemaTable schemaTable = mFiji.getSchemaTable(); long id = 0; Schema schema = schemaTable.getSchema(id); while (null != schema) { getPrintStream().printf("%d: %s%n", id, schema.toString()); schema = schemaTable.getSchema(++id); } return SUCCESS; }
if (null != counter) { SchemaOption schemaOption = new SchemaOption(schemaTable. getOrCreateSchemaId(Schema.create(Schema.Type.LONG))); returnRow.addCell(counter, schemaOption); if (null != counter) { SchemaOption schemaOption = new SchemaOption(schemaTable. getOrCreateSchemaId(counter.getWriterSchema())); returnRow.addCell(counter, schemaOption); FijiCell<Object> fijiCell = timestampedCell.getValue(); SchemaOption schemaOption = new SchemaOption(schemaTable. getOrCreateSchemaId(fijiCell.getWriterSchema())); returnRow.addCell(fijiCell, schemaOption); for (FijiCell<Object> timestampedCell : e.getValue().values()) { SchemaOption schemaOption = new SchemaOption(schemaTable. getOrCreateSchemaId(timestampedCell.getWriterSchema())); returnRow.addCell(timestampedCell, schemaOption);
/** {@inheritDoc} */ @Override public Schema decode(ByteStreamArray bstream) throws IOException { final BytesKey schemaHash = new BytesKey(bstream.readBytes(Hasher.HASH_SIZE_BYTES)); final Schema schema = mSchemaTable.getSchema(schemaHash); if (null == schema) { throw new IOException( String.format("Schema with hash %s not found in schema table.", schemaHash)); } return schema; } }