@@ -143,7 +143,6 @@ func ExampleRepository_Write() {
143143 fmt .Println (event .Cells ["event_type" ])
144144 fmt .Println (event .Cells ["device_type" ])
145145 }
146-
147146 // Output:
148147 // front:11 1
149148 // front:12 1
@@ -164,6 +163,99 @@ func ExampleRepository_Write() {
164163
165164}
166165
166+ func ExampleRepository_Search () {
167+ ctx := context .Background ()
168+ client := getBigTableClient (ctx )
169+ c , err := fs .ReadFile ("testdata/mapping.json" )
170+ if err != nil {
171+ log .Fatalln (err )
172+ }
173+ jsonMapping , err := mapping .LoadMapping (c )
174+ if err != nil {
175+ log .Fatalln (err )
176+ }
177+ mapper := mapping .NewMapper (jsonMapping )
178+ tbl := client .Open (table )
179+
180+ repo := NewRepository (tbl , mapper )
181+ eventSet := & data.Set {Events : map [string ][]* data.Event {
182+ "front" : {
183+ {
184+ RowKey : "contactx-101" ,
185+ Date : time .Date (2018 , time .January , 1 , 0 , 0 , 0 , 0 , time .UTC ),
186+ Cells : map [string ]string {
187+ "event_type" : "page_view" ,
188+ "device_type" : "Smartphone" ,
189+ "url" : "https://example.org/some/product" ,
190+ },
191+ },
192+ {
193+ RowKey : "contactx-101" ,
194+ Date : time .Date (2018 , time .January , 1 , 0 , 1 , 0 , 0 , time .UTC ),
195+ Cells : map [string ]string {
196+ "event_type" : "add_to_cart" ,
197+ "device_type" : "Smartphone" ,
198+ "url" : "https://example.org/some/product" ,
199+ },
200+ },
201+ {
202+ RowKey : "contactx-101" ,
203+ Date : time .Date (2018 , time .January , 1 , 0 , 2 , 0 , 0 , time .UTC ),
204+ Cells : map [string ]string {
205+ "event_type" : "purchase" ,
206+ "device_type" : "Smartphone" ,
207+ "url" : "https://example.org/some/product" ,
208+ },
209+ },
210+ {
211+ RowKey : "contactx-102" ,
212+ Date : time .Date (2018 , time .January , 1 , 0 , 2 , 0 , 0 , time .UTC ),
213+ Cells : map [string ]string {
214+ "event_type" : "add_to_cart" ,
215+ "device_type" : "Computer" ,
216+ "url" : "https://example.org/some/product" ,
217+ },
218+ },
219+ {
220+ RowKey : "contacty-102" ,
221+ Date : time .Date (2018 , time .January , 1 , 0 , 2 , 0 , 0 , time .UTC ),
222+ Cells : map [string ]string {
223+ "event_type" : "add_to_cart" ,
224+ "device_type" : "Computer" ,
225+ "url" : "https://example.org/some/product" ,
226+ },
227+ },
228+ },
229+ }}
230+ errs , err := repo .Write (ctx , eventSet )
231+ if err != nil {
232+ log .Fatalln (err )
233+ }
234+ if len (errs ) > 0 {
235+ log .Fatalln (errs )
236+ }
237+ readSet , err := repo .Search (ctx , bigtable .PrefixRange ("contactx" ), bigtable .CellsPerRowLimitFilter (1 ))
238+ if err != nil {
239+ log .Fatalln (err )
240+ }
241+ for _ , event := range readSet .Events ["front" ] {
242+ fmt .Println (event .Date .UTC ())
243+ fmt .Println (event .RowKey )
244+ fmt .Println (event .Cells ["event_type" ])
245+ fmt .Println (event .Cells ["device_type" ])
246+ }
247+
248+ // Output:
249+ // 2018-01-01 00:00:00 +0000 UTC
250+ // contactx-101
251+ // page_view
252+ // Smartphone
253+ // 2018-01-01 00:02:00 +0000 UTC
254+ // contactx-102
255+ // add_to_cart
256+ // Computer
257+ }
258+
167259var t1 = bigtable .Time (time .Date (2020 , time .January , 1 , 0 , 1 , 0 , 0 , time .UTC ))
168260var t2 = bigtable .Time (time .Date (2020 , time .January , 1 , 0 , 2 , 0 , 0 , time .UTC ))
169261var t3 = bigtable .Time (time .Date (2020 , time .January , 1 , 0 , 3 , 0 , 0 , time .UTC ))
0 commit comments