-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdataframe.go
More file actions
57 lines (47 loc) · 1.19 KB
/
Copy pathdataframe.go
File metadata and controls
57 lines (47 loc) · 1.19 KB
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
package fuse
import (
"context"
"fmt"
gen "github.com/declaredata/fuse_go/gen"
"github.com/google/uuid"
)
type DataFrame struct {
dfUID uuid.UUID
sess *Session
}
func (d *DataFrame) Collect(ctx context.Context) ([]*Row, error) {
contents, err := d.sess.client.Collect(ctx, &gen.DataFrameUID{
DataframeUid: d.dfUID.String(),
})
if err != nil {
return nil, fmt.Errorf("collecting dataframe: %w", err)
}
return mapSlice(contents.GetRows(), func(r *gen.Row) *Row {
return &Row{r: r}
}), nil
}
func (d *DataFrame) Col(colName string) *ExistingCol {
return Col(colName)
}
func (d *DataFrame) Select(ctx context.Context, cols ...Column) (*DataFrame, error) {
resp, err := d.sess.client.Select(ctx, &gen.SelectRequest{
DfUid: d.dfUID.String(),
Columns: mapSlice(cols, func(c Column) *gen.Column {
return c.toColumn()
}),
})
if err != nil {
return nil, fmt.Errorf(
"calling select on %d columns: %w",
len(cols),
err,
)
}
return d.createDescendant(resp)
}
func (d *DataFrame) Builder() DataFrameBuilder {
return DataFrameBuilder{origDF: d, funcs: nil}
}
func (d *DataFrame) createDescendant(dfUID *gen.DataFrameUID) (*DataFrame, error) {
return dfUIDToDF(dfUID, d.sess)
}