You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2023/01/14 14:54:47 UTC

[GitHub] [beam] byronellis commented on a diff in pull request #24974: Add AvroReadSchemaTransform and AvroWriteSchemaTransform

byronellis commented on code in PR #24974:
URL: https://github.com/apache/beam/pull/24974#discussion_r1070293489


##########
sdks/java/core/src/main/java/org/apache/beam/sdk/io/AvroReadSchemaTransformProvider.java:
##########
@@ -0,0 +1,122 @@
+/*
+ * 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;
+
+import com.google.auto.value.AutoValue;
+import java.io.Serializable;
+import java.util.Collections;
+import java.util.List;
+import org.apache.beam.sdk.schemas.AutoValueSchema;
+import org.apache.beam.sdk.schemas.Schema;
+import org.apache.beam.sdk.schemas.annotations.DefaultSchema;
+import org.apache.beam.sdk.schemas.transforms.Convert;
+import org.apache.beam.sdk.schemas.transforms.SchemaTransform;
+import org.apache.beam.sdk.schemas.transforms.TypedSchemaTransformProvider;
+import org.apache.beam.sdk.schemas.utils.AvroUtils;
+import org.apache.beam.sdk.transforms.PTransform;
+import org.apache.beam.sdk.values.PCollectionRowTuple;
+import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Strings;
+
+public class AvroReadSchemaTransformProvider
+    extends TypedSchemaTransformProvider<
+        AvroReadSchemaTransformProvider.AvroReadSchemaTransformConfiguration> {
+  @Override
+  public String identifier() {
+    return "beam:schematransform:org.apache.beam:avro_read:v1";
+  }
+
+  @Override
+  public List<String> inputCollectionNames() {
+    return Collections.emptyList();
+  }
+
+  @Override
+  public List<String> outputCollectionNames() {
+    return Collections.singletonList("output");
+  }
+
+  @Override
+  protected Class<AvroReadSchemaTransformConfiguration> configurationClass() {
+    return AvroReadSchemaTransformConfiguration.class;
+  }
+
+  @Override
+  protected SchemaTransform from(AvroReadSchemaTransformConfiguration configuration) {
+    return new AvroReadSchemaTransform(configuration);
+  }
+
+  static class AvroReadSchemaTransform implements SchemaTransform {
+
+    AvroReadSchemaTransformConfiguration config;
+
+    AvroReadSchemaTransform(AvroReadSchemaTransformConfiguration config) {
+      this.config = config;
+    }
+
+    @Override
+    public PTransform<PCollectionRowTuple, PCollectionRowTuple> buildTransform() {
+      return new PTransform<PCollectionRowTuple, PCollectionRowTuple>() {
+        @Override
+        public PCollectionRowTuple expand(PCollectionRowTuple input) {

Review Comment:
   Moved expansion to its own class for clarity



##########
sdks/java/core/src/main/java/org/apache/beam/sdk/io/AvroWriteSchemaTransformProvider.java:
##########
@@ -0,0 +1,141 @@
+/*
+ * 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;
+
+import com.google.auto.value.AutoValue;
+import java.io.Serializable;
+import java.util.Collections;
+import java.util.List;
+import javax.annotation.Nullable;
+import org.apache.avro.generic.GenericRecord;
+import org.apache.beam.sdk.schemas.AutoValueSchema;
+import org.apache.beam.sdk.schemas.Schema;
+import org.apache.beam.sdk.schemas.annotations.DefaultSchema;
+import org.apache.beam.sdk.schemas.transforms.Convert;
+import org.apache.beam.sdk.schemas.transforms.SchemaTransform;
+import org.apache.beam.sdk.schemas.transforms.TypedSchemaTransformProvider;
+import org.apache.beam.sdk.schemas.utils.AvroUtils;
+import org.apache.beam.sdk.transforms.PTransform;
+import org.apache.beam.sdk.transforms.windowing.FixedWindows;
+import org.apache.beam.sdk.transforms.windowing.Window;
+import org.apache.beam.sdk.values.PCollection;
+import org.apache.beam.sdk.values.PCollectionRowTuple;
+import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Strings;
+import org.joda.time.Duration;
+
+public class AvroWriteSchemaTransformProvider
+    extends TypedSchemaTransformProvider<
+        AvroWriteSchemaTransformProvider.AvroWriteSchemaTransformConfiguration> {
+  @Override
+  public String identifier() {
+    return "beam:schematransform:org.apache.beam:avro_write:v1";
+  }
+
+  @Override
+  public List<String> inputCollectionNames() {
+    return Collections.singletonList("input");
+  }
+
+  @Override
+  public List<String> outputCollectionNames() {
+    return Collections.emptyList();
+  }
+
+  @Override
+  protected Class<AvroWriteSchemaTransformConfiguration> configurationClass() {
+    return AvroWriteSchemaTransformConfiguration.class;
+  }
+
+  @Override
+  protected SchemaTransform from(AvroWriteSchemaTransformConfiguration configuration) {
+    return new AvroWriteSchemaTransform(configuration);
+  }
+
+  static class AvroWriteSchemaTransform implements SchemaTransform, Serializable {
+
+    AvroWriteSchemaTransformConfiguration config;
+
+    AvroWriteSchemaTransform(AvroWriteSchemaTransformConfiguration config) {
+      this.config = config;
+    }
+
+    @Override
+    public PTransform<PCollectionRowTuple, PCollectionRowTuple> buildTransform() {

Review Comment:
   Same



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org