Package org.kiji.schema.avro

Examples of org.kiji.schema.avro.RowKeyFormat2


  // -----------------------------------------------------------------------------------------------

  @Test
  public void testFormattedEntityId() {
    final RowKeyFormat2 format = makeRowKeyFormat();
    final FormattedEntityId formattedEntityId = makeId(format, "one", 1, 7L);
    byte[] hbaseRowKey = formattedEntityId.getHBaseRowKey();
    assertNotNull(hbaseRowKey);

    FormattedEntityId testEntityId = FormattedEntityId.fromHBaseRowKey(hbaseRowKey, format);
    final List<Object> actuals = testEntityId.getComponents();
    assertEquals(format.getComponents().size(), actuals.size());
    assertEquals("one", actuals.get(0));
    assertEquals(1, actuals.get(1));
    assertEquals(7L, actuals.get(2));

    assertArrayEquals(formattedEntityId.getHBaseRowKey(), testEntityId.getHBaseRowKey());
View Full Code Here


    assertArrayEquals(formattedEntityId.getHBaseRowKey(), testEntityId.getHBaseRowKey());
  }

  @Test
  public void testFormattedEntityIdUsingFactory() {
    final RowKeyFormat2 format = makeRowKeyFormat();
    final EntityIdFactory entityIdFactory = EntityIdFactory.getFactory(format);
    final List<Object> inputRowKey = Lists.<Object>newArrayList("one", 1, 7L);

    // passing args as list
    final EntityId formattedEntityId = entityIdFactory.getEntityId(inputRowKey);
    final byte[] hbaseRowKey = formattedEntityId.getHBaseRowKey();
    assertNotNull(hbaseRowKey);
    LOG.info("Hbase Key is: {}", ByteArrayFormatter.toHex(hbaseRowKey, ':'));

    EntityId testEntityId = entityIdFactory.getEntityIdFromHBaseRowKey(hbaseRowKey);
    final List<Object> actuals = testEntityId.getComponents();
    assertEquals(format.getComponents().size(), actuals.size());
    assertEquals("one", actuals.get(0));
    assertEquals(1, actuals.get(1));
    assertEquals(7L, actuals.get(2));

    assertArrayEquals(formattedEntityId.getHBaseRowKey(), testEntityId.getHBaseRowKey());

    // passing args as varargs
    EntityId formattedEntityId2 = entityIdFactory.getEntityId("two",
        new Integer(2), new Long(72L));
    byte[] hbaseRowKey2 = formattedEntityId2.getHBaseRowKey();
    assertNotNull(hbaseRowKey2);

    EntityId testEntityId2 = entityIdFactory.getEntityIdFromHBaseRowKey(hbaseRowKey2);
    List<Object> actuals2 = testEntityId2.getComponents();
    assertEquals(format.getComponents().size(), actuals2.size());
    assertEquals("two", actuals2.get(0));
    assertEquals(2, actuals2.get(1));
    assertEquals(72L, actuals2.get(2));

    assertArrayEquals(formattedEntityId2.getHBaseRowKey(), testEntityId2.getHBaseRowKey());
View Full Code Here

    assertArrayEquals(formattedEntityId2.getHBaseRowKey(), testEntityId2.getHBaseRowKey());
  }

  @Test
  public void testOtherHashSizes() {
    final RowKeyFormat2 format = makeIntRowKeyFormat();
    final FormattedEntityId formattedEntityId = makeId(format, 1);
    final byte[] hbaseRowKey = formattedEntityId.getHBaseRowKey();
    assertNotNull(hbaseRowKey);

    FormattedEntityId testEntityId = FormattedEntityId.fromHBaseRowKey(hbaseRowKey, format);
    final List<Object> actuals = testEntityId.getComponents();
    assertEquals(format.getComponents().size(), actuals.size());
    assertEquals(1, actuals.get(0));
    assertArrayEquals(formattedEntityId.getHBaseRowKey(), testEntityId.getHBaseRowKey());

  }
