-
Notifications
You must be signed in to change notification settings - Fork 111
/
athena.go
205 lines (173 loc) · 5.21 KB
/
athena.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
package athena
import (
"context"
"errors"
"github.com/mitchellh/mapstructure"
"github.com/rilldata/rill/runtime/drivers"
"github.com/rilldata/rill/runtime/pkg/activity"
"go.uber.org/zap"
)
func init() {
drivers.Register("athena", driver{})
drivers.RegisterAsConnector("athena", driver{})
}
var spec = drivers.Spec{
DisplayName: "Amazon Athena",
Description: "Connect to Amazon Athena database.",
DocsURL: "",
SourceProperties: []*drivers.PropertySpec{
{
Key: "sql",
Type: drivers.StringPropertyType,
Required: true,
DisplayName: "SQL",
Description: "Query to extract data from Athena.",
Placeholder: "select * from catalog.table;",
},
{
Key: "output_location",
Type: drivers.StringPropertyType,
DisplayName: "S3 output location",
Description: "Output location for query results in S3.",
Placeholder: "s3://bucket-name/path/",
Required: false,
},
{
Key: "workgroup",
Type: drivers.StringPropertyType,
DisplayName: "AWS Athena workgroup",
Description: "AWS Athena workgroup to use for queries.",
Placeholder: "primary",
Required: false,
},
{
Key: "region",
Type: drivers.StringPropertyType,
DisplayName: "AWS region",
Description: "AWS region to connect to Athena and the output location.",
Placeholder: "us-east-1",
Required: false,
},
},
ConfigProperties: []*drivers.PropertySpec{
{
Key: "aws_access_key_id",
Type: drivers.StringPropertyType,
Secret: true,
},
{
Key: "aws_secret_access_key",
Type: drivers.StringPropertyType,
Secret: true,
},
},
}
type driver struct{}
type configProperties struct {
AccessKeyID string `mapstructure:"aws_access_key_id"`
SecretAccessKey string `mapstructure:"aws_secret_access_key"`
SessionToken string `mapstructure:"aws_access_token"`
AllowHostAccess bool `mapstructure:"allow_host_access"`
}
func (d driver) Open(instanceID string, config map[string]any, client *activity.Client, logger *zap.Logger) (drivers.Handle, error) {
if instanceID == "" {
return nil, errors.New("athena driver can't be shared")
}
conf := &configProperties{}
err := mapstructure.WeakDecode(config, conf)
if err != nil {
return nil, err
}
conn := &Connection{
config: conf,
logger: logger,
}
return conn, nil
}
func (d driver) Spec() drivers.Spec {
return spec
}
func (d driver) HasAnonymousSourceAccess(ctx context.Context, src map[string]any, logger *zap.Logger) (bool, error) {
return false, nil
}
func (d driver) TertiarySourceConnectors(ctx context.Context, src map[string]any, logger *zap.Logger) ([]string, error) {
return nil, nil
}
type Connection struct {
config *configProperties
logger *zap.Logger
}
var _ drivers.Handle = &Connection{}
// Driver implements drivers.Connection.
func (c *Connection) Driver() string {
return "athena"
}
// Config implements drivers.Connection.
func (c *Connection) Config() map[string]any {
m := make(map[string]any, 0)
_ = mapstructure.Decode(c.config, m)
return m
}
// Close implements drivers.Connection.
func (c *Connection) Close() error {
return nil
}
// AsRegistry implements drivers.Connection.
func (c *Connection) AsRegistry() (drivers.RegistryStore, bool) {
return nil, false
}
// AsCatalogStore implements drivers.Connection.
func (c *Connection) AsCatalogStore(instanceID string) (drivers.CatalogStore, bool) {
return nil, false
}
// AsRepoStore implements drivers.Connection.
func (c *Connection) AsRepoStore(instanceID string) (drivers.RepoStore, bool) {
return nil, false
}
// AsAdmin implements drivers.Handle.
func (c *Connection) AsAdmin(instanceID string) (drivers.AdminService, bool) {
return nil, false
}
// AsAI implements drivers.Handle.
func (c *Connection) AsAI(instanceID string) (drivers.AIService, bool) {
return nil, false
}
// AsOLAP implements drivers.Connection.
func (c *Connection) AsOLAP(instanceID string) (drivers.OLAPStore, bool) {
return nil, false
}
// Migrate implements drivers.Connection.
func (c *Connection) Migrate(ctx context.Context) (err error) {
return nil
}
// MigrationStatus implements drivers.Connection.
func (c *Connection) MigrationStatus(ctx context.Context) (current, desired int, err error) {
return 0, 0, nil
}
// AsObjectStore implements drivers.Connection.
func (c *Connection) AsObjectStore() (drivers.ObjectStore, bool) {
return nil, false
}
// AsModelExecutor implements drivers.Handle.
func (c *Connection) AsModelExecutor(instanceID string, opts *drivers.ModelExecutorOptions) (drivers.ModelExecutor, bool) {
return nil, false
}
// AsModelManager implements drivers.Handle.
func (c *Connection) AsModelManager(instanceID string) (drivers.ModelManager, bool) {
return nil, false
}
// AsTransporter implements drivers.Connection.
func (c *Connection) AsTransporter(from, to drivers.Handle) (drivers.Transporter, bool) {
return nil, false
}
func (c *Connection) AsFileStore() (drivers.FileStore, bool) {
return nil, false
}
// AsSQLStore implements drivers.Connection.
func (c *Connection) AsSQLStore() (drivers.SQLStore, bool) {
return c, true
}
// AsNotifier implements drivers.Handle.
func (c *Connection) AsNotifier(properties map[string]any) (drivers.Notifier, error) {
return nil, drivers.ErrNotNotifier
}