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 2022/11/06 14:34:36 UTC
[GitHub] [beam] christogav commented on a diff in pull request #23285: Golang SpannerIO Implementation
christogav commented on code in PR #23285:
URL: https://github.com/apache/beam/pull/23285#discussion_r1014840171
##########
sdks/go/pkg/beam/io/spannerio/spanner.go:
##########
@@ -0,0 +1,163 @@
+package spannerio
+
+import (
+ "cloud.google.com/go/spanner"
+ "context"
+ "fmt"
+ "github.com/apache/beam/sdks/v2/go/pkg/beam"
+ "google.golang.org/api/iterator"
+ "reflect"
+ "strings"
+)
+
+func init() {
+ beam.RegisterType(reflect.TypeOf((*queryFn)(nil)).Elem())
+ beam.RegisterType(reflect.TypeOf((*writeFn)(nil)).Elem())
+}
+
+func columnsFromStruct(t reflect.Type) []string {
+ var columns []string
+
+ for i := 0; i < t.NumField(); i++ {
+ columns = append(columns, t.Field(i).Tag.Get("spanner"))
+ }
+
+ return columns
+}
+
+// Read reads all rows from the given table. The table must have a schema
+// compatible with the given type, t, and Read returns a PCollection<t>. If the
+// table has more rows than t, then Read is implicitly a projection.
+func Read(s beam.Scope, database, table string, t reflect.Type) beam.PCollection {
+ s = s.Scope("spanner.Read")
+
+ // TODO(herohde) 7/13/2017: using * is probably too inefficient. We could infer
+ // a focused query from the type.
+
+ cols := strings.Join(columnsFromStruct(t), ",")
+
+ return query(s, database, fmt.Sprintf("SELECT %v from [%v]", cols, table), t)
+}
+
+// QueryOptions represents additional options for executing a query.
+type QueryOptions struct {
+}
+
+// Query executes a query. The output must have a schema compatible with the given
+// type, t. It returns a PCollection<t>.
Review Comment:
Done
--
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