Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions website/www/site/content/en/documentation/programming-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -4164,14 +4164,31 @@ as schema fields may have different requirements or restrictions from Go exporte

### 6.6. Using Schema Transforms {#using-schemas}

A schema on a `PCollection` enables a rich variety of relational transforms. The fact that each record is composed of
named fields allows for simple and readable aggregations that reference fields by name, similar to the aggregations in
a SQL expression.

{{< paragraph class="language-go">}}
Beam does not yet support Schema transforms natively in Go. However, it will be implemented with the following behavior.
In Go, schemas are inferred from struct types. You can use schema-aware
<code>PCollection</code>s by defining structs and accessing their fields
directly in transforms. The following example demonstrates extracting
a nested field from a schema-aware collection.
{{< /paragraph >}}

{{< highlight go >}}
type ShippingAddress struct {
PostCode string `beam:"postCode"`
}
type Purchase struct {
ShippingAddress ShippingAddress `beam:"shippingAddress"`
}
purchases := beam.Create(s,
Purchase{
ShippingAddress: ShippingAddress{PostCode: "12345"},
},
)
postCodes := beam.ParDo(s, func(p Purchase) string {
return p.ShippingAddress.PostCode
}, purchases)
{{< /highlight >}}


#### 6.6.1. Field selection syntax

The advantage of schemas is that they allow referencing of element fields by name. Beam provides a selection syntax for
Expand Down