View Full Code Here

  }

  @Test
  public void testFormattedEntityIdWithNull() {
    final RowKeyFormat2 format = makeRowKeyFormat();
    final FormattedEntityId formattedEntityId = makeId(format, "one", 1, null);
    final byte[] hbaseRowKey = formattedEntityId.getHBaseRowKey();
    assertNotNull(hbaseRowKey);

    FormattedEntityId testEntityId = FormattedEntityId.fromHBaseRowKey(hbaseRowKey, format);
    final List<Object> actuals = testEntityId.getComponents();
    assertEquals(format.getComponents().size(), actuals.size());
    assertEquals("one", actuals.get(0));
    assertEquals(1, actuals.get(1));
    assertNull(actuals.get(2));

    // another way of doing nulls
View Full Code Here

    assertArrayEquals(formattedEntityId.getHBaseRowKey(), formattedEntityId1.getHBaseRowKey());
  }

  @Test
  public void testFormattedEntityIdOrdering() {
    final RowKeyFormat2 rkf = makeOrderingTestRowKeyFormat();
    final List<FormattedEntityId> expected = Lists.newArrayList();

    // We expect this to be the ordering for the keys below.
    // x is the dummy key to make all hashes equal.
    expected.add(makeId(rkf, "x", "a", "bc"));
View Full Code Here

    }
  }

  @Test
  public void testCompositeHashEntityId() {
    final RowKeyFormat2 format = makeCompositeHashRowKeyFormat();
    final FormattedEntityId formattedEntityId = makeId(format, "one", 1, 7L);
    final byte[] hbaseRowKey = formattedEntityId.getHBaseRowKey();

    final FormattedEntityId testEntityId = FormattedEntityId.fromHBaseRowKey(hbaseRowKey, format);
    final List<Object> actuals = testEntityId.getComponents();
    assertEquals(format.getComponents().size(), actuals.size());
    assertEquals("one", actuals.get(0));
    assertEquals(1, actuals.get(1));
    assertEquals(7L, actuals.get(2));

    assertArrayEquals(formattedEntityId.getHBaseRowKey(), testEntityId.getHBaseRowKey());
View Full Code Here

    assertArrayEquals(formattedEntityId.getHBaseRowKey(), testEntityId.getHBaseRowKey());
  }

  @Test
  public void testEmptyStringFormattedEntityId() {
    final RowKeyFormat2 format = makeStringRowKeyFormat();
    final FormattedEntityId formattedEntityId = makeId(format, "", "");
    final byte[] hbaseRowKey = formattedEntityId.getHBaseRowKey();

    FormattedEntityId testEntityId = FormattedEntityId.fromHBaseRowKey(hbaseRowKey, format);
    final List<Object> actuals = testEntityId.getComponents();
    assertEquals(format.getComponents().size(), actuals.size());
    assertEquals("", actuals.get(0));
    assertEquals("", actuals.get(1));
    assertEquals(null, actuals.get(2));

    assertArrayEquals(formattedEntityId.getHBaseRowKey(), testEntityId.getHBaseRowKey());
View Full Code Here

  }

  @Test
  public void testNullValueInHash() {
    final RowKeyFormat2 format = makeCompletelyHashedRowKeyFormat();

    // Set one component as null explicitly, do not include the next one at all:
    final FormattedEntityId formattedEntityId = makeId(format, "one", null);
    byte[] hbaseRowKey = formattedEntityId.getHBaseRowKey();

    FormattedEntityId testEntityId = FormattedEntityId.fromHBaseRowKey(hbaseRowKey, format);
    final List<Object> actuals = testEntityId.getComponents();
    assertEquals(format.getComponents().size(), actuals.size());
    assertEquals("one", actuals.get(0));
    assertNull(actuals.get(1));
    assertNull(actuals.get(2));

    assertArrayEquals(formattedEntityId.getHBaseRowKey(), testEntityId.getHBaseRowKey());
View Full Code Here

    assertArrayEquals(formattedEntityId.getHBaseRowKey(), testEntityId.getHBaseRowKey());
  }

  @Test
  public void testExplicitNullValueInHash() {
    final RowKeyFormat2 format = makeCompletelyHashedRowKeyFormat();

    FormattedEntityId formattedEntityId = makeId(format, "one", null, null);
    byte[] hbaseRowKey = formattedEntityId.getHBaseRowKey();

    FormattedEntityId testEntityId = FormattedEntityId.fromHBaseRowKey(hbaseRowKey, format);
    final List<Object> actuals = testEntityId.getComponents();
    assertEquals(format.getComponents().size(), actuals.size());
    assertEquals("one", actuals.get(0));
    assertNull(actuals.get(1));
    assertNull(actuals.get(2));

    assertArrayEquals(formattedEntityId.getHBaseRowKey(), testEntityId.getHBaseRowKey());
View Full Code Here

    assertArrayEquals(formattedEntityId.getHBaseRowKey(), testEntityId.getHBaseRowKey());
  }

  @Test
  public void testImplicitNullValueInHash() {
    final RowKeyFormat2 format = makeCompletelyHashedRowKeyFormat();

    // Implicit nulls for remaining components:
    FormattedEntityId formattedEntityId = makeId(format, "one");
    byte[] hbaseRowKey = formattedEntityId.getHBaseRowKey();

    FormattedEntityId testEntityId = FormattedEntityId.fromHBaseRowKey(hbaseRowKey, format);
    final List<Object> actuals = testEntityId.getComponents();
    assertEquals(format.getComponents().size(), actuals.size());
    assertEquals("one", actuals.get(0));
    assertNull(actuals.get(1));
    assertNull(actuals.get(2));

    assertArrayEquals(formattedEntityId.getHBaseRowKey(), testEntityId.getHBaseRowKey());
View Full Code Here

TOP

Related Classes of org.kiji.schema.avro.RowKeyFormat2

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.