Package org.kiji.schema.util

Examples of org.kiji.schema.util.BytesKey


    }

    /** {@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));
      }
View Full Code Here


  /** Schema encoders that uses a hash of the schema. */
  private class SchemaHashEncoder implements SchemaEncoder {
    /** {@inheritDoc} */
    @Override
    public void encode(final Schema writerSchema) throws IOException {
      final BytesKey schemaHash = mCellSpec.getSchemaTable().getOrCreateSchemaHash(writerSchema);
      mByteArrayEncoder.writeFixed(schemaHash.getBytes());
    }
View Full Code Here

     *
     * @param schema Avro schema to hash.
     * @return the schema hash.
     */
    public BytesKey getHash(Schema schema) {
      final BytesKey hash = mCache.get(schema);
      if (null != hash) {
        return hash;
      }
      final BytesKey newHash = new BytesKey(hashSchema(schema));
      mCache.put(schema, newHash);
      return newHash;
    }
View Full Code Here

  private synchronized SchemaEntry getOrCreateSchemaEntry(final Schema schema) throws IOException {
    final State state = mState.get();
    Preconditions.checkState(state == State.OPEN,
        "Cannot get or create schema entry from SchemaTable instance in state %s.", state);

    final BytesKey schemaHash = getSchemaHash(schema);
    final SchemaEntry knownEntry = getSchemaEntry(schemaHash);
    if (knownEntry != null) {
      return knownEntry;
    }
View Full Code Here

   * @return an equivalent SchemaEntry
   */
  public static SchemaEntry fromAvroEntry(final SchemaTableEntry avroEntry) {
    final String schemaJson = avroEntry.getAvroSchema();
    final Schema schema = new Schema.Parser().parse(schemaJson);
    return new SchemaEntry(avroEntry.getId(), new BytesKey(avroEntry.getHash().bytes()), schema);
  }
View Full Code Here

            new BytesKey(result.getRow()), Hasher.HASH_SIZE_BYTES));
        continue;
      */

      // Get the row key, timestamp, and schema for this row
      final BytesKey rowKey = new BytesKey(ByteUtils.toBytes(row.getBytes(SCHEMA_COLUMN_HASH_KEY)));
      final long timestamp = row.getDate(SCHEMA_COLUMN_TIME).getTime();
      final byte[] schemaAsBytes = ByteUtils.toBytes(row.getBytes(SCHEMA_COLUMN_VALUE));

      try {
        final SchemaEntry entry = fromAvroEntry(decodeSchemaEntry(schemaAsBytes));
        entries.add(entry);
        if (!getSchemaHash(entry.getSchema()).equals(entry.getHash())) {
          LOG.error(
              "Invalid schema hash table entry: computed schema hash {} does not match entry {}.",
              getSchemaHash(entry.getSchema()), entry);
        }
        if (!rowKey.equals(entry.getHash())) {
          LOG.error(
              "Inconsistent schema hash table: hash encoded in row key {}"
                  + " does not match schema entry: {}.",
              rowKey, entry
          );
View Full Code Here

    for (Row row : resultSet) {
      idTableRowCounter += 1;

      // Get the row key, timestamp, and schema for this row.  Use "Unsafe" version of method here
      // to get raw bytes no matter what format the field is in the C* table.
      final BytesKey rowKey = new BytesKey(
          ByteUtils.toBytes(row.getBytesUnsafe(SCHEMA_COLUMN_ID_KEY)));

      long schemaId = -1;
      try {
        schemaId = row.getLong(SCHEMA_COLUMN_ID_KEY);
View Full Code Here

    final KijiSchemaTable table = mKiji.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()) {
View Full Code Here

   * @return Tool exit code.
   * @throws IOException in case of an error.
   */
  private int getByHash() throws IOException {
    final KijiSchemaTable table = mKiji.getSchemaTable();
    final BytesKey bytesKey = new BytesKey(ByteArrayFormatter.parseHex(mGetByHashFlag, ':'));
    final SchemaEntry sEntry = table.getSchemaEntry(bytesKey);
    final Schema schema = sEntry.getSchema();

    if (isInteractive()) {
      getPrintStream().print("Schema ID for the given schema is: ");
View Full Code Here

    assertEquals(SCHEMA_DOUBLE, schemaTable.getSchema(schemaTable.getSchemaHash(SCHEMA_DOUBLE)));
    assertEquals(SCHEMA_BOOLEAN, schemaTable.getSchema(schemaTable.getSchemaHash(SCHEMA_BOOLEAN)));
    assertEquals(SCHEMA_NULL, schemaTable.getSchema(schemaTable.getSchemaHash(SCHEMA_NULL)));

    // There is no hash composed of a single byte 0:
    assertNull(schemaTable.getSchema(new BytesKey(new byte[]{0})));

    // Re-creating existing schemas are no-ops:
    assertEquals(
        PreRegisteredSchema.NULL.getSchemaId(),
        schemaTable.getOrCreateSchemaId(SCHEMA_NULL));
View Full Code Here

TOP

Related Classes of org.kiji.schema.util.BytesKey

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.