From 7c07f7ff453ebdc45cbe7d9bda50cf2d5c930f57 Mon Sep 17 00:00:00 2001 From: lahariguduru <108150650+lahariguduru@users.noreply.github.com> Date: Sat, 13 Jul 2024 00:13:14 +0000 Subject: [PATCH] Create CsvIOParse scaffold (#31878) Co-authored-by: Lahari Guduru --- .../apache/beam/sdk/io/csv/CsvIOParse.java | 57 +++++++++++++++++++ .../beam/sdk/io/csv/CsvIOParseTest.java | 32 +++++++++++ 2 files changed, 89 insertions(+) create mode 100644 sdks/java/io/csv/src/main/java/org/apache/beam/sdk/io/csv/CsvIOParse.java create mode 100644 sdks/java/io/csv/src/test/java/org/apache/beam/sdk/io/csv/CsvIOParseTest.java diff --git a/sdks/java/io/csv/src/main/java/org/apache/beam/sdk/io/csv/CsvIOParse.java b/sdks/java/io/csv/src/main/java/org/apache/beam/sdk/io/csv/CsvIOParse.java new file mode 100644 index 000000000000..3a3ffccf4888 --- /dev/null +++ b/sdks/java/io/csv/src/main/java/org/apache/beam/sdk/io/csv/CsvIOParse.java @@ -0,0 +1,57 @@ +/* + * 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; + +import org.apache.beam.sdk.schemas.Schema; +import org.apache.beam.sdk.transforms.DoFn; +import org.apache.beam.sdk.transforms.PTransform; +import org.apache.beam.sdk.transforms.ParDo; +import org.apache.beam.sdk.values.PCollection; + +/** + * CsvIO master class that takes an input of {@link PCollection} and outputs custom type + * {@link PCollection}. + */ +// TODO(https://github.com/apache/beam/issues/31877): Plan for implementation after all dependencies +// are completed. +class CsvIOParse extends PTransform, PCollection> { + + /** Stores required parameters for parsing. */ + private final CsvIOParseConfiguration.Builder configBuilder; + + CsvIOParse(CsvIOParseConfiguration.Builder configBuilder) { + this.configBuilder = configBuilder; + } + + @Override + public PCollection expand(PCollection input) { + // TODO: Remove dependency to build CsvIOConfiguration with future PR, needed to pass checks. + configBuilder.build(); + return input.apply(ParDo.of(new DoFn() {})); + } + + /** Parses to custom type not specified under {@link Schema.FieldType}. */ + // TODO(https://github.com/apache/beam/issues/31875): Implement method. + void withCustomRecordParsing() {} + + /** Parses cell to emit the value, as well as potential errors with filename. */ + // TODO(https://github.com/apache/beam/issues/31876):Implement method. + Object parseCell(String cell, Schema.Field field) { + return ""; + } +} diff --git a/sdks/java/io/csv/src/test/java/org/apache/beam/sdk/io/csv/CsvIOParseTest.java b/sdks/java/io/csv/src/test/java/org/apache/beam/sdk/io/csv/CsvIOParseTest.java new file mode 100644 index 000000000000..7c3acb360b2d --- /dev/null +++ b/sdks/java/io/csv/src/test/java/org/apache/beam/sdk/io/csv/CsvIOParseTest.java @@ -0,0 +1,32 @@ +/* + * 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; + +import org.apache.beam.sdk.util.SerializableUtils; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** Tests for {@link CsvIOParse}. */ +@RunWith(JUnit4.class) +public class CsvIOParseTest { + @Test + public void isSerializable() { + SerializableUtils.ensureSerializable(CsvIOParse.class); + } +}