Package com.cloudera.cdk.data.hbase.impl.EntitySchema

Examples of com.cloudera.cdk.data.hbase.impl.EntitySchema.FieldMapping


  }

  public SingleFieldEntityFilter(EntitySchema entitySchema,
      EntitySerDe<?> entitySerDe, String fieldName, Object filterValue,
      CompareFilter.CompareOp equalityOperator) {
    FieldMapping fieldMapping = entitySchema.getFieldMapping(fieldName);
    if (fieldMapping.getMappingType() != MappingType.COLUMN) {
      throw new DatasetException(
          "SingleColumnValueFilter only compatible with COLUMN mapping types.");
    }

    byte[] family = fieldMapping.getFamily();
    byte[] qualifier = fieldMapping.getQualifier();
    byte[] comparisonBytes = entitySerDe.serializeColumnValueToBytes(fieldName,
        filterValue);

    this.filter = new SingleColumnValueFilter(family, qualifier,
        equalityOperator, comparisonBytes);
View Full Code Here


  private final Filter filter;

  public RegexEntityFilter(EntitySchema entitySchema,
      EntitySerDe<?> entitySerDe, String fieldName, String regex,
      boolean isEqual) {
    FieldMapping fieldMapping = entitySchema.getFieldMapping(fieldName);
    if (fieldMapping.getMappingType() != MappingType.COLUMN) {
      throw new DatasetException(
          "SingleColumnValueFilter only compatible with COLUMN mapping types.");
    }

    byte[] family = fieldMapping.getFamily();
    byte[] qualifier = fieldMapping.getQualifier();

    this.filter = new org.apache.hadoop.hbase.filter.SingleColumnValueFilter(
        family, qualifier, isEqual ? CompareFilter.CompareOp.EQUAL
            : CompareFilter.CompareOp.NOT_EQUAL, new RegexStringComparator(
            regex));
View Full Code Here

  }

  @Override
  public Increment mapToIncrement(PartitionKey key, String fieldName,
      long amount) {
    FieldMapping fieldMapping = entitySchema.getFieldMapping(fieldName);
    if (fieldMapping == null) {
      throw new DatasetException("Unknown field in the schema: "
          + fieldName);
    }
    if (fieldMapping.getMappingType() != MappingType.COUNTER) {
      throw new DatasetException("Field is not a counter type: "
          + fieldName);
    }

    byte[] keyBytes = keySerDe.serialize(key);
    Increment increment = new Increment(keyBytes);
    increment.addColumn(fieldMapping.getFamily(), fieldMapping.getQualifier(),
        amount);
    return increment;
  }
View Full Code Here

    return increment;
  }

  @Override
  public long mapFromIncrementResult(Result result, String fieldName) {
    FieldMapping fieldMapping = entitySchema.getFieldMapping(fieldName);
    if (fieldMapping == null) {
      throw new DatasetException("Unknown field in the schema: "
          + fieldName);
    }
    if (fieldMapping.getMappingType() != MappingType.COUNTER) {
      throw new DatasetException("Field is not a counter type: "
          + fieldName);
    }
    return (Long) entitySerDe.deserialize(fieldMapping, result);
  }
View Full Code Here

    // field).
    List<FieldMapping> fieldMappings = new ArrayList<FieldMapping>();
    for (JsonNode recordFieldJson : fields) {
      String fieldName = recordFieldJson.get("name").getTextValue();
      Schema.Type type = schema.getField(fieldName).schema().getType();
      FieldMapping fieldMapping = createFieldMapping(fieldName,
          recordFieldJson, defaultValueMap, type);
      if (fieldMapping != null) {
        fieldMappings.add(fieldMapping);
      }
    }
View Full Code Here

   * @return The AvroFieldMapping of this field.
   */
  private FieldMapping createFieldMapping(String fieldName,
      JsonNode recordFieldJson, Map<String, Object> defaultValueMap,
      Schema.Type type) {
    FieldMapping fieldMapping = null;
    JsonNode mappingNode = recordFieldJson.get("mapping");
    if (mappingNode != null) {
      JsonNode mappingTypeNode = mappingNode.get("type");
      JsonNode mappingValueNode = mappingNode.get("value");
      JsonNode prefixValueNode = mappingNode.get("prefix");
      if (mappingTypeNode == null) {
        String msg = "mapping attribute must contain type.";
        throw new SchemaValidationException(msg);
      }

      MappingType mappingType = null;
      String mappingValue = null;
      String prefix = null;

      if (mappingTypeNode.getTextValue().equals("column")) {
        mappingType = MappingType.COLUMN;
        if (mappingValueNode == null) {
          throw new SchemaValidationException(
              "column mapping type must contain a value.");
        }
        mappingValue = mappingValueNode.getTextValue();
      } else if ((mappingTypeNode.getTextValue().equals("keyAsColumn"))) {
        mappingType = MappingType.KEY_AS_COLUMN;
        if (mappingValueNode == null) {
          throw new SchemaValidationException(
              "keyAsColumn mapping type must contain a value.");
        }
        mappingValue = mappingValueNode.getTextValue();
        if (prefixValueNode != null) {
          prefix = prefixValueNode.getTextValue();
        }
      } else if (mappingTypeNode.getTextValue().equals("counter")) {
        if (type != Schema.Type.INT && type != Schema.Type.LONG) {
          throw new SchemaValidationException("counter mapping type must be an int or a long");
        }
        if (mappingValueNode == null) {
          throw new SchemaValidationException(
              "counter mapping type must contain a value.");
        }
        mappingType = MappingType.COUNTER;
        mappingValue = mappingValueNode.getTextValue();
      } else if (mappingTypeNode.getTextValue().equals("occVersion")) {
        mappingType = MappingType.OCC_VERSION;
      } else if (mappingTypeNode.getTextValue().equals("key")) {
        mappingType = MappingType.KEY;
        if (mappingValueNode == null) {
          throw new SchemaValidationException(
              "key mapping type must contain an integer value specifying it's key order.");
        }
        mappingValue = mappingValueNode.getTextValue();
      }
      Object defaultValue = defaultValueMap.get(fieldName);
      fieldMapping = new FieldMapping(fieldName, mappingType, mappingValue,
          defaultValue, prefix);
    }
    return fieldMapping;
  }
View Full Code Here

TOP

Related Classes of com.cloudera.cdk.data.hbase.impl.EntitySchema.FieldMapping

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.