-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdataframe_ctor.go
More file actions
46 lines (39 loc) · 909 Bytes
/
Copy pathdataframe_ctor.go
File metadata and controls
46 lines (39 loc) · 909 Bytes
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
package fuse
import (
"context"
"fmt"
gen "github.com/declaredata/fuse_go/gen"
"github.com/google/uuid"
)
func newDataFrame(uid uuid.UUID, sess *Session) *DataFrame {
return &DataFrame{
dfUID: uid,
sess: sess,
}
}
func DataFrameFromCSV(ctx context.Context, sess *Session, fileName string) (*DataFrame, error) {
dfID, err := sess.client.LoadCSV(ctx, &gen.LoadFileRequest{
SessionId: sess.uid.String(),
Source: fileName,
})
if err != nil {
return nil, fmt.Errorf(
"loading CSV %s for session %s: %w",
fileName,
sess.uid.String(),
err,
)
}
return dfUIDToDF(dfID, sess)
}
func dfUIDToDF(dfUID *gen.DataFrameUID, sess *Session) (*DataFrame, error) {
parsed, err := uuid.Parse(dfUID.GetDataframeUid())
if err != nil {
return nil, fmt.Errorf(
"parsing raw DataFrameUID %s: %w",
dfUID.GetDataframeUid(),
err,
)
}
return newDataFrame(parsed, sess), nil
}