Search in sources :

Example 6 with FieldType

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();
}
Also used : Map(java.util.Map) FieldType(co.cask.cdap.api.dataset.lib.Partitioning.FieldType) Nullable(javax.annotation.Nullable)

Aggregations

FieldType (co.cask.cdap.api.dataset.lib.Partitioning.FieldType)6 Map (java.util.Map)6 ImmutableMap (com.google.common.collect.ImmutableMap)5 HashMap (java.util.HashMap)5 PartitionFilter (co.cask.cdap.api.dataset.lib.PartitionFilter)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 PartitionKey (co.cask.cdap.api.dataset.lib.PartitionKey)1 Nullable (javax.annotation.Nullable)1