This repository has been archived by the owner on Aug 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_test.go
68 lines (57 loc) · 1.4 KB
/
example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Tentative API
package carrow_test
import (
"fmt"
"github.com/353solutions/carrow"
)
func Example() {
size := 100
intBld := carrow.NewInteger64ArrayBuilder()
floatBld := carrow.NewFloat64ArrayBuilder()
for i := 0; i < size; i++ {
if err := intBld.Append(int64(i)); err != nil {
fmt.Printf("intBld.Append error: %s", err)
return
}
if err := floatBld.Append(float64(i)); err != nil {
fmt.Printf("floatBld.Append error: %s", err)
return
}
}
intArr, err := intBld.Finish()
if err != nil {
fmt.Printf("intBld.Finish error: %s", err)
return
}
floatArr, err := floatBld.Finish()
if err != nil {
fmt.Printf("floatBld.Finish error: %s", err)
return
}
intField, err := carrow.NewField("incCol", carrow.Integer64Type)
if err != nil {
fmt.Printf("intField error: %s", err)
return
}
floatField, err := carrow.NewField("floatCol", carrow.Float64Type)
if err != nil {
fmt.Printf("floatField error: %s", err)
return
}
schema, err := carrow.NewSchema([]*carrow.Field{intField, floatField})
if err != nil {
fmt.Printf("can't create schema: %s", err)
return
}
arrs := []*carrow.Array{intArr, floatArr}
table, err := carrow.NewTableFromArrays(schema, arrs)
if err != nil {
fmt.Printf("table creation error: %s", err)
return
}
fmt.Printf("num cols: %d\n", table.NumCols())
fmt.Printf("num rows: %d\n", table.NumRows())
// Output:
// num cols: 2
// num rows: 100
}