Package org.kiji.schema.avro

Examples of org.kiji.schema.avro.RowKeyFormat2


      implements KijiRowFilterDeserializer {
    /** {@inheritDoc} */
    @Override
    public KijiRowFilter createFromJson(JsonNode root) {
      try {
        final RowKeyFormat2 rowKeyFormat = (RowKeyFormat2) FromJson.fromAvroJsonString(
            root.path(ROW_KEY_FORMAT_NODE).getTextValue(), RowKeyFormat2.SCHEMA$);
        final JsonNode componentsJsonNode = root.path(COMPONENTS_NODE);
        Preconditions.checkArgument(componentsJsonNode.isArray(),
            "Node 'components' must be an array");
        final ArrayNode componentsNode = (ArrayNode)componentsJsonNode;
        final Object[] components = new Object[componentsNode.size()];
        for (int i = 0; i < components.length; i++) {
          JsonNode componentNode = componentsNode.get(i);
          if (componentNode.isNull()) {
            components[i] = null; // an explicit no-op
          } else {
            switch (rowKeyFormat.getComponents().get(i).getType()) {
              case INTEGER:
                components[i] = Integer.valueOf(componentNode.getIntValue());
                break;
              case LONG:
                components[i] = Long.valueOf(componentNode.getLongValue());
                break;
              case STRING:
                components[i] = componentNode.getTextValue();
                break;
              default:
                throw new IllegalStateException("Unknown component type: "
                    + rowKeyFormat.getComponents().get(i).getType());
            }
          }
        }
        return new FormattedEntityIdRowFilter(rowKeyFormat, components);
      } catch (IOException ioe) {
View Full Code Here


    int hashSize = 16;
    // No assumptions make about the RKF.
    if (RowKeyFormat.class.equals(tableLayout.getKeysFormat().getClass())) {
      hashSize = ((RowKeyFormat) tableLayout.getKeysFormat()).getHashSize();
    } else if (RowKeyFormat2.class.equals(tableLayout.getKeysFormat().getClass())) {
      RowKeyFormat2 format = (RowKeyFormat2) tableLayout.getKeysFormat();
      if (null == format.getSalt()) {
        throw new IllegalArgumentException(
            "This table layout defines an entityId format without hashing enabled.");
      }
      hashSize = ((RowKeyFormat2) tableLayout.getKeysFormat()).getSalt().getHashSize();
    }
View Full Code Here

   */
  public static int getHashSize(Object rowKeyFormat) {
    if (rowKeyFormat instanceof RowKeyFormat) {
      return ((RowKeyFormat) rowKeyFormat).getHashSize();
    } else if (rowKeyFormat instanceof RowKeyFormat2) {
      RowKeyFormat2 format2 = (RowKeyFormat2) rowKeyFormat;
      if (null == format2.getSalt()) {
        throw new RuntimeException("This RowKeyFormat2 instance does not specify salt/hashing.");
      } else {
        return format2.getSalt().getHashSize();
      }
    } else {
      throw new RuntimeException("Unsupported Row Key Format");
    }
  }
View Full Code Here

    if (keysFormat instanceof RowKeyFormat) {
      // Former, deprecated, unformatted row key specification:
      return factory.getEntityId(rowKeySpec);

    } else if (keysFormat instanceof RowKeyFormat2) {
      final RowKeyFormat2 format = (RowKeyFormat2) keysFormat;
      switch (format.getEncoding()) {
      case RAW: return factory.getEntityIdFromHBaseRowKey(parseBytesFlag(rowKeySpec));
      case FORMATTED: return parseJsonFormattedKeySpec(rowKeySpec, format, factory);
      default:
        throw new RuntimeException(String.format(
            "Invalid layout for table '%s' with unsupported keys format: '%s'.",
View Full Code Here

        RowKeyComponent.newBuilder().setName("str2").setType(ComponentType.STRING).build(),
        RowKeyComponent.newBuilder().setName("anint").setType(ComponentType.INTEGER).build(),
        RowKeyComponent.newBuilder().setName("along").setType(ComponentType.LONG).build());

    // build the row key format
    final RowKeyFormat2 format = RowKeyFormat2.newBuilder().setEncoding(RowKeyEncoding.FORMATTED)
        .setSalt(HashSpec.newBuilder().setHashSize(2).build())
        .setComponents(components)
        .build();

    return format;
View Full Code Here

                })
            // Force futures to execute by sending results to a list
            .toList();

    // We can use the DISTINCT optimization iff the entity ID contains only hashed components
    RowKeyFormat2 keyFormat = (RowKeyFormat2) layout.getDesc().getKeysFormat();
    final boolean deduplicateComponents =
        keyFormat.getRangeScanStartIndex() != keyFormat.getComponents().size();

    if (deduplicateComponents) {
      LOG.warn("Scanning a Cassandra Kiji table with non-hashed entity ID components is"
              + " inefficient.  Consider hashing all entity ID components. Table: {}.",
          table.getURI());
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.