Package org.kiji.schema.util

Examples of org.kiji.schema.util.BytesKey


  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

    for (Result result : hashTableScanner) {
      hashTableRowCounter += 1;
      if (result.getRow().length != Hasher.HASH_SIZE_BYTES) {
        LOG.error(String.format(
            "Invalid schema hash table row key size: %s, expecting %d bytes.",
            new BytesKey(result.getRow()), Hasher.HASH_SIZE_BYTES));
        continue;
      }
      final BytesKey rowKey = new BytesKey(result.getRow());
      for (KeyValue keyValue : result.getColumn(SCHEMA_COLUMN_FAMILY_BYTES,
                                                SCHEMA_COLUMN_QUALIFIER_BYTES)) {
        try {
          final SchemaEntry entry = fromAvroEntry(decodeSchemaEntry(keyValue.getValue()));
          entries.add(entry);
          if (!getSchemaHash(entry.getSchema()).equals(entry.getHash())) {
            LOG.error(String.format(
                "Invalid schema hash table entry: computed schema hash %s does not match entry %s",
                getSchemaHash(entry.getSchema()), entry));
          }
          if (!rowKey.equals(entry.getHash())) {
            LOG.error(String.format("Inconsistent schema hash table: "
                + "hash encoded in row key %s does not match schema entry: %s",
                rowKey, entry));
          }
        } catch (IOException ioe) {
View Full Code Here

      // Skip the schema ID counter row:
      if (Arrays.equals(result.getRow(), SCHEMA_COUNTER_ROW_NAME_BYTES)) {
        continue;
      }
      idTableRowCounter += 1;
      final BytesKey rowKey = new BytesKey(result.getRow());

      long schemaId = -1;
      try {
        schemaId = new ByteStreamArray(result.getRow()).readVarInt64();
      } catch (EncodingException exn) {
View Full Code Here

        String.format("%d: %s%n", simpleSchemaId, mSimpleSchema.toString())));
  }

  @Test
  public void testGetSchemaByHash() throws Exception {
    final BytesKey hash = mTable.getSchemaHash(mSimpleSchema);
    assertEquals(BaseTool.SUCCESS, runTool(new SchemaTableTool(),
        getKiji().getURI().toString(),
        "--get-schema-by-hash=" + hash,
        "--output=" + mFile.toString(),
        "--interactive=false"
View Full Code Here

    assertEquals(mSimpleSchema, mTable.getSchema(Long.parseLong(mToolOutputLines[0])));
  }

  @Test
  public void lookupSchema() throws Exception {
    final BytesKey hash = mTable.getSchemaHash(mSimpleSchema);
    final long id = mTable.getOrCreateSchemaId(mSimpleSchema);
    assertEquals(BaseTool.SUCCESS, runTool(new SchemaTableTool(),
        getKiji().getURI().toString(),
        "--lookup=" + mFile.toString(),
        "--interactive=false"
    ));
    assertEquals(id, Long.parseLong(mToolOutputLines[0]));
    assertEquals(hash, new BytesKey(ByteArrayFormatter.parseHex(mToolOutputLines[1], ':')));
  }
View Full Code Here

    assertEquals(hash, new BytesKey(ByteArrayFormatter.parseHex(mToolOutputLines[1], ':')));
  }

  @Test
  public void testWrongOperationCount() throws Exception {
    final BytesKey hash = mTable.getSchemaHash(mSimpleSchema);
    final long id = mTable.getOrCreateSchemaId(mSimpleSchema);
    try {
      runTool(new SchemaTableTool(),
          getKiji().getURI().toString(),
          "--get-schema-by-hash=" + hash,
View Full Code Here

        getKiji().getURI().toString(),
        "--lookup=" + mFile.toString(),
        "--interactive=false"
        ));
    final long id = Long.parseLong(mToolOutputLines[0]);
    final BytesKey hash = new BytesKey(ByteArrayFormatter.parseHex(mToolOutputLines[1], ':'));

    // Confirm the id returns the correct schema and hash.
    assertEquals(BaseTool.SUCCESS, runTool(new SchemaTableTool(),
        getKiji().getURI().toString(),
        "--get-schema-by-id=" + id,
        "--output=" + mFile.toString(),
        "--interactive=false"
        ));
    assertEquals(mSimpleSchema, new Schema.Parser().parse(mFile));
    assertEquals(hash, new BytesKey(ByteArrayFormatter.parseHex(mToolOutputLines[0], ':')));

    // Confirm the hash returns the correct schema and id.
    assertEquals(BaseTool.SUCCESS, runTool(new SchemaTableTool(),
        getKiji().getURI().toString(),
        "--get-schema-by-hash=" + hash.toString(),
        "--output=" + mFile.toString(),
        "--interactive=false"
        ));
    assertEquals(mSimpleSchema, new Schema.Parser().parse(mFile));
    assertEquals(id, Long.parseLong(mToolOutputLines[0]));
View Full Code Here

  public void testSchemaMD5CacheTwoIdenticalPrimitives() throws Exception {
    final Schema intSchema1 = Schema.create(Schema.Type.INT);
    final Schema intSchema2 = Schema.create(Schema.Type.INT);

    final SchemaHashCache cache = new SchemaHashCache();
    final BytesKey key1 = cache.getHash(intSchema1);
    assertEquals(key1, cache.getHash(intSchema1));
    final BytesKey key2 = cache.getHash(intSchema2);
    assertEquals(key1, key2);
  }
View Full Code Here

        + "  \"doc\": \"Modified documentation\","
        + "  \"fields\": []"
        + "}");

    final SchemaHashCache cache = new SchemaHashCache();
    final BytesKey key1 = cache.getHash(schema1);
    assertEquals(key1, cache.getHash(schema1));

    final BytesKey key1bis = cache.getHash(schema1bis);
    final BytesKey key2 = cache.getHash(schema2);
    assertEquals(key1, key1bis);
    assertFalse(key1.equals(key2));
  }
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.