-
Notifications
You must be signed in to change notification settings - Fork 117
/
file.go
67 lines (56 loc) · 1.51 KB
/
file.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
package localfile
import (
"context"
"fmt"
"github.com/mitchellh/mapstructure"
"github.com/rilldata/rill/runtime/connectors"
)
func init() {
connectors.Register("local_file", connector{})
}
var spec = connectors.Spec{
DisplayName: "Local file",
Description: "Import Locally Stored File.",
Properties: []connectors.PropertySchema{
{
Key: "path",
Type: connectors.StringPropertyType,
Required: true,
DisplayName: "Path",
Description: "Path or URL to file",
Placeholder: "/path/to/file",
},
{
Key: "format",
Type: connectors.StringPropertyType,
Required: false,
DisplayName: "Format",
Description: "Either CSV or Parquet. Inferred if not set.",
Placeholder: "csv",
},
},
}
type Config struct {
Path string `mapstructure:"path"`
Format string `mapstructure:"format"`
}
func ParseConfig(props map[string]any) (*Config, error) {
conf := &Config{}
err := mapstructure.Decode(props, &conf)
if err != nil {
return nil, err
}
return conf, nil
}
type connector struct{}
func (c connector) Spec() connectors.Spec {
return spec
}
// local file connectors should directly use glob patterns
// keeping it for reference
func (c connector) ConsumeAsIterator(ctx context.Context, env *connectors.Env, source *connectors.Source) (connectors.FileIterator, error) {
return nil, fmt.Errorf("not implemented")
}
func (c connector) HasAnonymousAccess(ctx context.Context, env *connectors.Env, source *connectors.Source) (bool, error) {
return true, nil
}