public FieldMapping getFieldMapping(String fieldName) { for (FieldMapping fm : fieldMappings) { if (fm.getFieldName().equals(fieldName)) { return fm; } } return null; }
private static PartitionStrategy buildPartitionStrategyForKeyMappings( Map<Integer, FieldMapping> keyMappings) { PartitionStrategy.Builder builder = new PartitionStrategy.Builder(); for (Integer index : new TreeSet<Integer>(keyMappings.keySet())) { builder.identity(keyMappings.get(index).getFieldName()); } return builder.build(); }
/** * Initialize the AvroRecordBuilderFactories for all keyAsColumn mapped fields * that are record types. We need to be able to get record builders for these * since the records are broken across many columns, and need to be * constructed by the composer. */ private void initRecordBuilderFactories() { for (FieldMapping fieldMapping : avroSchema.getColumnMappingDescriptor().getFieldMappings()) { if (fieldMapping.getMappingType() == MappingType.KEY_AS_COLUMN) { String fieldName = fieldMapping.getFieldName(); Schema fieldSchema = avroSchema.getAvroSchema().getField(fieldName) .schema(); Schema.Type fieldSchemaType = fieldSchema.getType(); if (fieldSchemaType == Schema.Type.RECORD) { AvroRecordBuilderFactory<E> factory = buildAvroRecordBuilderFactory(fieldSchema); kacRecordBuilderFactories.put(fieldName, factory); } } } }
/** * Initialize the AvroRecordBuilderFactories for all keyAsColumn mapped fields * that are record types. We need to be able to get record builders for these * since the records are broken across many columns, and need to be * constructed by the composer. */ private void initRecordBuilderFactories() { for (FieldMapping fieldMapping : avroSchema.getColumnMappingDescriptor().getFieldMappings()) { if (fieldMapping.getMappingType() == MappingType.KEY_AS_COLUMN) { String fieldName = fieldMapping.getFieldName(); Schema fieldSchema = avroSchema.getAvroSchema().getField(fieldName) .schema(); Schema.Type fieldSchemaType = fieldSchema.getType(); if (fieldSchemaType == Schema.Type.RECORD) { AvroRecordBuilderFactory<E> factory = buildAvroRecordBuilderFactory(fieldSchema); kacRecordBuilderFactories.put(fieldName, factory); } } } }
/** * Deserialize an entity field from the HBase Result. * * @param fieldMapping * The FieldMapping that specifies this field's mapping type and * field name. * @param result * The HBase Result that represents a row in HBase. * @return The field Object we deserialized from the Result. */ public Object deserialize(FieldMapping fieldMapping, Result result) { String fieldName = fieldMapping.getFieldName(); MappingType mappingType = fieldMapping.getMappingType(); if (mappingType == MappingType.COLUMN || mappingType == MappingType.COUNTER) { return deserializeColumn(fieldMapping.getFieldName(), fieldMapping.getFamily(), fieldMapping.getQualifier(), result); } else if (mappingType == MappingType.KEY_AS_COLUMN) { return deserializeKeyAsColumn(fieldMapping.getFieldName(), fieldMapping.getFamily(), fieldMapping.getPrefix(), result); } else if (mappingType == MappingType.OCC_VERSION) { return deserializeOCCColumn(result); } else { throw new ValidationException( "Invalid field mapping for field with name: " + fieldName); } }
Set<String> keyMappedFields = Sets.newHashSet(); for (FieldMapping fm : mappings.getFieldMappings()) { Schema fieldSchema = SchemaUtil.fieldSchema(schema, fm.getFieldName()); ValidationException.check( SchemaUtil.isConsistentWithMappingType( fieldSchema.getType(), fm); if (FieldMapping.MappingType.KEY == fm.getMappingType()) { keyMappedFields.add(fm.getFieldName());
/** * Deserialize an entity field from the HBase Result. * * @param fieldMapping * The FieldMapping that specifies this field's mapping type and * field name. * @param result * The HBase Result that represents a row in HBase. * @return The field Object we deserialized from the Result. */ public Object deserialize(FieldMapping fieldMapping, Result result) { String fieldName = fieldMapping.getFieldName(); MappingType mappingType = fieldMapping.getMappingType(); if (mappingType == MappingType.COLUMN || mappingType == MappingType.COUNTER) { return deserializeColumn(fieldMapping.getFieldName(), fieldMapping.getFamily(), fieldMapping.getQualifier(), result); } else if (mappingType == MappingType.KEY_AS_COLUMN) { return deserializeKeyAsColumn(fieldMapping.getFieldName(), fieldMapping.getFamily(), fieldMapping.getPrefix(), result); } else if (mappingType == MappingType.OCC_VERSION) { return deserializeOCCColumn(result); } else { throw new ValidationException( "Invalid field mapping for field with name: " + fieldName); } }
private static JsonNode toJson(FieldMapping fm) { ObjectNode fieldMapping = JsonNodeFactory.instance.objectNode(); fieldMapping.set(SOURCE, TextNode.valueOf(fm.getFieldName())); switch (fm.getMappingType()) { case KEY:
/** * Ensure that the column mappings for the shared fields between the old and * new schema haven't changed. * * @param oldSchema * @param newSchema * @return true if the mappings are compatible, false if not. */ private static boolean mappingCompatible(EntitySchema oldSchema, EntitySchema newSchema) { for (FieldMapping oldFieldMapping : oldSchema.getColumnMappingDescriptor() .getFieldMappings()) { FieldMapping newFieldMapping = newSchema.getColumnMappingDescriptor() .getFieldMapping(oldFieldMapping.getFieldName()); if (newFieldMapping != null) { if (!oldFieldMapping.equals(newFieldMapping)) { return false; } } } return true; }
/** * Ensure that the column mappings for the shared fields between the old and * new schema haven't changed. * * @param oldSchema * @param newSchema * @return true if the mappings are compatible, false if not. */ private static boolean mappingCompatible(EntitySchema oldSchema, EntitySchema newSchema) { for (FieldMapping oldFieldMapping : oldSchema.getColumnMappingDescriptor() .getFieldMappings()) { FieldMapping newFieldMapping = newSchema.getColumnMappingDescriptor() .getFieldMapping(oldFieldMapping.getFieldName()); if (newFieldMapping != null) { if (!oldFieldMapping.equals(newFieldMapping)) { return false; } } } return true; }
@Override public PutAction mapFromEntity(E entity) { List<PutAction> putActionList = new ArrayList<PutAction>(); byte[] keyBytes; if (keySchema == null || keySerDe == null) { keyBytes = new byte[] { (byte) 0 }; } else { keyBytes = keySerDe.serialize(mapToKey(entity)); } for (FieldMapping fieldMapping : entitySchema.getColumnMappingDescriptor() .getFieldMappings()) { if (fieldMapping.getMappingType() == MappingType.KEY) { continue; } Object fieldValue = getEntityComposer().extractField(entity, fieldMapping.getFieldName()); if (fieldValue != null) { PutAction put = entitySerDe.serialize(keyBytes, fieldMapping, fieldValue); putActionList.add(put); } } return HBaseUtils.mergePutActions(keyBytes, putActionList); }
@Override public PutAction mapFromEntity(E entity) { List<PutAction> putActionList = new ArrayList<PutAction>(); byte[] keyBytes; if (keySchema == null || keySerDe == null) { keyBytes = new byte[] { (byte) 0 }; } else { keyBytes = keySerDe.serialize(mapToKey(entity)); } for (FieldMapping fieldMapping : entitySchema.getColumnMappingDescriptor() .getFieldMappings()) { if (fieldMapping.getMappingType() == MappingType.KEY) { continue; } Object fieldValue = getEntityComposer().extractField(entity, fieldMapping.getFieldName()); if (fieldValue != null) { PutAction put = entitySerDe.serialize(keyBytes, fieldMapping, fieldValue); putActionList.add(put); } } return HBaseUtils.mergePutActions(keyBytes, putActionList); }
Put put = new Put(keyBytes); PutAction putAction = new PutAction(put); String fieldName = fieldMapping.getFieldName(); if (fieldMapping.getMappingType() == MappingType.COLUMN || fieldMapping.getMappingType() == MappingType.COUNTER) { throw new ValidationException( "Invalid field mapping for field with name: " + fieldMapping.getFieldName());
Put put = new Put(keyBytes); PutAction putAction = new PutAction(put); String fieldName = fieldMapping.getFieldName(); if (fieldMapping.getMappingType() == MappingType.COLUMN || fieldMapping.getMappingType() == MappingType.COUNTER) { throw new ValidationException( "Invalid field mapping for field with name: " + fieldMapping.getFieldName());
.getColumnMappingDescriptor().getFieldMappings()) { if (fieldMapping.getMappingType() == MappingType.OCC_VERSION) { LOG.warn("Field: " + fieldMapping.getFieldName() + " in schema " + entitySchema2.getName() + " conflicts with an occVersion field in "
.getColumnMappingDescriptor().getFieldMappings()) { if (fieldMapping.getMappingType() == MappingType.OCC_VERSION) { LOG.warn("Field: " + fieldMapping.getFieldName() + " in schema " + entitySchema2.getName() + " conflicts with an occVersion field in "
String fieldName = fieldMapping.getFieldName(); Schema fieldSchema = avroSchema.getAvroSchema().getField(fieldName) .schema();
String fieldName = fieldMapping.getFieldName(); Schema fieldSchema = avroSchema.getAvroSchema().getField(fieldName) .schema();
keySchema.position(fieldMapping.getFieldName())); } else { builder.put(fieldMapping.getFieldName(), fieldValue);
keySchema.position(fieldMapping.getFieldName())); } else { builder.put(fieldMapping.getFieldName(), fieldValue);