This is an automated email from the ASF dual-hosted git repository.
damondouglas pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git
The following commit(s) were added to refs/heads/master by this push:
new f8b63ff3d55 Create CsvIOParseResult (#31706)
f8b63ff3d55 is described below
commit f8b63ff3d55aeefab07020e463882225cf2350cf
Author: Damon <[email protected]>
AuthorDate: Fri Jun 28 15:04:53 2024 -0700
Create CsvIOParseResult (#31706)
---
.../sdk/io/csv/providers/CsvIOParseResult.java | 86 ++++++++++++++++++++++
1 file changed, 86 insertions(+)
diff --git
a/sdks/java/io/csv/src/main/java/org/apache/beam/sdk/io/csv/providers/CsvIOParseResult.java
b/sdks/java/io/csv/src/main/java/org/apache/beam/sdk/io/csv/providers/CsvIOParseResult.java
new file mode 100644
index 00000000000..3a6299e1591
--- /dev/null
+++
b/sdks/java/io/csv/src/main/java/org/apache/beam/sdk/io/csv/providers/CsvIOParseResult.java
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.sdk.io.csv.providers;
+
+import java.util.Map;
+import org.apache.beam.sdk.Pipeline;
+import org.apache.beam.sdk.io.csv.CsvIOParseError;
+import org.apache.beam.sdk.transforms.PTransform;
+import org.apache.beam.sdk.values.PCollection;
+import org.apache.beam.sdk.values.PCollectionTuple;
+import org.apache.beam.sdk.values.PInput;
+import org.apache.beam.sdk.values.POutput;
+import org.apache.beam.sdk.values.PValue;
+import org.apache.beam.sdk.values.TupleTag;
+import
org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.ImmutableMap;
+
+/**
+ * The {@link T} and {@link CsvIOParseError} {@link PCollection} results of
parsing CSV records. Use
+ * {@link #getOutput()} and {@link #getErrors()} to apply these results in a
pipeline.
+ */
+public class CsvIOParseResult<T> implements POutput {
+
+ static <T> CsvIOParseResult<T> of(
+ TupleTag<T> outputTag, TupleTag<CsvIOParseError> errorTag,
PCollectionTuple pct) {
+ return new CsvIOParseResult<>(outputTag, errorTag, pct);
+ }
+
+ private final Pipeline pipeline;
+ private final TupleTag<T> outputTag;
+ private final PCollection<T> output;
+ private final TupleTag<CsvIOParseError> errorTag;
+ private final PCollection<CsvIOParseError> errors;
+
+ private CsvIOParseResult(
+ TupleTag<T> outputTag, TupleTag<CsvIOParseError> errorTag,
PCollectionTuple pct) {
+ this.outputTag = outputTag;
+ this.errorTag = errorTag;
+ this.pipeline = pct.getPipeline();
+ this.output = pct.get(outputTag);
+ this.errors = pct.get(errorTag);
+ }
+
+ /** The {@link T} {@link PCollection} as a result of successfully parsing
CSV records. */
+ public PCollection<T> getOutput() {
+ return output;
+ }
+
+ /**
+ * The {@link CsvIOParseError} {@link PCollection} as a result of errors
associated with parsing
+ * CSV records.
+ */
+ public PCollection<CsvIOParseError> getErrors() {
+ return errors;
+ }
+
+ @Override
+ public Pipeline getPipeline() {
+ return pipeline;
+ }
+
+ @Override
+ public Map<TupleTag<?>, PValue> expand() {
+ return ImmutableMap.of(
+ outputTag, output,
+ errorTag, errors);
+ }
+
+ @Override
+ public void finishSpecifyingOutput(
+ String transformName, PInput input, PTransform<?, ?> transform) {}
+}