Package org.kiji.schema.avro

Examples of org.kiji.schema.avro.RowKeyFormat2


   * Convenience method to be a minimal and valid table layout that can then be used to
   * build one with a specific condition.
   * @return a valid table layout with one locality group and one column
   */
  private TableLayoutDesc makeMinimalValidLayout() {
    RowKeyFormat2 format = makeHashPrefixedRowKeyFormat();

    makeHashPrefixedRowKeyFormat();
    return TableLayoutDesc.newBuilder()
        .setName("table_name")
        .setKeysFormat(format)
View Full Code Here


    }
  }

  @Test
  public void testDuplicateQualifierName() throws Exception {
    RowKeyFormat2 format = makeHashPrefixedRowKeyFormat();
    // Reference layout with a single column: "family_name:column_name"
    final TableLayoutDesc desc = TableLayoutDesc.newBuilder()
        .setName("table_name")
        .setKeysFormat(format)
        .setVersion(TABLE_LAYOUT_VERSION)
View Full Code Here

  }

  /** Test for a family with both group and map type. */
  @Test
  public void testInvalidGroupAndMapFamily() throws Exception {
    RowKeyFormat2 format = makeHashPrefixedRowKeyFormat();
    // Reference layout with a single column: "family_name:column_name"
    final TableLayoutDesc desc = TableLayoutDesc.newBuilder()
        .setName("table_name")
        .setKeysFormat(format)
        .setVersion(TABLE_LAYOUT_VERSION)
View Full Code Here

    Object keysFormatRaw = descOut.getKeysFormat();
    assertNotNull("Unexpected null RowKeyFormat2 field", keysFormatRaw);
    assertTrue("keys_format should be an RKF2", keysFormatRaw instanceof RowKeyFormat2);

    RowKeyFormat2 rkf2 = (RowKeyFormat2) keysFormatRaw;
    HashSpec salt = rkf2.getSalt();
    assertNotNull("Expected non-null salt", salt);

    // Test that the null salt element specified above is replaced with the default
    // values we specified.
    assertEquals(2, (int) salt.getHashSize());
View Full Code Here

   */
  public static JsonEntityIdParser create(
      final JsonNode node,
      final KijiTableLayout layout) throws IOException {

    RowKeyFormat2 format = getRKF2(layout);

    if (node.isArray()) {
      final Object[] components = new Object[node.size()];
      boolean wildCarded = false;
      for (int i = 0; i < node.size(); i++) {
        final Object component = getNodeValue(node.get(i));
        if (component.equals(WildcardSingleton.INSTANCE)) {
          wildCarded = true;
          components[i] = null;
        } else if (null != format
            && ComponentType.LONG == format.getComponents().get(i).getType()) {
          components[i] = ((Number) component).longValue();
        } else {
          components[i] = component;
        }
      }
View Full Code Here

   */
  private static LinkedHashMap<String, String> getEntityIdColumnTypes(
      final KijiTableLayout layout
  ) {
    LinkedHashMap<String, String> columns = Maps.newLinkedHashMap();
    RowKeyFormat2 keyFormat = (RowKeyFormat2) layout.getDesc().getKeysFormat();
    switch (keyFormat.getEncoding()) {
      case RAW: {
        columns.put(RAW_KEY_COL, BYTES_TYPE);
        break;
      }
      case FORMATTED: {
        for (RowKeyComponent component : keyFormat.getComponents()) {
          columns.put(
              translateEntityIDComponentNameToColumnName(component.getName()),
              getCQLType(component.getType()));
        }
        break;
      }
      default: throw new IllegalArgumentException(
          String.format("Unknown row key encoding %s.", keyFormat.getEncoding()));
    }
    return columns;
  }
View Full Code Here

   */
  private static LinkedHashMap<String, Object> getEntityIdColumnValues(
      final KijiTableLayout layout,
      final EntityId entityId
  ) {
    RowKeyFormat2 keyFormat = (RowKeyFormat2) layout.getDesc().getKeysFormat();
    final LinkedHashMap<String, Object> columnValues = Maps.newLinkedHashMap();
    switch (keyFormat.getEncoding()) {
      case RAW: {
        columnValues.put(RAW_KEY_COL, ByteBuffer.wrap(entityId.getHBaseRowKey()));
        break;
      }
      case FORMATTED: {
        final List<RowKeyComponent> components = keyFormat.getComponents();
        final List<Object> values = entityId.getComponents();
        Preconditions.checkArgument(components.size() == values.size(),
            "Number of entity ID components (%s) must match the number of entity ID values (%s).",
            components, values);
        for (int i = 0; i < components.size(); i++) {
          columnValues.put(
              translateEntityIDComponentNameToColumnName(components.get(i).getName()),
              values.get(i));
        }
        break;
      }
      default: throw new IllegalArgumentException(
          String.format("Unknown row key encoding %s.", keyFormat.getEncoding()));
    }
    return columnValues;
  }
View Full Code Here

   *
   * @param layout to return partition key columns for.
   * @return the primary key columns for the layout.
   */
  public static List<String> getPartitionKeyColumns(KijiTableLayout layout) {
    RowKeyFormat2 keyFormat = (RowKeyFormat2) layout.getDesc().getKeysFormat();
    switch (keyFormat.getEncoding()) {
      case RAW: return Lists.newArrayList(RAW_KEY_COL);
      case FORMATTED:
        return transformToColumns(
            keyFormat.getComponents().subList(0, keyFormat.getRangeScanStartIndex()));
      default:
        throw new IllegalArgumentException(
            String.format("Unknown row key encoding %s.", keyFormat.getEncoding()));
    }
  }
View Full Code Here

   *
   * @param layout The layou of the table.
   * @return the cluster columns of the table from the entity ID.
   */
  private static List<String> getEntityIdClusterColumns(KijiTableLayout layout) {
    RowKeyFormat2 keyFormat = (RowKeyFormat2) layout.getDesc().getKeysFormat();
    switch (keyFormat.getEncoding()) {
      case RAW: {
        return Lists.newArrayList();
      }
      case FORMATTED: {
        int size = keyFormat.getComponents().size();
        int start = keyFormat.getRangeScanStartIndex();
        if (start == size) {
          return Lists.newArrayList();
        } else {
          return transformToColumns(
              keyFormat
                  .getComponents()
                  .subList(keyFormat.getRangeScanStartIndex(), keyFormat.getComponents().size()));
        }
      }
      default:
        throw new IllegalArgumentException(
            String.format("Unknown row key encoding %s.", keyFormat.getEncoding()));
    }
  }
View Full Code Here

   * @return A function to decode row keys and tokens for the table.
   */
  public static Function<Row, TokenRowKeyComponents> getRowKeyDecoderFunction(
      final KijiTableLayout layout
  ) {
    final RowKeyFormat2 keyFormat = (RowKeyFormat2) layout.getDesc().getKeysFormat();

    switch (keyFormat.getEncoding()) {
      case RAW: return new RawRowKeyDecoder(layout);
      case FORMATTED: return new FormattedRowKeyDecoder(layout);
      default:
        throw new IllegalArgumentException(
            String.format("Unknown row key encoding %s.", keyFormat.getEncoding()));
    }
  }
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.