github.com/apache/beam/sdks/v2@v2.48.2/go/test/integration/transforms/xlang/dataframe/dataframe.go (about) 1 // Licensed to the Apache Software Foundation (ASF) under one or more 2 // contributor license agreements. See the NOTICE file distributed with 3 // this work for additional information regarding copyright ownership. 4 // The ASF licenses this file to You under the Apache License, Version 2.0 5 // (the "License"); you may not use this file except in compliance with 6 // the License. You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 16 package dataframe 17 18 import ( 19 "reflect" 20 21 "github.com/apache/beam/sdks/v2/go/pkg/beam" 22 "github.com/apache/beam/sdks/v2/go/pkg/beam/testing/passert" 23 "github.com/apache/beam/sdks/v2/go/pkg/beam/transforms/xlang/dataframe" 24 ) 25 26 func init() { 27 beam.RegisterType(reflect.TypeOf((*TestRow)(nil)).Elem()) 28 } 29 30 type TestRow struct { 31 A int64 `beam:"a"` 32 B int32 `beam:"b"` 33 } 34 35 func DataframeTransform(expansionAddr string) *beam.Pipeline { 36 row0 := TestRow{A: int64(100), B: int32(1)} 37 row1 := TestRow{A: int64(100), B: int32(2)} 38 row2 := TestRow{A: int64(100), B: int32(3)} 39 row3 := TestRow{A: int64(200), B: int32(4)} 40 41 p, s := beam.NewPipelineWithRoot() 42 43 input := beam.Create(s, row0, row1, row3) 44 outCol := dataframe.Transform(s, "lambda df: df.groupby('a').sum()", input, reflect.TypeOf((*TestRow)(nil)).Elem(), dataframe.WithExpansionAddr(expansionAddr), dataframe.WithIndexes()) 45 46 passert.Equals(s, outCol, row2, row3) 47 return p 48 }