private final String type;
private final ByteArrayValueMapper byteArrayMapper;
// also see ByteArrayExtractors
public Mapping(Config config, MorphlineContext context) {
Configs configs = new Configs();
this.inputColumn = resolveColumnName(configs.getString(config, "inputColumn"));
this.columnFamily = Bytes.toBytes(splitFamilyAndQualifier(inputColumn)[0]);
String qualifierString = splitFamilyAndQualifier(inputColumn)[1];
this.isWildCard = qualifierString.endsWith("*");
if (isWildCard) {
qualifierString = qualifierString.substring(0, qualifierString.length() - 1);
}
this.qualifier = Bytes.toBytes(qualifierString);
String outputField = configs.getString(config, "outputField", null);
this.outputFieldNames = configs.getStringList(config, "outputFields", null);
if (outputField == null && outputFieldNames == null) {
throw new MorphlineCompilationException("Either outputField or outputFields must be defined", config);
}
if (outputField != null && outputFieldNames != null) {
throw new MorphlineCompilationException("Must not define both outputField and outputFields at the same time", config);
}
if (outputField == null) {
this.isDynamicOutputFieldName = false;
this.outputFieldName = null;
} else {
this.isDynamicOutputFieldName = outputField.endsWith("*");
if (isDynamicOutputFieldName) {
this.outputFieldName = outputField.substring(0, outputField.length() - 1);
} else {
this.outputFieldName = outputField;
}
}
this.type = configs.getString(config, "type", "byte[]");
if (type.equals("byte[]")) { // pass through byte[] to downstream morphline commands without conversion
this.byteArrayMapper = new ByteArrayValueMapper() {
@Override
public Collection map(byte[] input) {
return Collections.singletonList(input);
}
};
} else {
this.byteArrayMapper = ByteArrayValueMappers.getMapper(type);
}
LowerCaseValueSource source = new Validator<LowerCaseValueSource>().validateEnum(config,
configs.getString(config, "source", LowerCaseValueSource.value.toString()),
LowerCaseValueSource.class);
if (source == LowerCaseValueSource.value) {
if (isWildCard) {
this.extractor = new PrefixMatchingCellExtractor(columnFamily, qualifier);
} else {
this.extractor = new SingleCellExtractor(columnFamily, qualifier);
}
} else {
if (isWildCard) {
this.extractor = new PrefixMatchingQualifierExtractor(columnFamily, qualifier);
} else {
throw new IllegalArgumentException("Can't create a non-prefix-based qualifier extractor");
}
}
configs.validateArguments(config);
if (context instanceof HBaseMorphlineContext) {
((HBaseMorphlineContext)context).getExtractors().add(this.extractor);
}
}