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 2021/01/05 23:44:46 UTC

[GitHub] [beam] iemejia opened a new pull request #13671: [BEAM-11571] Support Conversion to GenericRecords in Convert.to transform

iemejia opened a new pull request #13671:
URL: https://github.com/apache/beam/pull/13671


   R: @TheNeuralBit 
   CC: @reuvenlax 


----------------------------------------------------------------
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.

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



[GitHub] [beam] iemejia commented on a change in pull request #13671: [BEAM-11571] Support Conversion to GenericRecords in Convert.to transform

Posted by GitBox <gi...@apache.org>.
iemejia commented on a change in pull request #13671:
URL: https://github.com/apache/beam/pull/13671#discussion_r552265658



##########
File path: sdks/java/core/src/main/java/org/apache/beam/sdk/io/GenericRecordWriteConverter.java
##########
@@ -1,67 +0,0 @@
-/*
- * 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 org.apache.avro.generic.GenericRecord;
-import org.apache.beam.sdk.coders.AvroCoder;
-import org.apache.beam.sdk.schemas.Schema;
-import org.apache.beam.sdk.schemas.utils.AvroUtils;
-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;
-import org.apache.beam.sdk.values.Row;
-
-/** A {@link PTransform} to convert {@link Row} to {@link GenericRecord}. */
-@AutoValue
-public abstract class GenericRecordWriteConverter

Review comment:
       This class was 'wrongly' exposed and missing the `@Internal` annotation, that's why I went straight to remove it.




----------------------------------------------------------------
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.

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



[GitHub] [beam] iemejia commented on pull request #13671: [BEAM-11571] Support Conversion to GenericRecords in Convert.to transform

Posted by GitBox <gi...@apache.org>.
iemejia commented on pull request #13671:
URL: https://github.com/apache/beam/pull/13671#issuecomment-757112734


   Merged manually to fix a minor conflict on CHANGES.md 


----------------------------------------------------------------
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.

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



[GitHub] [beam] TheNeuralBit commented on a change in pull request #13671: [BEAM-11571] Support Conversion to GenericRecords in Convert.to transform

Posted by GitBox <gi...@apache.org>.
TheNeuralBit commented on a change in pull request #13671:
URL: https://github.com/apache/beam/pull/13671#discussion_r554212074



