lostluck commented on code in PR #16818:
URL: https://github.com/apache/beam/pull/16818#discussion_r892998973


##########
sdks/go/test/integration/io/xlang/bigquery/bigquery.go:
##########
@@ -31,7 +31,7 @@ import (
 func init() {
        register.DoFn2x0[[]byte, func(TestRow)](&CreateTestRowsFn{})
        register.Emitter1[TestRow]()
-       register.Function1x1[TestRowPtrs, TestRow](castFn)
+       //register.Function1x1[TestRowPtrs, TestRow](castFn)

Review Comment:
   I'll note you should be able to elide the explicit type parameters for the 
Function* registrations, and it'll happen automatically.



##########
sdks/go/test/integration/io/xlang/bigquery/bigquery.go:
##########
@@ -141,7 +141,14 @@ type RandDataPtrs struct {
        Word *string `beam:"word"`
 }
 
-func castFn(elm TestRowPtrs) TestRow {
+func castFn(elm struct {

Review Comment:
   Add a TODO to change it to the "correct" type. We probably want to file a 
linked issue for it.



##########
sdks/go/test/integration/io/xlang/bigquery/bigquery.go:
##########
@@ -0,0 +1,186 @@
+// 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 bigquery contains integration tests for cross-language BigQuery IO 
transforms.
+package bigquery
+
+import (
+       "fmt"
+       "math/rand"
+       "reflect"
+       "strings"
+
+       "github.com/apache/beam/sdks/v2/go/pkg/beam"
+       "github.com/apache/beam/sdks/v2/go/pkg/beam/io/xlang/bigqueryio"
+       "github.com/apache/beam/sdks/v2/go/pkg/beam/register"
+       "github.com/apache/beam/sdks/v2/go/pkg/beam/testing/passert"
+)
+
+func init() {
+       register.DoFn2x0[[]byte, func(TestRow)](&CreateTestRowsFn{})
+       register.Emitter1[TestRow]()
+       //register.Function1x1[TestRowPtrs, TestRow](castFn)
+       beam.RegisterType(reflect.TypeOf((*TestRow)(nil)))
+       beam.RegisterType(reflect.TypeOf((*RandData)(nil)))
+       beam.RegisterType(reflect.TypeOf((*TestRowPtrs)(nil)))
+       beam.RegisterType(reflect.TypeOf((*RandDataPtrs)(nil)))

Review Comment:
   With the generic registrations, it should be possible to avoid registering 
these explicitly.



##########
sdks/go/test/integration/io/xlang/bigquery/bigquery.go:
##########
@@ -160,7 +167,14 @@ func ReadFromQueryPipeline(expansionAddr, table string, 
createFn interface{}) *b
 
        // Read from table and compare to generated elements.
        rows := beam.ParDo(s, createFn, beam.Impulse(s))
-       inType := reflect.TypeOf((*TestRowPtrs)(nil)).Elem()
+       inType := reflect.TypeOf((*struct {
+               Counter   *int64 `beam:"counter"`
+               Rand_data *struct {
+                       Flip *bool   `beam:"flip"`
+                       Num  *int64  `beam:"num"`
+                       Word *string `beam:"word"`
+               } `beam:"rand_data"`
+       })(nil)).Elem()

Review Comment:
   Given how oboxious this is, use a type alias instead
   `type foo = struct {... }`
   
   And then we can avoid defining it in multiple places.
   
   The `=` there does the work, but it's not an ideal fix, but it's a much 
cleaner work around, which we can officially document if we need to.
   
   See: https://go.dev/play/p/zVj03UIydm5



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to