[
https://issues.apache.org/jira/browse/BEAM-9615?focusedWorklogId=567791&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-567791
]
ASF GitHub Bot logged work on BEAM-9615:
----------------------------------------
Author: ASF GitHub Bot
Created on: 17/Mar/21 16:21
Start Date: 17/Mar/21 16:21
Worklog Time Spent: 10m
Work Description: lostluck commented on a change in pull request #14192:
URL: https://github.com/apache/beam/pull/14192#discussion_r596180354
##########
File path: sdks/go/pkg/beam/core/graph/coder/row_decoder.go
##########
@@ -114,16 +114,38 @@ func (b *RowDecoderBuilder) decoderForType(t
reflect.Type) (func(io.Reader) (int
// decoderForStructReflect returns a reflection based decoder function for the
// given struct type.
func (b *RowDecoderBuilder) decoderForStructReflect(t reflect.Type)
(func(reflect.Value, io.Reader) error, error) {
-
var coder typeDecoderReflect
coder.typ = t
for i := 0; i < t.NumField(); i++ {
i := i // avoid alias issues in the closures.
sf := t.Field(i)
isUnexported := sf.PkgPath != ""
- if isUnexported {
+ if sf.Anonymous {
+ ft := sf.Type
+ if ft.Kind() == reflect.Ptr {
+ // If a struct embeds a pointer to an
unexported type,
+ // it is not possible to set a newly allocated
value
+ // since the field is unexported.
+ //
+ // See https://golang.org/issue/21357
+ //
+ // Since the values are created by this package
reflectively,
+ // there's no work around like pre-allocating
the field
+ // manually.
+ if isUnexported {
Review comment:
This one is pretty complicated.
A reflect.StructField.PkgPath has this documentation
`PkgPath is the package path that qualifies a lower case (unexported) field
name. It is empty for upper case (exported) field names.` So normally, it's
only referring to the field itself.
This changes when it's an embedded field. As far as the AST (abstract syntax
tree) and reflective representations are concerned, an embedded field is named
*the same as the type being embedded*. However, this means that if you're
embedding an unexported type, that has Exported fields itself. So in the block
where we check whether the field is Anonymous (AKA embedded), we know that the
exported state of the field indicates whether the embedded type is unexported.
But, you want to be able to access those fields, and methods. The compiler
hoists the methods on embedded fields to the containing type, allowing the any
interfaces the embedded type satisfieds to be also satisfied by the containing
type. So, in this case, we want to serialize the exported fields of the
embedded type, whether or not the type itself is exported, since the user
expectation is they could access it.
Relatedly, if the embedded type is a pointer to an unexported type, there's
no way for us to synthetically create and allocate to that field, hence the big
comment there. A non-pointer doesn't have this problem because the fields of
the embedded type are a part of the container type's allocation, so we have
access to them as expected. The Go reflect library desperately avoids
allocating and changing values of unexported fields, but that's not the same on
types themselves.
----------------------------------------------------------------
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: 567791)
Time Spent: 24h 20m (was: 24h 10m)
> [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: 24h 20m
> 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)