##########
File path: sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/utils/ConvertHelpers.java
##########
@@ -78,12 +83,15 @@ public ConvertedSchemaInformation(
   public static <T> ConvertedSchemaInformation<T> getConvertedSchemaInformation(
       Schema inputSchema, TypeDescriptor<T> outputType, SchemaRegistry schemaRegistry) {
     ConvertedSchemaInformation<T> convertedSchema = null;
-    boolean toRow = outputType.equals(TypeDescriptor.of(Row.class));
-    if (toRow) {
+    if (outputType.equals(TypeDescriptor.of(Row.class))) {
       // If the output is of type Row, then just forward the schema of the input type to the
       // output.
       convertedSchema =
           new ConvertedSchemaInformation<>((SchemaCoder<T>) SchemaCoder.of(inputSchema), null);
+    } else if (outputType.equals(TypeDescriptor.of(GenericRecord.class))) {
+      convertedSchema =
+          new ConvertedSchemaInformation<T>(
+              (SchemaCoder<T>) AvroUtils.schemaCoder(AvroUtils.toAvroSchema(inputSchema)), null);

Review comment:
       Hm it seems like this should be generalized somehow so we don't need to have if blocks for converting to every "dynamic" class. For example we might want something similar for protobuf's DynamicMessage. Something pluggable like SchemaProvider, but for making conversions to/from other dynamic row types.
   
   This is fine for now, but maybe drop a TODO and jira about generalizing?




----------------------------------------------------------------
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.

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



[GitHub] [beam] iemejia commented on a change in pull request #13671: [BEAM-11571] Support Conversion to GenericRecords in Convert.to transform

Posted by GitBox <gi...@apache.org>.
iemejia commented on a change in pull request #13671:
URL: https://github.com/apache/beam/pull/13671#discussion_r554306591



##########
File path: sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/utils/ConvertHelpers.java
##########
@@ -78,12 +83,15 @@ public ConvertedSchemaInformation(
   public static <T> ConvertedSchemaInformation<T> getConvertedSchemaInformation(
       Schema inputSchema, TypeDescriptor<T> outputType, SchemaRegistry schemaRegistry) {
     ConvertedSchemaInformation<T> convertedSchema = null;
-    boolean toRow = outputType.equals(TypeDescriptor.of(Row.class));
-    if (toRow) {
+    if (outputType.equals(TypeDescriptor.of(Row.class))) {
       // If the output is of type Row, then just forward the schema of the input type to the
       // output.
       convertedSchema =
           new ConvertedSchemaInformation<>((SchemaCoder<T>) SchemaCoder.of(inputSchema), null);
+    } else if (outputType.equals(TypeDescriptor.of(GenericRecord.class))) {
+      convertedSchema =
+          new ConvertedSchemaInformation<T>(
+              (SchemaCoder<T>) AvroUtils.schemaCoder(AvroUtils.toAvroSchema(inputSchema)), null);

Review comment:
       Agree, I will fill a JIRA and add TODO for this in a subsequent PR. I am going to merge this as it is because I have some pending PRs on top of these changes. Thanks!




----------------------------------------------------------------
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.

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



[GitHub] [beam] iemejia commented on pull request #13671: [BEAM-11571] Support Conversion to GenericRecords in Convert.to transform

Posted by GitBox <gi...@apache.org>.
iemejia commented on pull request #13671:
URL: https://github.com/apache/beam/pull/13671#issuecomment-757112734


   Merged manually to fix a minor conflict on CHANGES.md 


----------------------------------------------------------------
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.

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



[GitHub] [beam] iemejia commented on a change in pull request #13671: [BEAM-11571] Support Conversion to GenericRecords in Convert.to transform

Posted by GitBox <gi...@apache.org>.
iemejia commented on a change in pull request #13671:
URL: https://github.com/apache/beam/pull/13671#discussion_r585570049



##########
File path: sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/utils/ConvertHelpers.java
##########
@@ -78,12 +83,15 @@ public ConvertedSchemaInformation(
   public static <T> ConvertedSchemaInformation<T> getConvertedSchemaInformation(
       Schema inputSchema, TypeDescriptor<T> outputType, SchemaRegistry schemaRegistry) {
     ConvertedSchemaInformation<T> convertedSchema = null;
-    boolean toRow = outputType.equals(TypeDescriptor.of(Row.class));
-    if (toRow) {
+    if (outputType.equals(TypeDescriptor.of(Row.class))) {
       // If the output is of type Row, then just forward the schema of the input type to the
       // output.
       convertedSchema =
           new ConvertedSchemaInformation<>((SchemaCoder<T>) SchemaCoder.of(inputSchema), null);
+    } else if (outputType.equals(TypeDescriptor.of(GenericRecord.class))) {
+      convertedSchema =
+          new ConvertedSchemaInformation<T>(
+              (SchemaCoder<T>) AvroUtils.schemaCoder(AvroUtils.toAvroSchema(inputSchema)), null);

Review comment:
       Jira created sorry I had not forgotten, just too long backlog :)
   https://issues.apache.org/jira/browse/BEAM-11911




----------------------------------------------------------------
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.

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



[GitHub] [beam] TheNeuralBit commented on a change in pull request #13671: [BEAM-11571] Support Conversion to GenericRecords in Convert.to transform

Posted by GitBox <gi...@apache.org>.
TheNeuralBit commented on a change in pull request #13671:
URL: https://github.com/apache/beam/pull/13671#discussion_r554212074



##########
File path: sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/utils/ConvertHelpers.java
##########
@@ -78,12 +83,15 @@ public ConvertedSchemaInformation(
   public static <T> ConvertedSchemaInformation<T> getConvertedSchemaInformation(
       Schema inputSchema, TypeDescriptor<T> outputType, SchemaRegistry schemaRegistry) {
     ConvertedSchemaInformation<T> convertedSchema = null;
-    boolean toRow = outputType.equals(TypeDescriptor.of(Row.class));
-    if (toRow) {
+    if (outputType.equals(TypeDescriptor.of(Row.class))) {
       // If the output is of type Row, then just forward the schema of the input type to the
       // output.
       convertedSchema =
           new ConvertedSchemaInformation<>((SchemaCoder<T>) SchemaCoder.of(inputSchema), null);
+    } else if (outputType.equals(TypeDescriptor.of(GenericRecord.class))) {
+      convertedSchema =
+          new ConvertedSchemaInformation<T>(
+              (SchemaCoder<T>) AvroUtils.schemaCoder(AvroUtils.toAvroSchema(inputSchema)), null);

Review comment:
       Hm it seems like this should be generalized somehow so we don't need to have if blocks for converting to every class that doesn't encode schema information itself. For example we might want something similar for protobuf's DynamicMessage. Something pluggable like SchemaProvider, but for making conversions to/from other dynamic row types.
   
   This is fine for now, but maybe drop a TODO and jira about generalizing?

##########
File path: sdks/java/core/src/main/java/org/apache/beam/sdk/io/GenericRecordWriteConverter.java
##########
@@ -1,67 +0,0 @@
-/*
- * 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 org.apache.avro.generic.GenericRecord;
-import org.apache.beam.sdk.coders.AvroCoder;
-import org.apache.beam.sdk.schemas.Schema;
-import org.apache.beam.sdk.schemas.utils.AvroUtils;
-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;
-import org.apache.beam.sdk.values.Row;
-
-/** A {@link PTransform} to convert {@link Row} to {@link GenericRecord}. */
-@AutoValue
-public abstract class GenericRecordWriteConverter

Review comment:
       Thanks for fixing this, sorry I didn't catch the error :grimacing: 




----------------------------------------------------------------
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.

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



[GitHub] [beam] iemejia commented on a change in pull request #13671: [BEAM-11571] Support Conversion to GenericRecords in Convert.to transform

Posted by GitBox <gi...@apache.org>.
iemejia commented on a change in pull request #13671:
URL: https://github.com/apache/beam/pull/13671#discussion_r554306591



##########
File path: sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/utils/ConvertHelpers.java
##########
@@ -78,12 +83,15 @@ public ConvertedSchemaInformation(
   public static <T> ConvertedSchemaInformation<T> getConvertedSchemaInformation(
       Schema inputSchema, TypeDescriptor<T> outputType, SchemaRegistry schemaRegistry) {
     ConvertedSchemaInformation<T> convertedSchema = null;
-    boolean toRow = outputType.equals(TypeDescriptor.of(Row.class));
-    if (toRow) {
+    if (outputType.equals(TypeDescriptor.of(Row.class))) {
       // If the output is of type Row, then just forward the schema of the input type to the
       // output.
       convertedSchema =
           new ConvertedSchemaInformation<>((SchemaCoder<T>) SchemaCoder.of(inputSchema), null);
+    } else if (outputType.equals(TypeDescriptor.of(GenericRecord.class))) {
+      convertedSchema =
+          new ConvertedSchemaInformation<T>(
+              (SchemaCoder<T>) AvroUtils.schemaCoder(AvroUtils.toAvroSchema(inputSchema)), null);

Review comment:
       Agree, I will fill a JIRA and add TODO for this in a subsequent PR. I am going to merge this as it is because I have some pending PRs on top of these changes. Thanks!

##########
File path: sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/utils/ConvertHelpers.java
##########
@@ -78,12 +83,15 @@ public ConvertedSchemaInformation(
   public static <T> ConvertedSchemaInformation<T> getConvertedSchemaInformation(
       Schema inputSchema, TypeDescriptor<T> outputType, SchemaRegistry schemaRegistry) {
     ConvertedSchemaInformation<T> convertedSchema = null;
-    boolean toRow = outputType.equals(TypeDescriptor.of(Row.class));
-    if (toRow) {
+    if (outputType.equals(TypeDescriptor.of(Row.class))) {
       // If the output is of type Row, then just forward the schema of the input type to the
       // output.
       convertedSchema =
           new ConvertedSchemaInformation<>((SchemaCoder<T>) SchemaCoder.of(inputSchema), null);
+    } else if (outputType.equals(TypeDescriptor.of(GenericRecord.class))) {
+      convertedSchema =
+          new ConvertedSchemaInformation<T>(
+              (SchemaCoder<T>) AvroUtils.schemaCoder(AvroUtils.toAvroSchema(inputSchema)), null);

Review comment:
       Agree, I will fill a JIRA and add TODO + improve a bit the Javadoc in a future PR. I am going to merge this as it is because I have some pending PRs on top of these changes. Thanks!




----------------------------------------------------------------
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.

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



[GitHub] [beam] TheNeuralBit commented on a change in pull request #13671: [BEAM-11571] Support Conversion to GenericRecords in Convert.to transform

Posted by GitBox <gi...@apache.org>.
TheNeuralBit commented on a change in pull request #13671:
URL: https://github.com/apache/beam/pull/13671#discussion_r554212074



##########
File path: sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/utils/ConvertHelpers.java
##########
@@ -78,12 +83,15 @@ public ConvertedSchemaInformation(
   public static <T> ConvertedSchemaInformation<T> getConvertedSchemaInformation(
       Schema inputSchema, TypeDescriptor<T> outputType, SchemaRegistry schemaRegistry) {
     ConvertedSchemaInformation<T> convertedSchema = null;
-    boolean toRow = outputType.equals(TypeDescriptor.of(Row.class));
-    if (toRow) {
+    if (outputType.equals(TypeDescriptor.of(Row.class))) {
       // If the output is of type Row, then just forward the schema of the input type to the
       // output.
       convertedSchema =
           new ConvertedSchemaInformation<>((SchemaCoder<T>) SchemaCoder.of(inputSchema), null);
+    } else if (outputType.equals(TypeDescriptor.of(GenericRecord.class))) {
+      convertedSchema =
+          new ConvertedSchemaInformation<T>(
+              (SchemaCoder<T>) AvroUtils.schemaCoder(AvroUtils.toAvroSchema(inputSchema)), null);

Review comment:
       Hm it seems like this should be generalized somehow so we don't need to have if blocks for converting to every class that doesn't encode schema information itself. For example we might want something similar for protobuf's DynamicMessage. Something pluggable like SchemaProvider, but for making conversions to/from other dynamic row types.
   
   This is fine for now, but maybe drop a TODO and jira about generalizing?

##########
File path: sdks/java/core/src/main/java/org/apache/beam/sdk/io/GenericRecordWriteConverter.java
##########
@@ -1,67 +0,0 @@
-/*
- * 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 org.apache.avro.generic.GenericRecord;
-import org.apache.beam.sdk.coders.AvroCoder;
-import org.apache.beam.sdk.schemas.Schema;
-import org.apache.beam.sdk.schemas.utils.AvroUtils;
-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;
-import org.apache.beam.sdk.values.Row;
-
-/** A {@link PTransform} to convert {@link Row} to {@link GenericRecord}. */
-@AutoValue
-public abstract class GenericRecordWriteConverter

Review comment:
       Thanks for fixing this, sorry I didn't catch the error :grimacing: 

##########
File path: sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/utils/ConvertHelpers.java
##########
@@ -78,12 +83,15 @@ public ConvertedSchemaInformation(
   public static <T> ConvertedSchemaInformation<T> getConvertedSchemaInformation(
       Schema inputSchema, TypeDescriptor<T> outputType, SchemaRegistry schemaRegistry) {
     ConvertedSchemaInformation<T> convertedSchema = null;
-    boolean toRow = outputType.equals(TypeDescriptor.of(Row.class));
-    if (toRow) {
+    if (outputType.equals(TypeDescriptor.of(Row.class))) {
       // If the output is of type Row, then just forward the schema of the input type to the
       // output.
       convertedSchema =
           new ConvertedSchemaInformation<>((SchemaCoder<T>) SchemaCoder.of(inputSchema), null);
+    } else if (outputType.equals(TypeDescriptor.of(GenericRecord.class))) {
+      convertedSchema =
+          new ConvertedSchemaInformation<T>(
+              (SchemaCoder<T>) AvroUtils.schemaCoder(AvroUtils.toAvroSchema(inputSchema)), null);

Review comment:
       Hm it seems like this should be generalized somehow so we don't need to have if blocks for converting to every "dynamic" class. For example we might want something similar for protobuf's DynamicMessage. Something pluggable like SchemaProvider, but for making conversions to/from other dynamic row types.
   
   This is fine for now, but maybe drop a TODO and jira about generalizing?




----------------------------------------------------------------
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.

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



[GitHub] [beam] iemejia closed pull request #13671: [BEAM-11571] Support Conversion to GenericRecords in Convert.to transform

Posted by GitBox <gi...@apache.org>.
iemejia closed pull request #13671:
URL: https://github.com/apache/beam/pull/13671


   


----------------------------------------------------------------
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.

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



[GitHub] [beam] iemejia commented on a change in pull request #13671: [BEAM-11571] Support Conversion to GenericRecords in Convert.to transform

Posted by GitBox <gi...@apache.org>.
iemejia commented on a change in pull request #13671:
URL: https://github.com/apache/beam/pull/13671#discussion_r552265658



##########
File path: sdks/java/core/src/main/java/org/apache/beam/sdk/io/GenericRecordWriteConverter.java
##########
@@ -1,67 +0,0 @@
-/*
- * 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 org.apache.avro.generic.GenericRecord;
-import org.apache.beam.sdk.coders.AvroCoder;
-import org.apache.beam.sdk.schemas.Schema;
-import org.apache.beam.sdk.schemas.utils.AvroUtils;
-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;
-import org.apache.beam.sdk.values.Row;
-
-/** A {@link PTransform} to convert {@link Row} to {@link GenericRecord}. */
-@AutoValue
-public abstract class GenericRecordWriteConverter

Review comment:
       This class was recently introduced and 'wrongly' exposed because it missed the `@Internal` annotation since its main use was to support the `@Internal` class AvroSchemaIOProvider, that's why I went straight to remove it.




----------------------------------------------------------------
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.

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



[GitHub] [beam] iemejia commented on a change in pull request #13671: [BEAM-11571] Support Conversion to GenericRecords in Convert.to transform

Posted by GitBox <gi...@apache.org>.
iemejia commented on a change in pull request #13671:
URL: https://github.com/apache/beam/pull/13671#discussion_r554306591



##########
File path: sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/utils/ConvertHelpers.java
##########
@@ -78,12 +83,15 @@ public ConvertedSchemaInformation(
   public static <T> ConvertedSchemaInformation<T> getConvertedSchemaInformation(
       Schema inputSchema, TypeDescriptor<T> outputType, SchemaRegistry schemaRegistry) {
     ConvertedSchemaInformation<T> convertedSchema = null;
-    boolean toRow = outputType.equals(TypeDescriptor.of(Row.class));
-    if (toRow) {
+    if (outputType.equals(TypeDescriptor.of(Row.class))) {
       // If the output is of type Row, then just forward the schema of the input type to the
       // output.
       convertedSchema =
           new ConvertedSchemaInformation<>((SchemaCoder<T>) SchemaCoder.of(inputSchema), null);
+    } else if (outputType.equals(TypeDescriptor.of(GenericRecord.class))) {
+      convertedSchema =
+          new ConvertedSchemaInformation<T>(
+              (SchemaCoder<T>) AvroUtils.schemaCoder(AvroUtils.toAvroSchema(inputSchema)), null);

Review comment:
       Agree, I will fill a JIRA and add TODO + improve a bit the Javadoc in a future PR. I am going to merge this as it is because I have some pending PRs on top of these changes. Thanks!




----------------------------------------------------------------
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.

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



[GitHub] [beam] iemejia commented on a change in pull request #13671: [BEAM-11571] Support Conversion to GenericRecords in Convert.to transform

Posted by GitBox <gi...@apache.org>.
iemejia commented on a change in pull request #13671:
URL: https://github.com/apache/beam/pull/13671#discussion_r552265658



##########
File path: sdks/java/core/src/main/java/org/apache/beam/sdk/io/GenericRecordWriteConverter.java
##########
@@ -1,67 +0,0 @@
-/*
- * 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 org.apache.avro.generic.GenericRecord;
-import org.apache.beam.sdk.coders.AvroCoder;
-import org.apache.beam.sdk.schemas.Schema;
-import org.apache.beam.sdk.schemas.utils.AvroUtils;
-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;
-import org.apache.beam.sdk.values.Row;
-
-/** A {@link PTransform} to convert {@link Row} to {@link GenericRecord}. */
-@AutoValue
-public abstract class GenericRecordWriteConverter

Review comment:
       This class was 'wrongly' exposed and missing the @Internal annotation, that's why I went straight to remove it.




----------------------------------------------------------------
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.

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



[GitHub] [beam] iemejia closed pull request #13671: [BEAM-11571] Support Conversion to GenericRecords in Convert.to transform

Posted by GitBox <gi...@apache.org>.
iemejia closed pull request #13671:
URL: https://github.com/apache/beam/pull/13671


   


----------------------------------------------------------------
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.

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



[GitHub] [beam] TheNeuralBit commented on a change in pull request #13671: [BEAM-11571] Support Conversion to GenericRecords in Convert.to transform

Posted by GitBox <gi...@apache.org>.
TheNeuralBit commented on a change in pull request #13671:
URL: https://github.com/apache/beam/pull/13671#discussion_r555213761



##########
File path: sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/utils/ConvertHelpers.java
##########
@@ -78,12 +83,15 @@ public ConvertedSchemaInformation(
   public static <T> ConvertedSchemaInformation<T> getConvertedSchemaInformation(
       Schema inputSchema, TypeDescriptor<T> outputType, SchemaRegistry schemaRegistry) {
     ConvertedSchemaInformation<T> convertedSchema = null;
-    boolean toRow = outputType.equals(TypeDescriptor.of(Row.class));
-    if (toRow) {
+    if (outputType.equals(TypeDescriptor.of(Row.class))) {
       // If the output is of type Row, then just forward the schema of the input type to the
       // output.
       convertedSchema =
           new ConvertedSchemaInformation<>((SchemaCoder<T>) SchemaCoder.of(inputSchema), null);
+    } else if (outputType.equals(TypeDescriptor.of(GenericRecord.class))) {
+      convertedSchema =
+          new ConvertedSchemaInformation<T>(
+              (SchemaCoder<T>) AvroUtils.schemaCoder(AvroUtils.toAvroSchema(inputSchema)), null);

Review comment:
       SGTM, thank you :+1: 




----------------------------------------------------------------
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.

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