use of co.cask.cdap.api.dataset.lib.Partitioning.FieldType in project cdap by caskdata.
the class PartitionedFileSetArguments method getOutputPartitionKey.
/**
* @return the partition key of the output partition to be written; or null if no partition key was found
*
* @param arguments the runtime arguments for a partitioned dataset
* @param partitioning the declared partitioning for the dataset, needed for proper interpretation of values
*/
@Nullable
public static PartitionKey getOutputPartitionKey(Map<String, String> arguments, Partitioning partitioning) {
// extract the arguments that describe the output partition key
Map<String, String> keyArguments = FileSetProperties.propertiesWithPrefix(arguments, OUTPUT_PARTITION_KEY_PREFIX);
if (keyArguments.isEmpty()) {
// there is no output partition key
return null;
}
// there is a partition key; now it is required to match the partitioning
PartitionKey.Builder builder = PartitionKey.builder();
for (Map.Entry<String, FieldType> entry : partitioning.getFields().entrySet()) {
String fieldName = entry.getKey();
FieldType fieldType = entry.getValue();
String stringValue = keyArguments.get(fieldName);
Comparable fieldValue = convertFieldValue("key", "value", fieldName, fieldType, stringValue, false);
builder.addField(fieldName, fieldValue);
}
return builder.build();
}
Aggregations