Search in sources :

Example 16 with GlobalMetadata

use of org.apache.gobblin.metadata.types.GlobalMetadata in project incubator-gobblin by apache.

the class MetadataWriterWrapper method writeMetadata.

/**
 * Write combined metadata to the {@link ConfigurationKeys#WRITER_METADATA_KEY} parameter.
 */
protected void writeMetadata() throws IOException {
    Set<GlobalMetadata> collectedMetadata = metadataCollector.getMetadataRecords();
    if (collectedMetadata.isEmpty()) {
        return;
    }
    String propName = ForkOperatorUtils.getPropertyNameForBranch(ConfigurationKeys.WRITER_METADATA_KEY, numBranches, branchId);
    String metadataStr;
    if (collectedMetadata.size() == 1) {
        metadataStr = collectedMetadata.iterator().next().toJson();
    } else {
        StringBuilder sb = new StringBuilder();
        sb.append('[');
        boolean first = true;
        for (GlobalMetadata md : collectedMetadata) {
            if (!first) {
                sb.append(',');
            }
            sb.append(md.toJson());
            first = false;
        }
        sb.append(']');
        metadataStr = sb.toString();
    }
    this.properties.setProp(propName, metadataStr);
}
Also used : GlobalMetadata(org.apache.gobblin.metadata.types.GlobalMetadata)

Aggregations

GlobalMetadata (org.apache.gobblin.metadata.types.GlobalMetadata)16 Test (org.testng.annotations.Test)9 File (java.io.File)5 State (org.apache.gobblin.configuration.State)5 WorkUnitState (org.apache.gobblin.configuration.WorkUnitState)5 FsWriterMetrics (org.apache.gobblin.writer.FsWriterMetrics)5 TaskState (org.apache.hadoop.mapreduce.v2.api.records.TaskState)5 FileInputStream (java.io.FileInputStream)3 FileOutputStream (java.io.FileOutputStream)2 InputStream (java.io.InputStream)2 ImmutableList (com.google.common.collect.ImmutableList)1 Files (com.google.common.io.Files)1 ConfigFactory (com.typesafe.config.ConfigFactory)1 IOException (java.io.IOException)1 StandardCharsets (java.nio.charset.StandardCharsets)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1