forked from grafadruid/go-druid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
task_types.go
245 lines (220 loc) · 7.6 KB
/
task_types.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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
package druid
import (
"fmt"
"time"
)
const (
iso8601Format = "2006-01-02T15:04:05"
)
// TaskStatusResponse is a response object containing status of a task.
type TaskStatusResponse struct {
Task string `json:"task"`
Status TaskStatus `json:"status"`
}
// TaskLocation holds location of the task execution.
type TaskLocation struct {
Host string `json:"host"`
Port int `json:"port"`
TlsPort int `json:"tlsPort"`
}
// TaskStatus is an object representing status of a druid task.
type TaskStatus struct {
ID string `json:"id"`
Type string `json:"type"`
CreatedTime string `json:"createdTime"`
QueueInsertionTime string `json:"queueInsertionTime"`
StatusCode string `json:"statusCode"`
Status string `json:"status"`
RunnerStatusCode string `json:"runnerStatusCode"`
Duration int `json:"duration"`
GroupId string `json:"groupId"`
Location *TaskLocation `json:"location|omitempty"`
Datasource string `json:"datasource"`
ErrorMessage string `json:"errorMessage"`
}
// TaskIngestionSpec is a specification for a druid task execution.
type TaskIngestionSpec struct {
Type string `json:"type"`
Spec *IngestionSpecData `json:"spec"`
}
// RunningTask defines running task returned by GetRunningTasks method.
// https://druid.apache.org/docs/latest/api-reference/tasks-api#sample-response-2
type RunningTask struct {
ID string `json:"id"`
Type string `json:"type"`
Status string `json:"status"`
Datasource string `json:"dataSource"`
}
// RunningTasksOptions defines supported options which can be passed to GetRunningTasks method.
// https://druid.apache.org/docs/latest/api-reference/tasks-api#query-parameters-2
type RunningTasksOptions struct {
Datasource string `url:"datasource"`
Type string `url:"type"`
}
// defaultTaskIngestionSpec returns a default TaskIngestionSpec with basic ingestion
// specification fields initialized.
func defaultTaskIngestionSpec() *TaskIngestionSpec {
spec := &TaskIngestionSpec{
Type: "index_parallel",
Spec: &IngestionSpecData{
DataSchema: &DataSchema{
DataSource: "some_datasource",
GranularitySpec: &GranularitySpec{
Type: "uniform",
SegmentGranularity: "DAY",
QueryGranularity: &QueryGranularitySpec{"none"},
},
DimensionsSpec: &DimensionsSpec{
UseSchemaDiscovery: true,
Dimensions: DimensionSet{},
},
TransformSpec: &TransformSpec{
Transforms: []Transform{},
},
TimeStampSpec: &TimestampSpec{},
},
IOConfig: &IOConfig{
Type: "index_parallel",
InputSource: &InputSource{},
},
TuningConfig: &TuningConfig{
Type: "index_parallel",
},
},
}
return spec
}
// TaskIngestionSpecOptions allows for configuring a TaskIngestionSpec.
type TaskIngestionSpecOptions func(*TaskIngestionSpec)
// SetTaskType sets the type of the task IOConfig.
func SetTaskType(stype string) TaskIngestionSpecOptions {
return func(spec *TaskIngestionSpec) {
if stype != "" {
spec.Type = stype
}
}
}
// SetTaskTimestampColumn sets the type of the task IOConfig.
func SetTaskTimestampColumn(column string) TaskIngestionSpecOptions {
return func(spec *TaskIngestionSpec) {
if column != "" {
spec.Spec.DataSchema.TimeStampSpec = &TimestampSpec{
Column: column,
Format: "auto",
}
}
}
}
// SetTaskDataSource sets the destination datasource of the task IOConfig.
func SetTaskDataSource(datasource string) TaskIngestionSpecOptions {
return func(spec *TaskIngestionSpec) {
if datasource != "" {
spec.Spec.DataSchema.DataSource = datasource
}
}
}
// SetTaskTuningConfig sets the tuning configuration the task IOConfig.
func SetTaskTuningConfig(typ string, maxRowsInMemory, maxRowsPerSegment int) TaskIngestionSpecOptions {
return func(spec *TaskIngestionSpec) {
if typ != "" {
spec.Spec.TuningConfig.Type = typ
spec.Spec.TuningConfig.MaxRowsInMemory = maxRowsInMemory
spec.Spec.TuningConfig.MaxRowsPerSegment = maxRowsPerSegment
}
}
}
// SetTaskDataDimensions sets druid datasource dimensions.
func SetTaskDataDimensions(dimensions DimensionSet) TaskIngestionSpecOptions {
return func(spec *TaskIngestionSpec) {
spec.Spec.DataSchema.DimensionsSpec.Dimensions = dimensions
}
}
// SetTaskSQLInputSource configures sql input source for the task based ingestion.
func SetTaskSQLInputSource(typ, connectURI, user, password string, sqls []string) TaskIngestionSpecOptions {
return func(spec *TaskIngestionSpec) {
spec.Spec.IOConfig.InputSource = &InputSource{
Type: "sql",
SQLs: sqls,
Database: &Database{
Type: typ,
ConnectorConfig: &ConnectorConfig{
ConnectURI: connectURI,
User: user,
Password: password,
},
},
}
}
}
// SetTaskIOConfigType sets the type of the task IOConfig.
func SetTaskIOConfigType(typ string) TaskIngestionSpecOptions {
return func(spec *TaskIngestionSpec) {
if typ != "" {
spec.Spec.IOConfig.Type = typ
}
}
}
// SetTaskInputFormat configures input format for the task based ingestion.
func SetTaskInputFormat(typ string, findColumnsHeader string, columns []string) TaskIngestionSpecOptions {
return func(spec *TaskIngestionSpec) {
if spec.Spec.IOConfig.InputFormat == nil {
spec.Spec.IOConfig.InputFormat = &InputFormat{}
}
spec.Spec.IOConfig.InputFormat.Type = typ
spec.Spec.IOConfig.InputFormat.FindColumnsFromHeader = findColumnsHeader
spec.Spec.IOConfig.InputFormat.Columns = columns
}
}
// SetTaskInlineInputData configures inline data for the task based ingestion.
func SetTaskInlineInputData(data string) TaskIngestionSpecOptions {
return func(spec *TaskIngestionSpec) {
spec.Spec.IOConfig.InputSource.Type = "inline"
spec.Spec.IOConfig.InputSource.Data = data
}
}
// SetTaskDruidInputSource configures druid reindex input source for the task based ingestion.
func SetTaskDruidInputSource(datasource string, startTime time.Time, endTime time.Time) TaskIngestionSpecOptions {
return func(spec *TaskIngestionSpec) {
spec.Spec.IOConfig.InputSource = &InputSource{
Type: "druid",
Datasource: datasource,
Interval: fmt.Sprintf(
"%s/%s",
startTime.Format(iso8601Format),
endTime.Format(iso8601Format),
),
}
}
}
// SetTaskSchemaDiscovery sets auto discovery of dimensions.
func SetTaskSchemaDiscovery(discovery bool) TaskIngestionSpecOptions {
return func(spec *TaskIngestionSpec) {
spec.Spec.DataSchema.DimensionsSpec.UseSchemaDiscovery = discovery
}
}
// SetTaskGranularitySpec sets granularity spec settings that are applied at druid ingestion partitioning stage.
func SetTaskGranularitySpec(segmentGranularity string, queryGranularity *QueryGranularitySpec, rollup bool) TaskIngestionSpecOptions {
return func(spec *TaskIngestionSpec) {
spec.Spec.DataSchema.GranularitySpec = &GranularitySpec{
Type: "uniform",
SegmentGranularity: segmentGranularity,
QueryGranularity: queryGranularity,
Rollup: rollup,
}
}
}
// SetForceGuaranteedRollup sets guaranteed rollup setting for ingestion spec.
// https://druid.apache.org/docs/latest/ingestion/rollup#perfect-rollup-vs-best-effort-rollup
func SetForceGuaranteedRollup(rollup bool) TaskIngestionSpecOptions {
return func(spec *TaskIngestionSpec) {
spec.Spec.TuningConfig.ForceGuaranteedRollup = rollup
}
}
// NewTaskIngestionSpec returns a default TaskIngestionSpec and applies any options passed to it.
func NewTaskIngestionSpec(options ...TaskIngestionSpecOptions) *TaskIngestionSpec {
spec := defaultTaskIngestionSpec()
for _, fn := range options {
fn(spec)
}
return spec
}