forked from grafadruid/go-druid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common_spec_types.go
422 lines (358 loc) · 16.4 KB
/
common_spec_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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
package druid
import (
"encoding/json"
"fmt"
)
// BitmapFactory is a field of IndexSpec.
type BitmapFactory struct {
Type string `json:"type"`
}
// StringEncodingStrategy type for specifying string encoding at indexing stage.
type StringEncodingStrategy struct {
Type string `json:"type"`
// FrontCoded fields.
BucketSize int `json:"bucketSize,omitempty"`
FormatVersion int `json:"formatVersion,omitempty"`
}
// IndexSpec defines segment storage format options to be used at indexing time.
// https://druid.apache.org/docs/latest/ingestion/ingestion-spec#indexspec
type IndexSpec struct {
Bitmap *BitmapFactory `json:"bitmap,omitempty"`
DimensionCompression string `json:"dimensionCompression"`
StringEncodingStrategy *StringEncodingStrategy `json:"stringEncodingStrategy,omitempty"`
MetricCompression string `json:"metricCompression,omitempty"`
LongEncoding string `json:"longEncoding,omitempty"`
JsonCompression string `json:"jsonCompression,omitempty"`
SegmentLoader string `json:"segmentLoader,omitempty"`
}
// TuningConfig controls various tuning parameters specific to each ingestion method.
// https://druid.apache.org/docs/latest/ingestion/ingestion-spec#tuningconfig
type TuningConfig struct {
Type string `json:"type"`
IntermediatePersistPeriod string `json:"intermediatePersistPeriod,omitempty"`
MaxRowsPerSegment int `json:"maxRowsPerSegment,omitempty"`
MaxRowsInMemory int `json:"maxRowsInMemory,omitempty"`
IndexSpecForIntermediatePersists *IndexSpec `json:"indexSpecForIntermediatePersists,omitempty"`
ForceGuaranteedRollup bool `json:"forceGuaranteedRollup,omitempty"`
}
// Metric is a Druid aggregator that is applied at ingestion time.
// https://druid.apache.org/docs/latest/ingestion/ingestion-spec#metricsspec
type Metric struct {
Name string `json:"name"`
Type string `json:"type"`
FieldName string `json:"fieldName"`
}
// DataSchema represents the Druid dataSchema spec.
type DataSchema struct {
DataSource string `json:"dataSource"`
Parser string `json:"parser,omitempty"`
TimeStampSpec *TimestampSpec `json:"timestampSpec,omitempty"`
TransformSpec *TransformSpec `json:"transformSpec,omitempty"`
DimensionsSpec *DimensionsSpec `json:"dimensionsSpec,omitempty"`
GranularitySpec *GranularitySpec `json:"granularitySpec,omitempty"`
MetricSpec []Metric `json:"metricSpec,omitempty"`
}
// FlattenSpec is responsible for flattening nested input JSON data into Druid's flat data model.
type FlattenSpec struct {
UseFieldDiscovery bool `json:"useFieldDiscovery,omitempty"`
Fields FieldList `json:"fields"`
}
// TimestampSpec is responsible for configuring the primary timestamp.
type TimestampSpec struct {
Column string `json:"column"`
Format string `json:"format"`
}
// FieldList is a list of Fields for ingestion FlattenSpec.
type FieldList []Field
// Field defines a single filed configuration of the FlattenSpec.
type Field struct {
Type string `json:"type"`
Name string `json:"name"`
Expr string `json:"expr"`
}
// Transform defines a single filed transformation of the TransformSpec.
type Transform struct {
Type string `json:"type"`
Name string `json:"name"`
Expr string `json:"expression"`
}
// SpatialDimension represents single spatial dimension datum.
// https://druid.apache.org/docs/latest/querying/geo/#spatial-indexing
type SpatialDimension struct {
DimensionName string `json:"dimName"`
Dimensions []string `json:"dims,omitempty"`
}
// TransformSet is a unique set of transforms applied to the input.
type TransformSet []Transform
// DimensionSet is a unique set of druid datasource dimensions(labels).
type DimensionSet []DimensionSpec
// Dimension is a typed definition of a datasource dimension.
type Dimension struct {
Type string `json:"type"`
Name string `json:"name"`
}
// SpatialDimensionSet is a unique set of druid datasource spatial dimensions.
type SpatialDimensionSet []SpatialDimension
// DimensionExclusionsSet represents set of excluded dimensions.
type DimensionExclusionsSet []string
// DimensionsSpec is responsible for configuring Druid's dimensions. They're a
// set of columns in Druid's data model that can be used for grouping, filtering
// or applying aggregations.
// https://druid.apache.org/docs/latest/ingestion/ingestion-spec#dimensionsspec
type DimensionsSpec struct {
Dimensions DimensionSet `json:"dimensions,omitempty"`
DimensionExclusions DimensionExclusionsSet `json:"dimensionExclusions,omitempty"`
SpatialDimensions SpatialDimensionSet `json:"spatialDimensions,omitempty"`
IncludeAllDimensions bool `json:"includeAllDimensions,omitempty"`
UseSchemaDiscovery bool `json:"useSchemaDiscovery,omitempty"`
}
// DimensionSpec is a single dataset dimension that can be represented by a typed Dimension or a string value.
type DimensionSpec struct {
Value any
}
// QueryGranularitySpec is an umbrella type for different representations of query granularity, can be string or
// QueryGranularity value.
type QueryGranularitySpec struct {
Value any
}
// QueryGranularity is a typed representation of query granularity.
type QueryGranularity struct {
Type string `json:"type,omitempty"`
}
// GranularitySpec allows for configuring operations such as data segment
// partitioning, truncating timestamps, time chunk segmentation or roll-up.
// https://druid.apache.org/docs/latest/ingestion/ingestion-spec#granularityspec
type GranularitySpec struct {
Type string `json:"type"`
SegmentGranularity string `json:"segmentGranularity,omitempty"`
QueryGranularity *QueryGranularitySpec `json:"queryGranularity,omitempty"`
Rollup bool `json:"rollup"`
Intervals []string `json:"intervals,omitempty"`
}
// AutoScalerConfig is part of IOConfig that controls ingestion auto-scaling.
type AutoScalerConfig struct {
EnableTaskAutoScaler bool `json:"enableTaskAutoScaler"`
LagCollectionIntervalMillis int `json:"lagCollectionIntervalMillis"`
LagCollectionRangeMillis int `json:"lagCollectionRangeMillis"`
ScaleOutThreshold int `json:"scaleOutThreshold"`
TriggerScaleOutFractionThreshold float64 `json:"triggerScaleOutFractionThreshold"`
ScaleInThreshold int `json:"scaleInThreshold"`
TriggerScaleInFractionThreshold float64 `json:"triggerScaleInFractionThreshold"`
ScaleActionStartDelayMillis int `json:"scaleActionStartDelayMillis"`
ScaleActionPeriodMillis int `json:"scaleActionPeriodMillis"`
TaskCountMax int `json:"taskCountMax"`
TaskCountMin int `json:"taskCountMin"`
ScaleInStep int `json:"scaleInStep"`
ScaleOutStep int `json:"scaleOutStep"`
MinTriggerScaleActionFrequencyMillis int `json:"minTriggerScaleActionFrequencyMillis"`
}
// IdleConfig defines if and when stream Supervisor can become idle.
type IdleConfig struct {
Enabled bool `json:"enabled"`
InactiveAfterMillis int64 `json:"inactiveAfterMillis"`
}
// Firehose is an IOConfig firehose configuration.
type Firehose struct {
Type string `json:"type,omitempty"`
// EventReceiverFirehoseFactory fields.
ServiceName string `json:"serviceName,omitempty"`
BufferSize int `json:"bufferSize,omitempty"`
MaxIdleTime int64 `json:"maxIdleTime,omitempty"`
// FixedCountFirehoseFactory / ClippedFirehoseFactory / TimedShutoffFirehoseFactory fields.
Delegate []Firehose `json:"delegate,omitempty"`
Count int `json:"count,omitempty"`
Interval string `json:"interval,omitempty"`
ShutoffTime string `json:"shutoffTime,omitempty"`
}
// CompactionInputSpec is a specification for compaction task.
type CompactionInputSpec struct {
Type string `json:"type"`
// CompactionIntervalSpec fields.
Interval string `json:"interval,omitempty"`
Sha256OfSortedSegmentIds string `json:"sha256OfSortedSegmentIds,omitempty"`
// SpecificSegmentsSpec fields.
Segments []string `json:"segments,omitempty"`
}
// MetadataStorageUpdaterJobSpec is a specification of endpoint for HadoopIOConfig.
type MetadataStorageUpdaterJobSpec struct {
Type string `json:"type"`
ConnectURI string `json:"connectURI"`
User string `json:"user"`
Password string `json:"password"`
SegmentTable string `json:"segmentTable"`
CreteTable bool `json:"creteTable"`
Host string `json:"host"`
Port string `json:"port"`
DBCPProperties map[string]any `json:"dbcp"`
}
// IOConfig influences how data is read into Druid from a source system.
// https://druid.apache.org/docs/latest/ingestion/ingestion-spec/#ioconfig
type IOConfig struct {
Type string `json:"type,omitempty"`
// IndexIOConfig / RealtimeIOConfig shared field
Firehose *Firehose `json:"firehose,omitempty"`
// IndexIOConfig field
InputSource *InputSource `json:"inputSource,omitempty"`
AppendToExisting bool `json:"appendToExisting,omitempty"`
// IndexIOConfig / CompactionIOConfig shared fields.
DropExisting bool `json:"dropExisting,omitempty"`
// CompactionIOConfig / HadoopIOConfig fields.
InputSpec map[string]any `json:"inputSpec,omitempty"`
// CompactionIOConfig fields.
AllowNonAlignedInterval bool `json:"allowNonAlignedInterval,omitempty"`
// HadoopIOConfig fields.
MetadataUpdateSpec *MetadataStorageUpdaterJobSpec `json:"metadataUpdateSpec,omitempty"`
SegmentOutputPath string `json:"segmentOutputPath,omitempty"`
// KafkaIndexTaskIOConfig / KinesisIndexTaskIOConfig fields.
Topic string `json:"topic,omitempty"`
ConsumerProperties *ConsumerProperties `json:"consumerProperties,omitempty"`
TaskDuration string `json:"taskDuration,omitempty"`
Replicas int `json:"replicas,omitempty"`
TaskCount int `json:"taskCount,omitempty"`
UseEarliestOffset bool `json:"useEarliestOffset"`
AutoScalerConfig *AutoScalerConfig `json:"autoScalerConfig,omitempty"`
TaskGroupID int `json:"taskGroupID,omitempty"`
BaseSequenceName string `json:"baseSequenceName,omitempty"`
CompletionTimeout string `json:"completionTimeout,omitempty"`
PollTimeout int `json:"pollTimeout,omitempty"`
StartDelay string `json:"startDelay,omitempty"`
Period string `json:"period,omitempty"`
Stream string `json:"stream,omitempty"`
UseEarliestSequenceNumber bool `json:"useEarliestSequenceNumber,omitempty"`
// Common fields.
FlattenSpec *FlattenSpec `json:"flattenSpec,omitempty"`
InputFormat *InputFormat `json:"inputFormat,omitempty"`
IdleConfig *IdleConfig `json:"idleConfig,omitempty"`
}
// EnvironmentVariableDynamicConfigProvider provides configuration values via environment variables.
type EnvironmentVariableDynamicConfigProvider struct {
Type string `json:"type"`
Variables map[string]string `json:"variables"`
}
// MapStringDynamicConfigProvider passes config values as a <key, value> map.
type MapStringDynamicConfigProvider struct {
Config map[string]string `json:"config"`
}
// DynamicConfigProvider is an umbrella type for different DynamicConfigProviders.
type DynamicConfigProvider struct {
Value any
}
// ConsumerProperties is a set of properties that is passed to a specific
// consumer, i.e. Kafka consumer.
type ConsumerProperties struct {
BootstrapServers string `json:"bootstrap.servers,omitempty"`
DruidDynamicConfigProvider *DynamicConfigProvider `json:"druid.dynamic.config.provider,omitempty"`
}
// InputFormat specifies kafka messages format type and describes any conversions applied to
// the input data while parsing.
// Type can take values 'json', 'protobuf' or 'kafka'.
type InputFormat struct {
Type string `json:"type"`
// FlatTextInputFormat / DelimitedInputFormat fields.
Delimiter string `json:"delimiter,omitempty"`
ListDelimiter string `json:"listDelimiter,omitempty"`
FindColumnsFromHeader string `json:"findColumnsFromHeader,omitempty"`
SkipHeaderRows int `json:"skipHeaderRows,omitempty"`
Columns []string `json:"columns,omitempty"`
// JsonInputFormat fields.
FlattenSpec *FlattenSpec `json:"flattenSpec,omitempty"`
FeatureSpec map[string]bool `json:"featureSpec,omitempty"`
// Common CsvInputFormat / JsonInputFormat fields.
KeepNullColumns bool `json:"keepNullColumns,omitempty"`
AssumeNewlineDelimited bool `json:"assumeNewlineDelimited,omitempty"`
UseJsonNodeReader bool `json:"useJsonNodeReader,omitempty"`
}
// HttpInputSourceConfig is a field of HttpInputSource specification.
type HttpInputSourceConfig struct {
AllowedProtocols []string `json:" allowedProtocols,omitempty"`
}
// ConnectorConfig is connection configuration for Database.
type ConnectorConfig struct {
ConnectURI string `json:"connectURI"`
User string `json:"user"`
Password string `json:"password"`
}
// Database configuration for InputSource "sql".
type Database struct {
Type string `json:"type"`
ConnectorConfig *ConnectorConfig `json:"connectorConfig"`
}
// InputSource is a specification of the storage system where input data is stored.
type InputSource struct {
Type string `json:"type"`
// LocalInputSource fields.
BaseDir string `json:"baseDir,omitempty"`
Filter string `json:"filter,omitempty"`
Files []string `json:"files,omitempty"`
// HttpInputSource fields.
URIs []string `json:"uris,omitempty"`
HttpAuthenticationUsername string `json:"httpAuthenticationUsername,omitempty"`
HttpAuthenticationPassword string `json:"httpAuthenticationPassword,omitempty"`
HttpSourceConfig *HttpInputSourceConfig `json:"config,omitempty"`
// InlineInputSource fields.
Data string `json:"data,omitempty"`
// CombiningInputSource fields.
Delegates []InputSource `json:"delegates,omitempty"`
// SqlInputSource.
SQLs []string `json:"sqls,omitempty"`
Database *Database `json:"database,omitempty"`
// Druid input source.
Datasource string `json:"dataSource,omitempty"`
// ISO-8601 interval, which defines the time range to fetch the data over.
Interval string `json:"interval,omitempty"`
Metrics []string `json:"metrics,omitempty"`
}
// TransformSpec is responsible for transforming druid input data
// after it was read from kafka and after flattenSpec was applied.
// https://druid.apache.org/docs/latest/ingestion/ingestion-spec#transformspec
type TransformSpec struct {
Transforms TransformSet `json:"transforms"`
}
func (g *QueryGranularitySpec) UnmarshalJSON(b []byte) error {
var str string
if err := json.Unmarshal(b, &str); err == nil {
g.Value = str
return nil
}
var qg QueryGranularity
if err := json.Unmarshal(b, &qg); err == nil {
g.Value = qg
return nil
}
return fmt.Errorf("unsupported query granularity: %s", b)
}
func (g *QueryGranularitySpec) MarshalJSON() ([]byte, error) {
return json.Marshal(&g.Value)
}
func (g *DimensionSpec) UnmarshalJSON(b []byte) error {
var str string
if err := json.Unmarshal(b, &str); err == nil {
g.Value = str
return nil
}
var qg Dimension
if err := json.Unmarshal(b, &qg); err == nil {
g.Value = qg
return nil
}
return fmt.Errorf("unsupported dimension value: %s", b)
}
func (g *DimensionSpec) MarshalJSON() ([]byte, error) {
return json.Marshal(&g.Value)
}
func (p *DynamicConfigProvider) UnmarshalJSON(b []byte) error {
var evcp EnvironmentVariableDynamicConfigProvider
if err := json.Unmarshal(b, &evcp); err == nil && evcp.Type == "environment" {
p.Value = evcp
return nil
}
var mcp MapStringDynamicConfigProvider
if err := json.Unmarshal(b, &mcp); err == nil {
p.Value = mcp
return nil
}
return fmt.Errorf("unsupported dynamic config provider: %s", b)
}
func (p *DynamicConfigProvider) MarshalJSON() ([]byte, error) {
return json.Marshal(&p.Value)
}