/
FieldConfig.java
268 lines (230 loc) · 10.1 KB
/
FieldConfig.java
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
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.pinot.spi.config.table;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.NullNode;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import java.util.List;
import java.util.Map;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.apache.pinot.spi.config.BaseJsonConfig;
public class FieldConfig extends BaseJsonConfig {
public static final String BLOOM_FILTER_COLUMN_KEY = "createBloomFilter";
public static final String ON_HEAP_DICTIONARY_COLUMN_KEY = "useOnHeapDictionary";
public static final String VAR_LENGTH_DICTIONARY_COLUMN_KEY = "useVarLengthDictionary";
public static final String DERIVE_NUM_DOCS_PER_CHUNK_RAW_INDEX_KEY = "deriveNumDocsPerChunkForRawIndex";
public static final String RAW_INDEX_WRITER_VERSION = "rawIndexWriterVersion";
public static final String IS_SEGMENT_PARTITIONED_COLUMN_KEY = "isSegmentPartitioned";
public static final String TEXT_INDEX_REALTIME_READER_REFRESH_KEY = "textIndexRealtimeReaderRefreshThreshold";
// Lucene creates a query result cache if this option is enabled
// the cache improves performance of repeatable queries
public static final String TEXT_INDEX_ENABLE_QUERY_CACHE = "enableQueryCacheForTextIndex";
public static final String TEXT_INDEX_USE_AND_FOR_MULTI_TERM_QUERIES = "useANDForMultiTermTextIndexQueries";
public static final String TEXT_INDEX_NO_RAW_DATA = "noRawDataForTextIndex";
public static final String TEXT_INDEX_RAW_VALUE = "rawValueForTextIndex";
public static final String TEXT_INDEX_DEFAULT_RAW_VALUE = "n";
public static final String TEXT_INDEX_STOP_WORD_INCLUDE_KEY = "stopWordInclude";
public static final String TEXT_INDEX_STOP_WORD_EXCLUDE_KEY = "stopWordExclude";
public static final String TEXT_INDEX_LUCENE_USE_COMPOUND_FILE = "luceneUseCompoundFile";
public static final String TEXT_INDEX_LUCENE_MAX_BUFFER_SIZE_MB = "luceneMaxBufferSizeMB";
public static final String TEXT_INDEX_LUCENE_ANALYZER_CLASS = "luceneAnalyzerClass";
public static final String TEXT_INDEX_DEFAULT_LUCENE_ANALYZER_CLASS =
"org.apache.lucene.analysis.standard.StandardAnalyzer";
public static final String TEXT_INDEX_STOP_WORD_SEPERATOR = ",";
// "native" for native, default is Lucene
public static final String TEXT_FST_TYPE = "fstType";
public static final String TEXT_NATIVE_FST_LITERAL = "native";
// Config to disable forward index
public static final String FORWARD_INDEX_DISABLED = "forwardIndexDisabled";
public static final String DEFAULT_FORWARD_INDEX_DISABLED = Boolean.FALSE.toString();
public static final String TEXT_INDEX_ENABLE_PREFIX_SUFFIX_PHRASE_QUERIES =
"enablePrefixSuffixMatchingInPhraseQueries";
private final String _name;
private final EncodingType _encodingType;
private final List<IndexType> _indexTypes;
private final JsonNode _indexes;
private final JsonNode _tierOverwrites;
private final CompressionCodec _compressionCodec;
private final Map<String, String> _properties;
private final TimestampConfig _timestampConfig;
@Deprecated
public FieldConfig(String name, EncodingType encodingType, IndexType indexType, CompressionCodec compressionCodec,
Map<String, String> properties) {
this(name, encodingType, indexType, null, compressionCodec, null, null, properties, null);
}
public FieldConfig(String name, EncodingType encodingType, List<IndexType> indexTypes,
CompressionCodec compressionCodec, Map<String, String> properties) {
this(name, encodingType, null, indexTypes, compressionCodec, null, null, properties, null);
}
@Deprecated
public FieldConfig(String name, EncodingType encodingType, @Nullable IndexType indexType,
@Nullable List<IndexType> indexTypes, @Nullable CompressionCodec compressionCodec,
@Nullable TimestampConfig timestampConfig, @Nullable Map<String, String> properties) {
this(name, encodingType, indexType, indexTypes, compressionCodec, timestampConfig, null, properties, null);
}
@JsonCreator
public FieldConfig(@JsonProperty(value = "name", required = true) String name,
@JsonProperty(value = "encodingType") EncodingType encodingType,
@JsonProperty(value = "indexType") @Nullable IndexType indexType,
@JsonProperty(value = "indexTypes") @Nullable List<IndexType> indexTypes,
@JsonProperty(value = "compressionCodec") @Nullable CompressionCodec compressionCodec,
@JsonProperty(value = "timestampConfig") @Nullable TimestampConfig timestampConfig,
@JsonProperty(value = "indexes") @Nullable JsonNode indexes,
@JsonProperty(value = "properties") @Nullable Map<String, String> properties,
@JsonProperty(value = "tierOverwrites") @Nullable JsonNode tierOverwrites) {
Preconditions.checkArgument(name != null, "'name' must be configured");
_name = name;
_encodingType = encodingType == null ? EncodingType.DICTIONARY : encodingType;
_indexTypes =
indexTypes != null ? indexTypes : (indexType == null ? Lists.newArrayList() : Lists.newArrayList(indexType));
_compressionCodec = compressionCodec;
_timestampConfig = timestampConfig;
_properties = properties;
_indexes = indexes == null ? NullNode.getInstance() : indexes;
_tierOverwrites = tierOverwrites == null ? NullNode.getInstance() : tierOverwrites;
}
// If null, we will create dictionary encoded forward index by default
public enum EncodingType {
RAW, DICTIONARY
}
// If null, there won't be any index
public enum IndexType {
INVERTED, SORTED, TEXT, FST, H3, JSON, TIMESTAMP, VECTOR, RANGE
}
public enum CompressionCodec {
PASS_THROUGH(true, false),
SNAPPY(true, false),
ZSTANDARD(true, false),
LZ4(true, false),
// CLP is a special type of compression codec that isn't generally applicable to all RAW columns and has a
// special handling for log lines (see {@link CLPForwardIndexCreatorV1})
CLP(false, false),
GZIP(true, false),
// For MV dictionary encoded forward index, add a second level dictionary encoding for the multi-value entries
MV_ENTRY_DICT(false, true);
private final boolean _applicableToRawIndex;
private final boolean _applicableToDictEncodedIndex;
CompressionCodec(boolean applicableToRawIndex, boolean applicableToDictEncodedIndex) {
_applicableToRawIndex = applicableToRawIndex;
_applicableToDictEncodedIndex = applicableToDictEncodedIndex;
}
public boolean isApplicableToRawIndex() {
return _applicableToRawIndex;
}
public boolean isApplicableToDictEncodedIndex() {
return _applicableToDictEncodedIndex;
}
}
public String getName() {
return _name;
}
public EncodingType getEncodingType() {
return _encodingType;
}
@Nullable
@Deprecated
public IndexType getIndexType() {
return _indexTypes.size() > 0 ? _indexTypes.get(0) : null;
}
public List<IndexType> getIndexTypes() {
return _indexTypes;
}
public JsonNode getIndexes() {
return _indexes;
}
public JsonNode getTierOverwrites() {
return _tierOverwrites;
}
@Nullable
public CompressionCodec getCompressionCodec() {
return _compressionCodec;
}
@Nullable
public TimestampConfig getTimestampConfig() {
return _timestampConfig;
}
@Nullable
public Map<String, String> getProperties() {
return _properties;
}
public static class Builder {
@Nonnull
private String _name;
private EncodingType _encodingType;
private List<IndexType> _indexTypes;
private JsonNode _indexes;
private CompressionCodec _compressionCodec;
private Map<String, String> _properties;
private TimestampConfig _timestampConfig;
private JsonNode _tierOverwrites;
public Builder(@Nonnull String name) {
_name = name;
}
public Builder(FieldConfig other) {
_name = other._name;
_encodingType = other._encodingType;
_indexTypes = other._indexTypes;
_indexes = other._indexes;
_compressionCodec = other._compressionCodec;
_properties = other._properties;
_timestampConfig = other._timestampConfig;
_tierOverwrites = other._tierOverwrites;
}
public Builder withIndexes(JsonNode indexes) {
_indexes = indexes;
return this;
}
public Builder withName(String name) {
_name = name;
return this;
}
public Builder withEncodingType(EncodingType encodingType) {
_encodingType = encodingType;
return this;
}
public Builder withIndexTypes(List<IndexType> indexTypes) {
_indexTypes = indexTypes;
return this;
}
public Builder withCompressionCodec(CompressionCodec compressionCodec) {
_compressionCodec = compressionCodec;
return this;
}
public Builder withProperties(Map<String, String> properties) {
_properties = properties;
return this;
}
public Builder withTimestampConfig(TimestampConfig timestampConfig) {
_timestampConfig = timestampConfig;
return this;
}
public Builder withTierOverwrites(JsonNode tierOverwrites) {
_tierOverwrites = tierOverwrites;
return this;
}
public FieldConfig build() {
return new FieldConfig(_name, _encodingType, null, _indexTypes, _compressionCodec, _timestampConfig, _indexes,
_properties, _tierOverwrites);
}
}
}