omarismail94 commented on a change in pull request #11754:
URL: https://github.com/apache/beam/pull/11754#discussion_r427678727



##########
File path: 
sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/example/BeamSqlExample.java
##########
@@ -66,38 +68,47 @@ public static void main(String[] args) {
         inputTable.apply(SqlTransform.query("select c1, c2, c3 from 
PCOLLECTION where c1 > 1"));
 
     // print the output record of case 1;
-    outputStream.apply(
-        "log_result",
-        MapElements.via(
-            new SimpleFunction<Row, Row>() {
-              @Override
-              public Row apply(Row input) {
-                // expect output:
-                //  PCOLLECTION: [3, row, 3.0]
-                //  PCOLLECTION: [2, row, 2.0]
-                System.out.println("PCOLLECTION: " + input.getValues());
-                return input;
-              }
-            }));
+    outputStream
+        .apply(
+            "log_result",
+            MapElements.via(
+                new SimpleFunction<Row, Row>() {
+                  @Override
+                  public Row apply(Row input) {
+                    // expect output:
+                    //  PCOLLECTION: [3, row, 3.0]
+                    //  PCOLLECTION: [2, row, 2.0]
+                    System.out.println("PCOLLECTION: " + input.getValues());
+                    return input;
+                  }
+                }))
+        .setCoder(RowCoder.of(type));
 
     // Case 2. run the query with SqlTransform.query over result PCollection 
of case 1.
     PCollection<Row> outputStream2 =
         PCollectionTuple.of(new TupleTag<>("CASE1_RESULT"), outputStream)
             .apply(SqlTransform.query("select c2, sum(c3) from CASE1_RESULT 
group by c2"));
 
     // print the output record of case 2;
-    outputStream2.apply(
-        "log_result",
-        MapElements.via(
-            new SimpleFunction<Row, Row>() {
-              @Override
-              public Row apply(Row input) {
-                // expect output:
-                //  CASE1_RESULT: [row, 5.0]
-                System.out.println("CASE1_RESULT: " + input.getValues());
-                return input;
-              }
-            }));
+    outputStream2
+        .apply(
+            "log_result",
+            MapElements.via(
+                new SimpleFunction<Row, Row>() {
+                  @Override
+                  public Row apply(Row input) {
+                    // expect output:
+                    //  CASE1_RESULT: [row, 5.0]
+                    System.out.println("CASE1_RESULT: " + input.getValues());
+                    return input;
+                  }
+                }))
+        .setCoder(
+            RowCoder.of(
+                Schema.builder()
+                    .addStringField("stringField")
+                    .addDoubleField("doubleField")
+                    .build()));

Review comment:
       This is part of the Stack trace that makes me think that
   ```
   Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to 
java.lang.Integer
           at org.apache.beam.sdk.coders.VarIntCoder.encode(VarIntCoder.java:33)
           at 
org.apache.beam.sdk.coders.RowCoderGenerator$EncodeInstruction.encodeDelegate(RowCoderGenerator.java:270)
           at 
org.apache.beam.sdk.coders.Coder$ByteBuddy$E99UrF3W.encode(Unknown Source)
           at 
org.apache.beam.sdk.coders.Coder$ByteBuddy$E99UrF3W.encode(Unknown Source)
           at 
org.apache.beam.sdk.schemas.SchemaCoder.encode(SchemaCoder.java:115)
   ```




----------------------------------------------------------------
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:
us...@infra.apache.org


Reply via email to