[
https://issues.apache.org/jira/browse/BEAM-9615?focusedWorklogId=567810&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-567810
]
ASF GitHub Bot logged work on BEAM-9615:
----------------------------------------
Author: ASF GitHub Bot
Created on: 17/Mar/21 16:45
Start Date: 17/Mar/21 16:45
Worklog Time Spent: 10m
Work Description: lostluck commented on a change in pull request #14192:
URL: https://github.com/apache/beam/pull/14192#discussion_r596200323
##########
File path: sdks/go/pkg/beam/core/runtime/graphx/schema/schema.go
##########
@@ -280,82 +301,194 @@ func (r *Registry) FromType(ot reflect.Type)
(*pipepb.Schema, error) {
return r.fromType(ot)
}
+func (r *Registry) logicalTypeToFieldType(t reflect.Type) (*pipepb.FieldType,
string, error) {
+ // Check if a logical type was registered that matches this struct type
directly
+ // and if so, extract the schema from it for use.
+ if lID, ok := r.logicalTypeIdentifiers[t]; ok {
+ lt := r.logicalTypes[lID]
+ ftype, err := r.reflectTypeToFieldType(lt.StorageType())
+ if err != nil {
+ return nil, "", errors.Wrapf(err, "unable to convert
LogicalType[%v]'s storage type %v for Go type of %v to a schema", lID,
lt.StorageType(), lt.GoType())
+ }
+ return ftype, lID, nil
+ }
+ for _, lti := range r.logicalTypeInterfaces {
+ if !t.Implements(lti) {
+ continue
+ }
+ p := r.logicalTypeProviders[lti]
+ st, err := p(t)
+ if err != nil {
+ return nil, "", errors.Wrapf(err, "unable to convert
LogicalType[%v] using provider for %v schema field", t, lti)
+ }
+ if st == nil {
+ continue
+ }
+ ftype, err := r.reflectTypeToFieldType(st)
+ if err != nil {
+ return nil, "", errors.Wrapf(err, "unable to convert
LogicalType[%v]'s storage type %v for Go type of %v to a schema", "interface",
st, t)
+ }
+ return ftype, t.String(), nil
+ }
+ return nil, "", nil
+}
+
func (r *Registry) fromType(ot reflect.Type) (*pipepb.Schema, error) {
- if reflectx.SkipPtr(ot).Kind() != reflect.Struct {
- return nil, errors.Errorf("cannot convert %v to schema.
FromType only converts structs to schemas", ot)
+ if schm, ok := r.typeToSchema[ot]; ok {
+ return schm, nil
}
- schm, err := r.structToSchema(ot)
+ ftype, lID, err := r.logicalTypeToFieldType(ot)
if err != nil {
return nil, err
}
- if ot.Kind() == reflect.Ptr {
- schm.Options = append(schm.Options, &pipepb.Option{
- Name: optGoNillable,
- })
+ if ftype != nil {
Review comment:
Very similar means they aren't the same. Also, structToSchema *always
and only* handles structs, not pointers to structs. If a pointer type is
registered for special handling, structToSchema will *never* catch it.
Originally structToSchema handled both, but that lead to *so many bugs*,
which this current approach avoids. You're right that there's probably a
further reduction opportunity here, but the cleanups done here already are
already far enough from what I have in my internal client, that I want to limit
further drift now.
----------------------------------------------------------------
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:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 567810)
Time Spent: 24.5h (was: 24h 20m)
> [Go SDK] Beam Schemas
> ---------------------
>
> Key: BEAM-9615
> URL: https://issues.apache.org/jira/browse/BEAM-9615
> Project: Beam
> Issue Type: New Feature
> Components: sdk-go
> Reporter: Robert Burke
> Assignee: Robert Burke
> Priority: P2
> Time Spent: 24.5h
> Remaining Estimate: 0h
>
> Schema support is required for advanced cross language features in Beam, and
> has the opportunity to replace the current default JSON encoding of elements.
> Some quick notes, though a better fleshed out doc with details will be
> forthcoming:
> * All base coders should be implemented, and listed as coder capabilities. I
> think only stringutf8 is missing presently.
> * Should support fairly arbitrary user types, seamlessly. That is, users
> should be able to rely on it "just working" if their type is compatible.
> * Should support schema metadata tagging.
> In particular, one breaking shift in the default will be to explicitly fail
> pipelines if elements have unexported fields, when no other custom coder has
> been added. This has been a source of errors/dropped data/keys and a simply
> warning at construction time won't cut it. However, we could provide a manual
> "use beam schemas, but ignore unexported fields" registration as a work
> around.
> Edit: Doc is now at https://s.apache.org/beam-go-schemas
--
This message was sent by Atlassian Jira
(v8.3.4#803005)