Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
BuiltinsDb.java
Go to the documentation of this file.
1 // Copyright 2012 Cloudera Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 package com.cloudera.impala.catalog;
16 
17 import java.util.ArrayList;
18 import java.util.Map;
19 
28 import com.cloudera.impala.builtins.ScalarBuiltins;
29 import com.google.common.collect.ImmutableMap;
30 import com.google.common.collect.Lists;
31 
32 public class BuiltinsDb extends Db {
33  public BuiltinsDb(String name, Catalog catalog) {
34  super(name, catalog);
35  setIsSystemDb(true);
36  initBuiltins();
37  }
38 
42  private void initBuiltins() {
43  // Populate all aggregate builtins.
45 
46  // Populate all scalar builtins.
47  ArithmeticExpr.initBuiltins(this);
48  BinaryPredicate.initBuiltins(this);
49  CastExpr.initBuiltins(this);
50  CaseExpr.initBuiltins(this);
51  CompoundPredicate.initBuiltins(this);
52  InPredicate.initBuiltins(this);
53  IsNullPredicate.initBuiltins(this);
54  LikePredicate.initBuiltins(this);
55  ScalarBuiltins.initBuiltins(this);
56  }
57 
58  private static final Map<Type, String> SAMPLE_INIT_SYMBOL =
59  ImmutableMap.<Type, String>builder()
60  .put(Type.BOOLEAN,
61  "19ReservoirSampleInitIN10impala_udf10BooleanValEEEvPNS2_15FunctionContextEPNS2_9StringValE")
62  .put(Type.TINYINT,
63  "19ReservoirSampleInitIN10impala_udf10TinyIntValEEEvPNS2_15FunctionContextEPNS2_9StringValE")
64  .put(Type.SMALLINT,
65  "19ReservoirSampleInitIN10impala_udf11SmallIntValEEEvPNS2_15FunctionContextEPNS2_9StringValE")
66  .put(Type.INT,
67  "19ReservoirSampleInitIN10impala_udf6IntValEEEvPNS2_15FunctionContextEPNS2_9StringValE")
68  .put(Type.BIGINT,
69  "19ReservoirSampleInitIN10impala_udf9BigIntValEEEvPNS2_15FunctionContextEPNS2_9StringValE")
70  .put(Type.FLOAT,
71  "19ReservoirSampleInitIN10impala_udf8FloatValEEEvPNS2_15FunctionContextEPNS2_9StringValE")
72  .put(Type.DOUBLE,
73  "19ReservoirSampleInitIN10impala_udf9DoubleValEEEvPNS2_15FunctionContextEPNS2_9StringValE")
74  .put(Type.STRING,
75  "19ReservoirSampleInitIN10impala_udf9StringValEEEvPNS2_15FunctionContextEPS3_")
76  .put(Type.TIMESTAMP,
77  "19ReservoirSampleInitIN10impala_udf12TimestampValEEEvPNS2_15FunctionContextEPNS2_9StringValE")
78  .put(Type.DECIMAL,
79  "19ReservoirSampleInitIN10impala_udf10DecimalValEEEvPNS2_15FunctionContextEPNS2_9StringValE")
80  .build();
81 
82  private static final Map<Type, String> SAMPLE_SERIALIZE_SYMBOL =
83  ImmutableMap.<Type, String>builder()
84  .put(Type.BOOLEAN,
85  "24ReservoirSampleSerializeIN10impala_udf10BooleanValEEEKNS2_9StringValEPNS2_15FunctionContextERS5_")
86  .put(Type.TINYINT,
87  "24ReservoirSampleSerializeIN10impala_udf10TinyIntValEEEKNS2_9StringValEPNS2_15FunctionContextERS5_")
88  .put(Type.SMALLINT,
89  "24ReservoirSampleSerializeIN10impala_udf11SmallIntValEEEKNS2_9StringValEPNS2_15FunctionContextERS5_")
90  .put(Type.INT,
91  "24ReservoirSampleSerializeIN10impala_udf6IntValEEEKNS2_9StringValEPNS2_15FunctionContextERS5_")
92  .put(Type.BIGINT,
93  "24ReservoirSampleSerializeIN10impala_udf9BigIntValEEEKNS2_9StringValEPNS2_15FunctionContextERS5_")
94  .put(Type.FLOAT,
95  "24ReservoirSampleSerializeIN10impala_udf8FloatValEEEKNS2_9StringValEPNS2_15FunctionContextERS5_")
96  .put(Type.DOUBLE,
97  "24ReservoirSampleSerializeIN10impala_udf9DoubleValEEEKNS2_9StringValEPNS2_15FunctionContextERS5_")
98  .put(Type.STRING,
99  "24ReservoirSampleSerializeIN10impala_udf9StringValEEEKS3_PNS2_15FunctionContextERS4_")
100  .put(Type.TIMESTAMP,
101  "24ReservoirSampleSerializeIN10impala_udf12TimestampValEEEKNS2_9StringValEPNS2_15FunctionContextERS5_")
102  .put(Type.DECIMAL,
103  "24ReservoirSampleSerializeIN10impala_udf10DecimalValEEEKNS2_9StringValEPNS2_15FunctionContextERS5_")
104  .build();
105 
106  private static final Map<Type, String> SAMPLE_MERGE_SYMBOL =
107  ImmutableMap.<Type, String>builder()
108  .put(Type.BOOLEAN,
109  "20ReservoirSampleMergeIN10impala_udf10BooleanValEEEvPNS2_15FunctionContextERKNS2_9StringValEPS6_")
110  .put(Type.TINYINT,
111  "20ReservoirSampleMergeIN10impala_udf10TinyIntValEEEvPNS2_15FunctionContextERKNS2_9StringValEPS6_")
112  .put(Type.SMALLINT,
113  "20ReservoirSampleMergeIN10impala_udf11SmallIntValEEEvPNS2_15FunctionContextERKNS2_9StringValEPS6_")
114  .put(Type.INT,
115  "20ReservoirSampleMergeIN10impala_udf6IntValEEEvPNS2_15FunctionContextERKNS2_9StringValEPS6_")
116  .put(Type.BIGINT,
117  "20ReservoirSampleMergeIN10impala_udf9BigIntValEEEvPNS2_15FunctionContextERKNS2_9StringValEPS6_")
118  .put(Type.FLOAT,
119  "20ReservoirSampleMergeIN10impala_udf8FloatValEEEvPNS2_15FunctionContextERKNS2_9StringValEPS6_")
120  .put(Type.DOUBLE,
121  "20ReservoirSampleMergeIN10impala_udf9DoubleValEEEvPNS2_15FunctionContextERKNS2_9StringValEPS6_")
122  .put(Type.STRING,
123  "20ReservoirSampleMergeIN10impala_udf9StringValEEEvPNS2_15FunctionContextERKS3_PS3_")
124  .put(Type.TIMESTAMP,
125  "20ReservoirSampleMergeIN10impala_udf12TimestampValEEEvPNS2_15FunctionContextERKNS2_9StringValEPS6_")
126  .put(Type.DECIMAL,
127  "20ReservoirSampleMergeIN10impala_udf10DecimalValEEEvPNS2_15FunctionContextERKNS2_9StringValEPS6_")
128  .build();
129 
130  private static final Map<Type, String> SAMPLE_UPDATE_SYMBOL =
131  ImmutableMap.<Type, String>builder()
132  .put(Type.BOOLEAN,
133  "21ReservoirSampleUpdateIN10impala_udf10BooleanValEEEvPNS2_15FunctionContextERKT_PNS2_9StringValE")
134  .put(Type.TINYINT,
135  "21ReservoirSampleUpdateIN10impala_udf10TinyIntValEEEvPNS2_15FunctionContextERKT_PNS2_9StringValE")
136  .put(Type.SMALLINT,
137  "21ReservoirSampleUpdateIN10impala_udf11SmallIntValEEEvPNS2_15FunctionContextERKT_PNS2_9StringValE")
138  .put(Type.INT,
139  "21ReservoirSampleUpdateIN10impala_udf6IntValEEEvPNS2_15FunctionContextERKT_PNS2_9StringValE")
140  .put(Type.BIGINT,
141  "21ReservoirSampleUpdateIN10impala_udf9BigIntValEEEvPNS2_15FunctionContextERKT_PNS2_9StringValE")
142  .put(Type.FLOAT,
143  "21ReservoirSampleUpdateIN10impala_udf8FloatValEEEvPNS2_15FunctionContextERKT_PNS2_9StringValE")
144  .put(Type.DOUBLE,
145  "21ReservoirSampleUpdateIN10impala_udf9DoubleValEEEvPNS2_15FunctionContextERKT_PNS2_9StringValE")
146  .put(Type.STRING,
147  "21ReservoirSampleUpdateIN10impala_udf9StringValEEEvPNS2_15FunctionContextERKT_PS3_")
148  .put(Type.TIMESTAMP,
149  "21ReservoirSampleUpdateIN10impala_udf12TimestampValEEEvPNS2_15FunctionContextERKT_PNS2_9StringValE")
150  .put(Type.DECIMAL,
151  "21ReservoirSampleUpdateIN10impala_udf10DecimalValEEEvPNS2_15FunctionContextERKT_PNS2_9StringValE")
152  .build();
153 
154  private static final Map<Type, String> SAMPLE_FINALIZE_SYMBOL =
155  ImmutableMap.<Type, String>builder()
156  .put(Type.BOOLEAN,
157  "23ReservoirSampleFinalizeIN10impala_udf10BooleanValEEENS2_9StringValEPNS2_15FunctionContextERKS4_")
158  .put(Type.TINYINT,
159  "23ReservoirSampleFinalizeIN10impala_udf10TinyIntValEEENS2_9StringValEPNS2_15FunctionContextERKS4_")
160  .put(Type.SMALLINT,
161  "23ReservoirSampleFinalizeIN10impala_udf11SmallIntValEEENS2_9StringValEPNS2_15FunctionContextERKS4_")
162  .put(Type.INT,
163  "23ReservoirSampleFinalizeIN10impala_udf6IntValEEENS2_9StringValEPNS2_15FunctionContextERKS4_")
164  .put(Type.BIGINT,
165  "23ReservoirSampleFinalizeIN10impala_udf9BigIntValEEENS2_9StringValEPNS2_15FunctionContextERKS4_")
166  .put(Type.FLOAT,
167  "23ReservoirSampleFinalizeIN10impala_udf8FloatValEEENS2_9StringValEPNS2_15FunctionContextERKS4_")
168  .put(Type.DOUBLE,
169  "23ReservoirSampleFinalizeIN10impala_udf9DoubleValEEENS2_9StringValEPNS2_15FunctionContextERKS4_")
170  .put(Type.STRING,
171  "23ReservoirSampleFinalizeIN10impala_udf9StringValEEES3_PNS2_15FunctionContextERKS3_")
172  .put(Type.TIMESTAMP,
173  "23ReservoirSampleFinalizeIN10impala_udf12TimestampValEEENS2_9StringValEPNS2_15FunctionContextERKS4_")
174  .put(Type.DECIMAL,
175  "23ReservoirSampleFinalizeIN10impala_udf10DecimalValEEENS2_9StringValEPNS2_15FunctionContextERKS4_")
176  .build();
177 
178  private static final Map<Type, String> APPX_MEDIAN_FINALIZE_SYMBOL =
179  ImmutableMap.<Type, String>builder()
180  .put(Type.BOOLEAN,
181  "18AppxMedianFinalizeIN10impala_udf10BooleanValEEET_PNS2_15FunctionContextERKNS2_9StringValE")
182  .put(Type.DECIMAL,
183  "18AppxMedianFinalizeIN10impala_udf10DecimalValEEET_PNS2_15FunctionContextERKNS2_9StringValE")
184  .put(Type.TINYINT,
185  "18AppxMedianFinalizeIN10impala_udf10TinyIntValEEET_PNS2_15FunctionContextERKNS2_9StringValE")
186  .put(Type.SMALLINT,
187  "18AppxMedianFinalizeIN10impala_udf11SmallIntValEEET_PNS2_15FunctionContextERKNS2_9StringValE")
188  .put(Type.TIMESTAMP,
189  "18AppxMedianFinalizeIN10impala_udf12TimestampValEEET_PNS2_15FunctionContextERKNS2_9StringValE")
190  .put(Type.INT,
191  "18AppxMedianFinalizeIN10impala_udf6IntValEEET_PNS2_15FunctionContextERKNS2_9StringValE")
192  .put(Type.FLOAT,
193  "18AppxMedianFinalizeIN10impala_udf8FloatValEEET_PNS2_15FunctionContextERKNS2_9StringValE")
194  .put(Type.BIGINT,
195  "18AppxMedianFinalizeIN10impala_udf9BigIntValEEET_PNS2_15FunctionContextERKNS2_9StringValE")
196  .put(Type.DOUBLE,
197  "18AppxMedianFinalizeIN10impala_udf9DoubleValEEET_PNS2_15FunctionContextERKNS2_9StringValE")
198  .put(Type.STRING,
199  "18AppxMedianFinalizeIN10impala_udf9StringValEEET_PNS2_15FunctionContextERKS3_")
200  .build();
201 
202  private static final Map<Type, String> HISTOGRAM_FINALIZE_SYMBOL =
203  ImmutableMap.<Type, String>builder()
204  .put(Type.BOOLEAN,
205  "17HistogramFinalizeIN10impala_udf10BooleanValEEENS2_9StringValEPNS2_15FunctionContextERKS4_")
206  .put(Type.TINYINT,
207  "17HistogramFinalizeIN10impala_udf10TinyIntValEEENS2_9StringValEPNS2_15FunctionContextERKS4_")
208  .put(Type.SMALLINT,
209  "17HistogramFinalizeIN10impala_udf11SmallIntValEEENS2_9StringValEPNS2_15FunctionContextERKS4_")
210  .put(Type.INT,
211  "17HistogramFinalizeIN10impala_udf6IntValEEENS2_9StringValEPNS2_15FunctionContextERKS4_")
212  .put(Type.BIGINT,
213  "17HistogramFinalizeIN10impala_udf9BigIntValEEENS2_9StringValEPNS2_15FunctionContextERKS4_")
214  .put(Type.FLOAT,
215  "17HistogramFinalizeIN10impala_udf8FloatValEEENS2_9StringValEPNS2_15FunctionContextERKS4_")
216  .put(Type.DOUBLE,
217  "17HistogramFinalizeIN10impala_udf9DoubleValEEENS2_9StringValEPNS2_15FunctionContextERKS4_")
218  .put(Type.STRING,
219  "17HistogramFinalizeIN10impala_udf9StringValEEES3_PNS2_15FunctionContextERKS3_")
220  .put(Type.TIMESTAMP,
221  "17HistogramFinalizeIN10impala_udf12TimestampValEEENS2_9StringValEPNS2_15FunctionContextERKS4_")
222  .put(Type.DECIMAL,
223  "17HistogramFinalizeIN10impala_udf10DecimalValEEENS2_9StringValEPNS2_15FunctionContextERKS4_")
224  .build();
225 
226  private static final Map<Type, String> HLL_UPDATE_SYMBOL =
227  ImmutableMap.<Type, String>builder()
228  .put(Type.BOOLEAN,
229  "9HllUpdateIN10impala_udf10BooleanValEEEvPNS2_15FunctionContextERKT_PNS2_9StringValE")
230  .put(Type.TINYINT,
231  "9HllUpdateIN10impala_udf10TinyIntValEEEvPNS2_15FunctionContextERKT_PNS2_9StringValE")
232  .put(Type.SMALLINT,
233  "9HllUpdateIN10impala_udf11SmallIntValEEEvPNS2_15FunctionContextERKT_PNS2_9StringValE")
234  .put(Type.INT,
235  "9HllUpdateIN10impala_udf6IntValEEEvPNS2_15FunctionContextERKT_PNS2_9StringValE")
236  .put(Type.BIGINT,
237  "9HllUpdateIN10impala_udf9BigIntValEEEvPNS2_15FunctionContextERKT_PNS2_9StringValE")
238  .put(Type.FLOAT,
239  "9HllUpdateIN10impala_udf8FloatValEEEvPNS2_15FunctionContextERKT_PNS2_9StringValE")
240  .put(Type.DOUBLE,
241  "9HllUpdateIN10impala_udf9DoubleValEEEvPNS2_15FunctionContextERKT_PNS2_9StringValE")
242  .put(Type.STRING,
243  "9HllUpdateIN10impala_udf9StringValEEEvPNS2_15FunctionContextERKT_PS3_")
244  .put(Type.TIMESTAMP,
245  "9HllUpdateIN10impala_udf12TimestampValEEEvPNS2_15FunctionContextERKT_PNS2_9StringValE")
246  .put(Type.DECIMAL,
247  "9HllUpdateIN10impala_udf10DecimalValEEEvPNS2_15FunctionContextERKT_PNS2_9StringValE")
248  .build();
249 
250  private static final Map<Type, String> PC_UPDATE_SYMBOL =
251  ImmutableMap.<Type, String>builder()
252  .put(Type.BOOLEAN,
253  "8PcUpdateIN10impala_udf10BooleanValEEEvPNS2_15FunctionContextERKT_PNS2_9StringValE")
254  .put(Type.TINYINT,
255  "8PcUpdateIN10impala_udf10TinyIntValEEEvPNS2_15FunctionContextERKT_PNS2_9StringValE")
256  .put(Type.SMALLINT,
257  "8PcUpdateIN10impala_udf11SmallIntValEEEvPNS2_15FunctionContextERKT_PNS2_9StringValE")
258  .put(Type.INT,
259  "8PcUpdateIN10impala_udf6IntValEEEvPNS2_15FunctionContextERKT_PNS2_9StringValE")
260  .put(Type.BIGINT,
261  "8PcUpdateIN10impala_udf9BigIntValEEEvPNS2_15FunctionContextERKT_PNS2_9StringValE")
262  .put(Type.FLOAT,
263  "8PcUpdateIN10impala_udf8FloatValEEEvPNS2_15FunctionContextERKT_PNS2_9StringValE")
264  .put(Type.DOUBLE,
265  "8PcUpdateIN10impala_udf9DoubleValEEEvPNS2_15FunctionContextERKT_PNS2_9StringValE")
266  .put(Type.STRING,
267  "8PcUpdateIN10impala_udf9StringValEEEvPNS2_15FunctionContextERKT_PS3_")
268  .put(Type.TIMESTAMP,
269  "8PcUpdateIN10impala_udf12TimestampValEEEvPNS2_15FunctionContextERKT_PNS2_9StringValE")
270  .put(Type.DECIMAL,
271  "8PcUpdateIN10impala_udf10DecimalValEEEvPNS2_15FunctionContextERKT_PNS2_9StringValE")
272  .build();
273 
274  private static final Map<Type, String> PCSA_UPDATE_SYMBOL =
275  ImmutableMap.<Type, String>builder()
276  .put(Type.BOOLEAN,
277  "10PcsaUpdateIN10impala_udf10BooleanValEEEvPNS2_15FunctionContextERKT_PNS2_9StringValE")
278  .put(Type.TINYINT,
279  "10PcsaUpdateIN10impala_udf10TinyIntValEEEvPNS2_15FunctionContextERKT_PNS2_9StringValE")
280  .put(Type.SMALLINT,
281  "10PcsaUpdateIN10impala_udf11SmallIntValEEEvPNS2_15FunctionContextERKT_PNS2_9StringValE")
282  .put(Type.INT,
283  "10PcsaUpdateIN10impala_udf6IntValEEEvPNS2_15FunctionContextERKT_PNS2_9StringValE")
284  .put(Type.BIGINT,
285  "10PcsaUpdateIN10impala_udf9BigIntValEEEvPNS2_15FunctionContextERKT_PNS2_9StringValE")
286  .put(Type.FLOAT,
287  "10PcsaUpdateIN10impala_udf8FloatValEEEvPNS2_15FunctionContextERKT_PNS2_9StringValE")
288  .put(Type.DOUBLE,
289  "10PcsaUpdateIN10impala_udf9DoubleValEEEvPNS2_15FunctionContextERKT_PNS2_9StringValE")
290  .put(Type.STRING,
291  "10PcsaUpdateIN10impala_udf9StringValEEEvPNS2_15FunctionContextERKT_PS3_")
292  .put(Type.TIMESTAMP,
293  "10PcsaUpdateIN10impala_udf12TimestampValEEEvPNS2_15FunctionContextERKT_PNS2_9StringValE")
294  .put(Type.DECIMAL,
295  "10PcsaUpdateIN10impala_udf10DecimalValEEEvPNS2_15FunctionContextERKT_PNS2_9StringValE")
296  .build();
297 
298  private static final Map<Type, String> MIN_UPDATE_SYMBOL =
299  ImmutableMap.<Type, String>builder()
300  .put(Type.BOOLEAN,
301  "3MinIN10impala_udf10BooleanValEEEvPNS2_15FunctionContextERKT_PS6_")
302  .put(Type.TINYINT,
303  "3MinIN10impala_udf10TinyIntValEEEvPNS2_15FunctionContextERKT_PS6_")
304  .put(Type.SMALLINT,
305  "3MinIN10impala_udf11SmallIntValEEEvPNS2_15FunctionContextERKT_PS6_")
306  .put(Type.INT,
307  "3MinIN10impala_udf6IntValEEEvPNS2_15FunctionContextERKT_PS6_")
308  .put(Type.BIGINT,
309  "3MinIN10impala_udf9BigIntValEEEvPNS2_15FunctionContextERKT_PS6_")
310  .put(Type.FLOAT,
311  "3MinIN10impala_udf8FloatValEEEvPNS2_15FunctionContextERKT_PS6_")
312  .put(Type.DOUBLE,
313  "3MinIN10impala_udf9DoubleValEEEvPNS2_15FunctionContextERKT_PS6_")
314  .put(Type.STRING,
315  "3MinIN10impala_udf9StringValEEEvPNS2_15FunctionContextERKT_PS6_")
316  .put(Type.TIMESTAMP,
317  "3MinIN10impala_udf12TimestampValEEEvPNS2_15FunctionContextERKT_PS6_")
318  .put(Type.DECIMAL,
319  "3MinIN10impala_udf10DecimalValEEEvPNS2_15FunctionContextERKT_PS6_")
320  .build();
321 
322  private static final Map<Type, String> MAX_UPDATE_SYMBOL =
323  ImmutableMap.<Type, String>builder()
324  .put(Type.BOOLEAN,
325  "3MaxIN10impala_udf10BooleanValEEEvPNS2_15FunctionContextERKT_PS6_")
326  .put(Type.TINYINT,
327  "3MaxIN10impala_udf10TinyIntValEEEvPNS2_15FunctionContextERKT_PS6_")
328  .put(Type.SMALLINT,
329  "3MaxIN10impala_udf11SmallIntValEEEvPNS2_15FunctionContextERKT_PS6_")
330  .put(Type.INT,
331  "3MaxIN10impala_udf6IntValEEEvPNS2_15FunctionContextERKT_PS6_")
332  .put(Type.BIGINT,
333  "3MaxIN10impala_udf9BigIntValEEEvPNS2_15FunctionContextERKT_PS6_")
334  .put(Type.FLOAT,
335  "3MaxIN10impala_udf8FloatValEEEvPNS2_15FunctionContextERKT_PS6_")
336  .put(Type.DOUBLE,
337  "3MaxIN10impala_udf9DoubleValEEEvPNS2_15FunctionContextERKT_PS6_")
338  .put(Type.STRING,
339  "3MaxIN10impala_udf9StringValEEEvPNS2_15FunctionContextERKT_PS6_")
340  .put(Type.TIMESTAMP,
341  "3MaxIN10impala_udf12TimestampValEEEvPNS2_15FunctionContextERKT_PS6_")
342  .put(Type.DECIMAL,
343  "3MaxIN10impala_udf10DecimalValEEEvPNS2_15FunctionContextERKT_PS6_")
344  .build();
345 
346  private static final Map<Type, String> STDDEV_UPDATE_SYMBOL =
347  ImmutableMap.<Type, String>builder()
348  .put(Type.TINYINT,
349  "14KnuthVarUpdateIN10impala_udf10TinyIntValEEEvPNS2_15FunctionContextERKT_PNS2_9StringValE")
350  .put(Type.SMALLINT,
351  "14KnuthVarUpdateIN10impala_udf11SmallIntValEEEvPNS2_15FunctionContextERKT_PNS2_9StringValE")
352  .put(Type.INT,
353  "14KnuthVarUpdateIN10impala_udf6IntValEEEvPNS2_15FunctionContextERKT_PNS2_9StringValE")
354  .put(Type.BIGINT,
355  "14KnuthVarUpdateIN10impala_udf9BigIntValEEEvPNS2_15FunctionContextERKT_PNS2_9StringValE")
356  .put(Type.FLOAT,
357  "14KnuthVarUpdateIN10impala_udf8FloatValEEEvPNS2_15FunctionContextERKT_PNS2_9StringValE")
358  .put(Type.DOUBLE,
359  "14KnuthVarUpdateIN10impala_udf9DoubleValEEEvPNS2_15FunctionContextERKT_PNS2_9StringValE")
360  .build();
361  private static final Map<Type, String> OFFSET_FN_INIT_SYMBOL =
362  ImmutableMap.<Type, String>builder()
363  .put(Type.BOOLEAN,
364  "12OffsetFnInitIN10impala_udf10BooleanValEEEvPNS2_15FunctionContextEPT_")
365  .put(Type.DECIMAL,
366  "12OffsetFnInitIN10impala_udf10DecimalValEEEvPNS2_15FunctionContextEPT_")
367  .put(Type.TINYINT,
368  "12OffsetFnInitIN10impala_udf10TinyIntValEEEvPNS2_15FunctionContextEPT_")
369  .put(Type.SMALLINT,
370  "12OffsetFnInitIN10impala_udf11SmallIntValEEEvPNS2_15FunctionContextEPT_")
371  .put(Type.TIMESTAMP,
372  "12OffsetFnInitIN10impala_udf12TimestampValEEEvPNS2_15FunctionContextEPT_")
373  .put(Type.INT,
374  "12OffsetFnInitIN10impala_udf6IntValEEEvPNS2_15FunctionContextEPT_")
375  .put(Type.FLOAT,
376  "12OffsetFnInitIN10impala_udf8FloatValEEEvPNS2_15FunctionContextEPT_")
377  .put(Type.BIGINT,
378  "12OffsetFnInitIN10impala_udf9BigIntValEEEvPNS2_15FunctionContextEPT_")
379  .put(Type.DOUBLE,
380  "12OffsetFnInitIN10impala_udf9DoubleValEEEvPNS2_15FunctionContextEPT_")
381  .put(Type.STRING,
382  "12OffsetFnInitIN10impala_udf9StringValEEEvPNS2_15FunctionContextEPT_")
383  .build();
384 
385  private static final Map<Type, String> OFFSET_FN_UPDATE_SYMBOL =
386  ImmutableMap.<Type, String>builder()
387  .put(Type.BOOLEAN,
388  "14OffsetFnUpdateIN10impala_udf10BooleanValEEEvPNS2_15FunctionContextERKT_RKNS2_9BigIntValES8_PS6_")
389  .put(Type.DECIMAL,
390  "14OffsetFnUpdateIN10impala_udf10DecimalValEEEvPNS2_15FunctionContextERKT_RKNS2_9BigIntValES8_PS6_")
391  .put(Type.TINYINT,
392  "14OffsetFnUpdateIN10impala_udf10TinyIntValEEEvPNS2_15FunctionContextERKT_RKNS2_9BigIntValES8_PS6_")
393  .put(Type.SMALLINT,
394  "14OffsetFnUpdateIN10impala_udf11SmallIntValEEEvPNS2_15FunctionContextERKT_RKNS2_9BigIntValES8_PS6_")
395  .put(Type.TIMESTAMP,
396  "14OffsetFnUpdateIN10impala_udf12TimestampValEEEvPNS2_15FunctionContextERKT_RKNS2_9BigIntValES8_PS6_")
397  .put(Type.INT,
398  "14OffsetFnUpdateIN10impala_udf6IntValEEEvPNS2_15FunctionContextERKT_RKNS2_9BigIntValES8_PS6_")
399  .put(Type.FLOAT,
400  "14OffsetFnUpdateIN10impala_udf8FloatValEEEvPNS2_15FunctionContextERKT_RKNS2_9BigIntValES8_PS6_")
401  .put(Type.BIGINT,
402  "14OffsetFnUpdateIN10impala_udf9BigIntValEEEvPNS2_15FunctionContextERKT_RKS3_S8_PS6_")
403  .put(Type.DOUBLE,
404  "14OffsetFnUpdateIN10impala_udf9DoubleValEEEvPNS2_15FunctionContextERKT_RKNS2_9BigIntValES8_PS6_")
405  .put(Type.STRING,
406  "14OffsetFnUpdateIN10impala_udf9StringValEEEvPNS2_15FunctionContextERKT_RKNS2_9BigIntValES8_PS6_")
407  .build();
408 
409  private static final Map<Type, String> LAST_VALUE_UPDATE_SYMBOL =
410  ImmutableMap.<Type, String>builder()
411  .put(Type.BOOLEAN,
412  "13LastValUpdateIN10impala_udf10BooleanValEEEvPNS2_15FunctionContextERKT_PS6_")
413  .put(Type.DECIMAL,
414  "13LastValUpdateIN10impala_udf10DecimalValEEEvPNS2_15FunctionContextERKT_PS6_")
415  .put(Type.TINYINT,
416  "13LastValUpdateIN10impala_udf10TinyIntValEEEvPNS2_15FunctionContextERKT_PS6_")
417  .put(Type.SMALLINT,
418  "13LastValUpdateIN10impala_udf11SmallIntValEEEvPNS2_15FunctionContextERKT_PS6_")
419  .put(Type.TIMESTAMP,
420  "13LastValUpdateIN10impala_udf12TimestampValEEEvPNS2_15FunctionContextERKT_PS6_")
421  .put(Type.INT,
422  "13LastValUpdateIN10impala_udf6IntValEEEvPNS2_15FunctionContextERKT_PS6_")
423  .put(Type.FLOAT,
424  "13LastValUpdateIN10impala_udf8FloatValEEEvPNS2_15FunctionContextERKT_PS6_")
425  .put(Type.BIGINT,
426  "13LastValUpdateIN10impala_udf9BigIntValEEEvPNS2_15FunctionContextERKT_PS6_")
427  .put(Type.DOUBLE,
428  "13LastValUpdateIN10impala_udf9DoubleValEEEvPNS2_15FunctionContextERKT_PS6_")
429  .put(Type.STRING,
430  "13LastValUpdateIN10impala_udf9StringValEEEvPNS2_15FunctionContextERKT_PS6_")
431  .build();
432 
433  private static final Map<Type, String> FIRST_VALUE_REWRITE_UPDATE_SYMBOL =
434  ImmutableMap.<Type, String>builder()
435  .put(Type.BOOLEAN,
436  "21FirstValRewriteUpdateIN10impala_udf10BooleanValEEEvPNS2_15FunctionContextERKT_RKNS2_9BigIntValEPS6_")
437  .put(Type.DECIMAL,
438  "21FirstValRewriteUpdateIN10impala_udf10DecimalValEEEvPNS2_15FunctionContextERKT_RKNS2_9BigIntValEPS6_")
439  .put(Type.TINYINT,
440  "21FirstValRewriteUpdateIN10impala_udf10TinyIntValEEEvPNS2_15FunctionContextERKT_RKNS2_9BigIntValEPS6_")
441  .put(Type.SMALLINT,
442  "21FirstValRewriteUpdateIN10impala_udf11SmallIntValEEEvPNS2_15FunctionContextERKT_RKNS2_9BigIntValEPS6_")
443  .put(Type.TIMESTAMP,
444  "21FirstValRewriteUpdateIN10impala_udf12TimestampValEEEvPNS2_15FunctionContextERKT_RKNS2_9BigIntValEPS6_")
445  .put(Type.INT,
446  "21FirstValRewriteUpdateIN10impala_udf6IntValEEEvPNS2_15FunctionContextERKT_RKNS2_9BigIntValEPS6_")
447  .put(Type.FLOAT,
448  "21FirstValRewriteUpdateIN10impala_udf8FloatValEEEvPNS2_15FunctionContextERKT_RKNS2_9BigIntValEPS6_")
449  .put(Type.BIGINT,
450  "21FirstValRewriteUpdateIN10impala_udf9BigIntValEEEvPNS2_15FunctionContextERKT_RKS3_PS6_")
451  .put(Type.DOUBLE,
452  "21FirstValRewriteUpdateIN10impala_udf9DoubleValEEEvPNS2_15FunctionContextERKT_RKNS2_9BigIntValEPS6_")
453  .put(Type.STRING,
454  "21FirstValRewriteUpdateIN10impala_udf9StringValEEEvPNS2_15FunctionContextERKT_RKNS2_9BigIntValEPS6_")
455  .build();
456 
457  private static final Map<Type, String> LAST_VALUE_REMOVE_SYMBOL =
458  ImmutableMap.<Type, String>builder()
459  .put(Type.BOOLEAN,
460  "13LastValRemoveIN10impala_udf10BooleanValEEEvPNS2_15FunctionContextERKT_PS6_")
461  .put(Type.DECIMAL,
462  "13LastValRemoveIN10impala_udf10DecimalValEEEvPNS2_15FunctionContextERKT_PS6_")
463  .put(Type.TINYINT,
464  "13LastValRemoveIN10impala_udf10TinyIntValEEEvPNS2_15FunctionContextERKT_PS6_")
465  .put(Type.SMALLINT,
466  "13LastValRemoveIN10impala_udf11SmallIntValEEEvPNS2_15FunctionContextERKT_PS6_")
467  .put(Type.TIMESTAMP,
468  "13LastValRemoveIN10impala_udf12TimestampValEEEvPNS2_15FunctionContextERKT_PS6_")
469  .put(Type.INT,
470  "13LastValRemoveIN10impala_udf6IntValEEEvPNS2_15FunctionContextERKT_PS6_")
471  .put(Type.FLOAT,
472  "13LastValRemoveIN10impala_udf8FloatValEEEvPNS2_15FunctionContextERKT_PS6_")
473  .put(Type.BIGINT,
474  "13LastValRemoveIN10impala_udf9BigIntValEEEvPNS2_15FunctionContextERKT_PS6_")
475  .put(Type.DOUBLE,
476  "13LastValRemoveIN10impala_udf9DoubleValEEEvPNS2_15FunctionContextERKT_PS6_")
477  .put(Type.STRING,
478  "13LastValRemoveIN10impala_udf9StringValEEEvPNS2_15FunctionContextERKT_PS6_")
479  .build();
480 
481  private static final Map<Type, String> FIRST_VALUE_UPDATE_SYMBOL =
482  ImmutableMap.<Type, String>builder()
483  .put(Type.BOOLEAN,
484  "14FirstValUpdateIN10impala_udf10BooleanValEEEvPNS2_15FunctionContextERKT_PS6_")
485  .put(Type.DECIMAL,
486  "14FirstValUpdateIN10impala_udf10DecimalValEEEvPNS2_15FunctionContextERKT_PS6_")
487  .put(Type.TINYINT,
488  "14FirstValUpdateIN10impala_udf10TinyIntValEEEvPNS2_15FunctionContextERKT_PS6_")
489  .put(Type.SMALLINT,
490  "14FirstValUpdateIN10impala_udf11SmallIntValEEEvPNS2_15FunctionContextERKT_PS6_")
491  .put(Type.TIMESTAMP,
492  "14FirstValUpdateIN10impala_udf12TimestampValEEEvPNS2_15FunctionContextERKT_PS6_")
493  .put(Type.INT,
494  "14FirstValUpdateIN10impala_udf6IntValEEEvPNS2_15FunctionContextERKT_PS6_")
495  .put(Type.FLOAT,
496  "14FirstValUpdateIN10impala_udf8FloatValEEEvPNS2_15FunctionContextERKT_PS6_")
497  .put(Type.BIGINT,
498  "14FirstValUpdateIN10impala_udf9BigIntValEEEvPNS2_15FunctionContextERKT_PS6_")
499  .put(Type.DOUBLE,
500  "14FirstValUpdateIN10impala_udf9DoubleValEEEvPNS2_15FunctionContextERKT_PS6_")
501  .put(Type.STRING,
502  "14FirstValUpdateIN10impala_udf9StringValEEEvPNS2_15FunctionContextERKT_PS6_")
503  .build();
504 
505  // Populate all the aggregate builtins in the catalog.
506  // null symbols indicate the function does not need that step of the evaluation.
507  // An empty symbol indicates a TODO for the BE to implement the function.
508  // TODO: We could also generate this in python but I'm not sure that is easier.
509  private void initAggregateBuiltins() {
510  final String prefix = "_ZN6impala18AggregateFunctions";
511  final String initNullString = prefix +
512  "14InitNullStringEPN10impala_udf15FunctionContextEPNS1_9StringValE";
513  final String initNull = prefix +
514  "8InitNullEPN10impala_udf15FunctionContextEPNS1_6AnyValE";
515  final String stringValSerializeOrFinalize = prefix +
516  "28StringValSerializeOrFinalizeEPN10impala_udf15FunctionContextERKNS1_9StringValE";
517  final String stringValGetValue = prefix +
518  "17StringValGetValueEPN10impala_udf15FunctionContextERKNS1_9StringValE";
519 
520  Db db = this;
521  // Count (*)
522  db.addBuiltin(AggregateFunction.createBuiltin(db, "count",
523  new ArrayList<Type>(), Type.BIGINT, Type.BIGINT,
524  prefix + "8InitZeroIN10impala_udf9BigIntValEEEvPNS2_15FunctionContextEPT_",
525  prefix + "15CountStarUpdateEPN10impala_udf15FunctionContextEPNS1_9BigIntValE",
526  prefix + "10CountMergeEPN10impala_udf15FunctionContextERKNS1_9BigIntValEPS4_",
527  null, null,
528  prefix + "15CountStarRemoveEPN10impala_udf15FunctionContextEPNS1_9BigIntValE",
529  null, false, true, true));
530 
531  for (Type t: Type.getSupportedTypes()) {
532  if (t.isNull()) continue; // NULL is handled through type promotion.
533  if (t.isScalarType(PrimitiveType.CHAR)) continue; // promoted to STRING
534  if (t.isScalarType(PrimitiveType.VARCHAR)) continue; // promoted to STRING
535  // Count
536  db.addBuiltin(AggregateFunction.createBuiltin(db, "count",
537  Lists.newArrayList(t), Type.BIGINT, Type.BIGINT,
538  prefix + "8InitZeroIN10impala_udf9BigIntValEEEvPNS2_15FunctionContextEPT_",
539  prefix + "11CountUpdateEPN10impala_udf15FunctionContextERKNS1_6AnyValEPNS1_9BigIntValE",
540  prefix + "10CountMergeEPN10impala_udf15FunctionContextERKNS1_9BigIntValEPS4_",
541  null, null,
542  prefix + "11CountRemoveEPN10impala_udf15FunctionContextERKNS1_6AnyValEPNS1_9BigIntValE",
543  null, false, true, true));
544 
545  // Min
546  String minMaxInit = t.isStringType() ? initNullString : initNull;
547  String minMaxSerializeOrFinalize = t.isStringType() ?
548  stringValSerializeOrFinalize : null;
549  String minMaxGetValue = t.isStringType() ? stringValGetValue : null;
550  db.addBuiltin(AggregateFunction.createBuiltin(db, "min",
551  Lists.newArrayList(t), t, t, minMaxInit,
552  prefix + MIN_UPDATE_SYMBOL.get(t),
553  prefix + MIN_UPDATE_SYMBOL.get(t),
554  minMaxSerializeOrFinalize, minMaxGetValue,
555  null, minMaxSerializeOrFinalize, true, true, false));
556  // Max
557  db.addBuiltin(AggregateFunction.createBuiltin(db, "max",
558  Lists.newArrayList(t), t, t, minMaxInit,
559  prefix + MAX_UPDATE_SYMBOL.get(t),
560  prefix + MAX_UPDATE_SYMBOL.get(t),
561  minMaxSerializeOrFinalize, minMaxGetValue,
562  null, minMaxSerializeOrFinalize, true, true, false));
563  // Sample
564  db.addBuiltin(AggregateFunction.createBuiltin(db, "sample",
565  Lists.newArrayList(t), Type.STRING, Type.STRING,
566  prefix + SAMPLE_INIT_SYMBOL.get(t),
567  prefix + SAMPLE_UPDATE_SYMBOL.get(t),
568  prefix + SAMPLE_MERGE_SYMBOL.get(t),
569  prefix + SAMPLE_SERIALIZE_SYMBOL.get(t),
570  prefix + SAMPLE_FINALIZE_SYMBOL.get(t),
571  false, false, true));
572 
573  // Approximate median
574  db.addBuiltin(AggregateFunction.createBuiltin(db, "appx_median",
575  Lists.newArrayList(t), t, Type.STRING,
576  prefix + SAMPLE_INIT_SYMBOL.get(t),
577  prefix + SAMPLE_UPDATE_SYMBOL.get(t),
578  prefix + SAMPLE_MERGE_SYMBOL.get(t),
579  prefix + SAMPLE_SERIALIZE_SYMBOL.get(t),
580  prefix + APPX_MEDIAN_FINALIZE_SYMBOL.get(t),
581  false, false, true));
582 
583  // Histogram
584  db.addBuiltin(AggregateFunction.createBuiltin(db, "histogram",
585  Lists.newArrayList(t), Type.STRING, Type.STRING,
586  prefix + SAMPLE_INIT_SYMBOL.get(t),
587  prefix + SAMPLE_UPDATE_SYMBOL.get(t),
588  prefix + SAMPLE_MERGE_SYMBOL.get(t),
589  prefix + SAMPLE_SERIALIZE_SYMBOL.get(t),
590  prefix + HISTOGRAM_FINALIZE_SYMBOL.get(t),
591  false, false, true));
592 
593  // NDV
594  // TODO: this needs to switch to CHAR(64) as the intermediate type
595  db.addBuiltin(AggregateFunction.createBuiltin(db, "ndv",
596  Lists.newArrayList(t), Type.BIGINT, Type.STRING,
597  prefix + "7HllInitEPN10impala_udf15FunctionContextEPNS1_9StringValE",
598  prefix + HLL_UPDATE_SYMBOL.get(t),
599  prefix + "8HllMergeEPN10impala_udf15FunctionContextERKNS1_9StringValEPS4_",
600  stringValSerializeOrFinalize,
601  prefix + "11HllFinalizeEPN10impala_udf15FunctionContextERKNS1_9StringValE",
602  true, false, true));
603 
604  db.addBuiltin(AggregateFunction.createBuiltin(db, "ndv_no_finalize",
605  Lists.newArrayList(t), Type.STRING, Type.STRING,
606  prefix + "7HllInitEPN10impala_udf15FunctionContextEPNS1_9StringValE",
607  prefix + HLL_UPDATE_SYMBOL.get(t),
608  prefix + "8HllMergeEPN10impala_udf15FunctionContextERKNS1_9StringValEPS4_",
609  stringValSerializeOrFinalize,
610  "_Z20IncrementNdvFinalizePN10impala_udf15FunctionContextERKNS_9StringValE",
611  true, false, true));
612 
613  // distinctpc
614  // TODO: this needs to switch to CHAR(64) as the intermediate type
615  db.addBuiltin(AggregateFunction.createBuiltin(db, "distinctpc",
616  Lists.newArrayList(t), Type.BIGINT, Type.STRING,
617  prefix + "6PcInitEPN10impala_udf15FunctionContextEPNS1_9StringValE",
618  prefix + PC_UPDATE_SYMBOL.get(t),
619  prefix + "7PcMergeEPN10impala_udf15FunctionContextERKNS1_9StringValEPS4_",
620  stringValSerializeOrFinalize,
621  prefix + "10PcFinalizeEPN10impala_udf15FunctionContextERKNS1_9StringValE",
622  false, false, true));
623 
624  // distinctpcsa
625  // TODO: this needs to switch to CHAR(64) as the intermediate type
626  db.addBuiltin(AggregateFunction.createBuiltin(db, "distinctpcsa",
627  Lists.newArrayList(t), Type.BIGINT, Type.STRING,
628  prefix + "6PcInitEPN10impala_udf15FunctionContextEPNS1_9StringValE",
629  prefix + PCSA_UPDATE_SYMBOL.get(t),
630  prefix + "7PcMergeEPN10impala_udf15FunctionContextERKNS1_9StringValEPS4_",
631  stringValSerializeOrFinalize,
632  prefix + "12PcsaFinalizeEPN10impala_udf15FunctionContextERKNS1_9StringValE",
633  false, false, true));
634 
635  if (STDDEV_UPDATE_SYMBOL.containsKey(t)) {
636  db.addBuiltin(AggregateFunction.createBuiltin(db, "stddev",
637  Lists.newArrayList(t), Type.DOUBLE, ScalarType.createCharType(24),
638  prefix + "12KnuthVarInitEPN10impala_udf15FunctionContextEPNS1_9StringValE",
639  prefix + STDDEV_UPDATE_SYMBOL.get(t),
640  prefix + "13KnuthVarMergeEPN10impala_udf15FunctionContextERKNS1_9StringValEPS4_",
641  null,
642  prefix + "19KnuthStddevFinalizeEPN10impala_udf15FunctionContextERKNS1_9StringValE",
643  false, false, false));
644  db.addBuiltin(AggregateFunction.createBuiltin(db, "stddev_samp",
645  Lists.newArrayList(t), Type.DOUBLE, ScalarType.createCharType(24),
646  prefix + "12KnuthVarInitEPN10impala_udf15FunctionContextEPNS1_9StringValE",
647  prefix + STDDEV_UPDATE_SYMBOL.get(t),
648  prefix + "13KnuthVarMergeEPN10impala_udf15FunctionContextERKNS1_9StringValEPS4_",
649  null,
650  prefix + "19KnuthStddevFinalizeEPN10impala_udf15FunctionContextERKNS1_9StringValE",
651  false, false, false));
652  db.addBuiltin(AggregateFunction.createBuiltin(db, "stddev_pop",
653  Lists.newArrayList(t), Type.DOUBLE, ScalarType.createCharType(24),
654  prefix + "12KnuthVarInitEPN10impala_udf15FunctionContextEPNS1_9StringValE",
655  prefix + STDDEV_UPDATE_SYMBOL.get(t),
656  prefix + "13KnuthVarMergeEPN10impala_udf15FunctionContextERKNS1_9StringValEPS4_",
657  null,
658  prefix + "22KnuthStddevPopFinalizeEPN10impala_udf15FunctionContextERKNS1_9StringValE",
659  false, false, false));
660  db.addBuiltin(AggregateFunction.createBuiltin(db, "variance",
661  Lists.newArrayList(t), Type.DOUBLE, ScalarType.createCharType(24),
662  prefix + "12KnuthVarInitEPN10impala_udf15FunctionContextEPNS1_9StringValE",
663  prefix + STDDEV_UPDATE_SYMBOL.get(t),
664  prefix + "13KnuthVarMergeEPN10impala_udf15FunctionContextERKNS1_9StringValEPS4_",
665  null,
666  prefix + "16KnuthVarFinalizeEPN10impala_udf15FunctionContextERKNS1_9StringValE",
667  false, false, false));
668  db.addBuiltin(AggregateFunction.createBuiltin(db, "variance_samp",
669  Lists.newArrayList(t), Type.DOUBLE, ScalarType.createCharType(24),
670  prefix + "12KnuthVarInitEPN10impala_udf15FunctionContextEPNS1_9StringValE",
671  prefix + STDDEV_UPDATE_SYMBOL.get(t),
672  prefix + "13KnuthVarMergeEPN10impala_udf15FunctionContextERKNS1_9StringValEPS4_",
673  null,
674  prefix + "16KnuthVarFinalizeEPN10impala_udf15FunctionContextERKNS1_9StringValE",
675  false, false, false));
676  db.addBuiltin(AggregateFunction.createBuiltin(db, "var_samp",
677  Lists.newArrayList(t), Type.DOUBLE, ScalarType.createCharType(24),
678  prefix + "12KnuthVarInitEPN10impala_udf15FunctionContextEPNS1_9StringValE",
679  prefix + STDDEV_UPDATE_SYMBOL.get(t),
680  prefix + "13KnuthVarMergeEPN10impala_udf15FunctionContextERKNS1_9StringValEPS4_",
681  null,
682  prefix + "16KnuthVarFinalizeEPN10impala_udf15FunctionContextERKNS1_9StringValE",
683  false, false, false));
684  db.addBuiltin(AggregateFunction.createBuiltin(db, "variance_pop",
685  Lists.newArrayList(t), Type.DOUBLE, ScalarType.createCharType(24),
686  prefix + "12KnuthVarInitEPN10impala_udf15FunctionContextEPNS1_9StringValE",
687  prefix + STDDEV_UPDATE_SYMBOL.get(t),
688  prefix + "13KnuthVarMergeEPN10impala_udf15FunctionContextERKNS1_9StringValEPS4_",
689  null,
690  prefix + "19KnuthVarPopFinalizeEPN10impala_udf15FunctionContextERKNS1_9StringValE",
691  false, false, false));
692  db.addBuiltin(AggregateFunction.createBuiltin(db, "var_pop",
693  Lists.newArrayList(t), Type.DOUBLE, ScalarType.createCharType(24),
694  prefix + "12KnuthVarInitEPN10impala_udf15FunctionContextEPNS1_9StringValE",
695  prefix + STDDEV_UPDATE_SYMBOL.get(t),
696  prefix + "13KnuthVarMergeEPN10impala_udf15FunctionContextERKNS1_9StringValEPS4_",
697  null,
698  prefix + "19KnuthVarPopFinalizeEPN10impala_udf15FunctionContextERKNS1_9StringValE",
699  false, false, false));
700  }
701  }
702 
703  // Sum
704  db.addBuiltin(AggregateFunction.createBuiltin(db, "sum",
705  Lists.<Type>newArrayList(Type.BIGINT), Type.BIGINT, Type.BIGINT, initNull,
706  prefix + "9SumUpdateIN10impala_udf9BigIntValES3_EEvPNS2_15FunctionContextERKT_PT0_",
707  prefix + "9SumUpdateIN10impala_udf9BigIntValES3_EEvPNS2_15FunctionContextERKT_PT0_",
708  null, null,
709  prefix + "9SumRemoveIN10impala_udf9BigIntValES3_EEvPNS2_15FunctionContextERKT_PT0_",
710  null, false, true, false));
711  db.addBuiltin(AggregateFunction.createBuiltin(db, "sum",
712  Lists.<Type>newArrayList(Type.DOUBLE), Type.DOUBLE, Type.DOUBLE, initNull,
713  prefix + "9SumUpdateIN10impala_udf9DoubleValES3_EEvPNS2_15FunctionContextERKT_PT0_",
714  prefix + "9SumUpdateIN10impala_udf9DoubleValES3_EEvPNS2_15FunctionContextERKT_PT0_",
715  null, null,
716  prefix + "9SumRemoveIN10impala_udf9DoubleValES3_EEvPNS2_15FunctionContextERKT_PT0_",
717  null, false, true, false));
718  db.addBuiltin(AggregateFunction.createBuiltin(db, "sum",
719  Lists.<Type>newArrayList(Type.DECIMAL), Type.DECIMAL, Type.DECIMAL, initNull,
720  prefix + "16SumDecimalUpdateEPN10impala_udf15FunctionContextERKNS1_10DecimalValEPS4_",
721  prefix + "15SumDecimalMergeEPN10impala_udf15FunctionContextERKNS1_10DecimalValEPS4_",
722  null, null,
723  prefix + "16SumDecimalRemoveEPN10impala_udf15FunctionContextERKNS1_10DecimalValEPS4_",
724  null, false, true, false));
725 
726  // Avg
727  // TODO: switch to CHAR(sizeof(AvgIntermediateType) when that becomes available
728  db.addBuiltin(AggregateFunction.createBuiltin(db, "avg",
729  Lists.<Type>newArrayList(Type.BIGINT), Type.DOUBLE, Type.STRING,
730  prefix + "7AvgInitEPN10impala_udf15FunctionContextEPNS1_9StringValE",
731  prefix + "9AvgUpdateIN10impala_udf9BigIntValEEEvPNS2_15FunctionContextERKT_PNS2_9StringValE",
732  prefix + "8AvgMergeEPN10impala_udf15FunctionContextERKNS1_9StringValEPS4_",
733  stringValSerializeOrFinalize,
734  prefix + "11AvgGetValueEPN10impala_udf15FunctionContextERKNS1_9StringValE",
735  prefix + "9AvgRemoveIN10impala_udf9BigIntValEEEvPNS2_15FunctionContextERKT_PNS2_9StringValE",
736  prefix + "11AvgFinalizeEPN10impala_udf15FunctionContextERKNS1_9StringValE",
737  false, true, false));
738  db.addBuiltin(AggregateFunction.createBuiltin(db, "avg",
739  Lists.<Type>newArrayList(Type.DOUBLE), Type.DOUBLE, Type.STRING,
740  prefix + "7AvgInitEPN10impala_udf15FunctionContextEPNS1_9StringValE",
741  prefix + "9AvgUpdateIN10impala_udf9DoubleValEEEvPNS2_15FunctionContextERKT_PNS2_9StringValE",
742  prefix + "8AvgMergeEPN10impala_udf15FunctionContextERKNS1_9StringValEPS4_",
743  stringValSerializeOrFinalize,
744  prefix + "11AvgGetValueEPN10impala_udf15FunctionContextERKNS1_9StringValE",
745  prefix + "9AvgRemoveIN10impala_udf9DoubleValEEEvPNS2_15FunctionContextERKT_PNS2_9StringValE",
746  prefix + "11AvgFinalizeEPN10impala_udf15FunctionContextERKNS1_9StringValE",
747  false, true, false));
748  db.addBuiltin(AggregateFunction.createBuiltin(db, "avg",
749  Lists.<Type>newArrayList(Type.DECIMAL), Type.DECIMAL, Type.STRING,
750  prefix + "14DecimalAvgInitEPN10impala_udf15FunctionContextEPNS1_9StringValE",
751  prefix + "16DecimalAvgUpdateEPN10impala_udf15FunctionContextERKNS1_10DecimalValEPNS1_9StringValE",
752  prefix + "15DecimalAvgMergeEPN10impala_udf15FunctionContextERKNS1_9StringValEPS4_",
753  stringValSerializeOrFinalize,
754  prefix + "18DecimalAvgGetValueEPN10impala_udf15FunctionContextERKNS1_9StringValE",
755  prefix + "16DecimalAvgRemoveEPN10impala_udf15FunctionContextERKNS1_10DecimalValEPNS1_9StringValE",
756  prefix + "18DecimalAvgFinalizeEPN10impala_udf15FunctionContextERKNS1_9StringValE",
757  false, true, false));
758  // Avg(Timestamp)
759  db.addBuiltin(AggregateFunction.createBuiltin(db, "avg",
760  Lists.<Type>newArrayList(Type.TIMESTAMP), Type.TIMESTAMP, Type.STRING,
761  prefix + "7AvgInitEPN10impala_udf15FunctionContextEPNS1_9StringValE",
762  prefix + "18TimestampAvgUpdateEPN10impala_udf15FunctionContextERKNS1_12TimestampValEPNS1_9StringValE",
763  prefix + "8AvgMergeEPN10impala_udf15FunctionContextERKNS1_9StringValEPS4_",
764  stringValSerializeOrFinalize,
765  prefix + "20TimestampAvgGetValueEPN10impala_udf15FunctionContextERKNS1_9StringValE",
766  prefix + "18TimestampAvgRemoveEPN10impala_udf15FunctionContextERKNS1_12TimestampValEPNS1_9StringValE",
767  prefix + "20TimestampAvgFinalizeEPN10impala_udf15FunctionContextERKNS1_9StringValE",
768  false, true, false));
769 
770  // Group_concat(string)
771  db.addBuiltin(AggregateFunction.createBuiltin(db, "group_concat",
772  Lists.<Type>newArrayList(Type.STRING), Type.STRING, Type.STRING, initNullString,
773  prefix +
774  "18StringConcatUpdateEPN10impala_udf15FunctionContextERKNS1_9StringValEPS4_",
775  prefix +
776  "17StringConcatMergeEPN10impala_udf15FunctionContextERKNS1_9StringValEPS4_",
777  stringValSerializeOrFinalize,
778  prefix +
779  "20StringConcatFinalizeEPN10impala_udf15FunctionContextERKNS1_9StringValE",
780  false, false, false));
781  // Group_concat(string, string)
782  db.addBuiltin(AggregateFunction.createBuiltin(db, "group_concat",
783  Lists.<Type>newArrayList(Type.STRING, Type.STRING), Type.STRING, Type.STRING,
784  initNullString,
785  prefix +
786  "18StringConcatUpdateEPN10impala_udf15FunctionContextERKNS1_9StringValES6_PS4_",
787  prefix +
788  "17StringConcatMergeEPN10impala_udf15FunctionContextERKNS1_9StringValEPS4_",
789  stringValSerializeOrFinalize,
790  prefix +
791  "20StringConcatFinalizeEPN10impala_udf15FunctionContextERKNS1_9StringValE",
792  false, false, false));
793 
794  // analytic functions
795  // Rank
796  db.addBuiltin(AggregateFunction.createAnalyticBuiltin(db, "rank",
797  Lists.<Type>newArrayList(), Type.BIGINT, Type.STRING,
798  prefix + "8RankInitEPN10impala_udf15FunctionContextEPNS1_9StringValE",
799  prefix + "10RankUpdateEPN10impala_udf15FunctionContextEPNS1_9StringValE",
800  null,
801  prefix + "12RankGetValueEPN10impala_udf15FunctionContextERNS1_9StringValE",
802  prefix + "12RankFinalizeEPN10impala_udf15FunctionContextERNS1_9StringValE"));
803  // Dense rank
804  db.addBuiltin(AggregateFunction.createAnalyticBuiltin(db, "dense_rank",
805  Lists.<Type>newArrayList(), Type.BIGINT, Type.STRING,
806  prefix + "8RankInitEPN10impala_udf15FunctionContextEPNS1_9StringValE",
807  prefix + "15DenseRankUpdateEPN10impala_udf15FunctionContextEPNS1_9StringValE",
808  null,
809  prefix + "17DenseRankGetValueEPN10impala_udf15FunctionContextERNS1_9StringValE",
810  prefix + "12RankFinalizeEPN10impala_udf15FunctionContextERNS1_9StringValE"));
811  db.addBuiltin(AggregateFunction.createAnalyticBuiltin(
812  db, "row_number", new ArrayList<Type>(), Type.BIGINT, Type.BIGINT,
813  prefix + "8InitZeroIN10impala_udf9BigIntValEEEvPNS2_15FunctionContextEPT_",
814  prefix + "15CountStarUpdateEPN10impala_udf15FunctionContextEPNS1_9BigIntValE",
815  prefix + "10CountMergeEPN10impala_udf15FunctionContextERKNS1_9BigIntValEPS4_",
816  null, null));
817 
818  for (Type t: Type.getSupportedTypes()) {
819  if (t.isNull()) continue; // NULL is handled through type promotion.
820  if (t.isScalarType(PrimitiveType.CHAR)) continue; // promoted to STRING
821  if (t.isScalarType(PrimitiveType.VARCHAR)) continue; // promoted to STRING
822  db.addBuiltin(AggregateFunction.createAnalyticBuiltin(
823  db, "first_value", Lists.newArrayList(t), t, t,
824  t.isStringType() ? initNullString : initNull,
825  prefix + FIRST_VALUE_UPDATE_SYMBOL.get(t),
826  null,
827  t == Type.STRING ? stringValGetValue : null,
828  t == Type.STRING ? stringValSerializeOrFinalize : null));
829  // Implements FIRST_VALUE for some windows that require rewrites during planning.
830  db.addBuiltin(AggregateFunction.createAnalyticBuiltin(
831  db, "first_value_rewrite", Lists.newArrayList(t, Type.BIGINT), t, t,
832  t.isStringType() ? initNullString : initNull,
833  prefix + FIRST_VALUE_REWRITE_UPDATE_SYMBOL.get(t),
834  null,
835  t == Type.STRING ? stringValGetValue : null,
836  t == Type.STRING ? stringValSerializeOrFinalize : null,
837  false));
838 
839  db.addBuiltin(AggregateFunction.createAnalyticBuiltin(
840  db, "last_value", Lists.newArrayList(t), t, t,
841  t.isStringType() ? initNullString : initNull,
842  prefix + LAST_VALUE_UPDATE_SYMBOL.get(t),
843  prefix + LAST_VALUE_REMOVE_SYMBOL.get(t),
844  t == Type.STRING ? stringValGetValue : null,
845  t == Type.STRING ? stringValSerializeOrFinalize : null));
846 
847  db.addBuiltin(AggregateFunction.createAnalyticBuiltin(
848  db, "lag", Lists.newArrayList(t, Type.BIGINT, t), t, t,
849  prefix + OFFSET_FN_INIT_SYMBOL.get(t),
850  prefix + OFFSET_FN_UPDATE_SYMBOL.get(t),
851  null, null, null));
852  db.addBuiltin(AggregateFunction.createAnalyticBuiltin(
853  db, "lead", Lists.newArrayList(t, Type.BIGINT, t), t, t,
854  prefix + OFFSET_FN_INIT_SYMBOL.get(t),
855  prefix + OFFSET_FN_UPDATE_SYMBOL.get(t),
856  null, null, null));
857 
858  // lead() and lag() the default offset and the default value should be
859  // rewritten to call the overrides that take all parameters.
860  db.addBuiltin(AggregateFunction.createAnalyticBuiltin(
861  db, "lag", Lists.newArrayList(t), t, t));
862  db.addBuiltin(AggregateFunction.createAnalyticBuiltin(
863  db, "lag", Lists.newArrayList(t, Type.BIGINT), t, t));
864  db.addBuiltin(AggregateFunction.createAnalyticBuiltin(
865  db, "lead", Lists.newArrayList(t), t, t));
866  db.addBuiltin(AggregateFunction.createAnalyticBuiltin(
867  db, "lead", Lists.newArrayList(t, Type.BIGINT), t, t));
868  }
869  }
870 }
static final Map< Type, String > HISTOGRAM_FINALIZE_SYMBOL
static final ScalarType BIGINT
Definition: Type.java:50
static final Map< Type, String > STDDEV_UPDATE_SYMBOL
static final Map< Type, String > FIRST_VALUE_UPDATE_SYMBOL
static final Map< Type, String > PC_UPDATE_SYMBOL
static final Map< Type, String > MAX_UPDATE_SYMBOL
static final ScalarType STRING
Definition: Type.java:53
static final Map< Type, String > SAMPLE_FINALIZE_SYMBOL
static final Map< Type, String > OFFSET_FN_UPDATE_SYMBOL
BuiltinsDb(String name, Catalog catalog)
Definition: BuiltinsDb.java:33
static final Map< Type, String > PCSA_UPDATE_SYMBOL
static final Map< Type, String > OFFSET_FN_INIT_SYMBOL
static final Map< Type, String > MIN_UPDATE_SYMBOL
static final ScalarType BOOLEAN
Definition: Type.java:46
static final ScalarType SMALLINT
Definition: Type.java:48
static ScalarType createCharType(int len)
Definition: ScalarType.java:93
static final ScalarType FLOAT
Definition: Type.java:51
static final Map< Type, String > HLL_UPDATE_SYMBOL
static final Map< Type, String > SAMPLE_UPDATE_SYMBOL
static final Map< Type, String > FIRST_VALUE_REWRITE_UPDATE_SYMBOL
static final ScalarType DOUBLE
Definition: Type.java:52
static final Map< Type, String > SAMPLE_MERGE_SYMBOL
static final ScalarType TINYINT
Definition: Type.java:47
static final ScalarType INT
Definition: Type.java:49
static final ScalarType DECIMAL
Definition: Type.java:61
static final Map< Type, String > LAST_VALUE_REMOVE_SYMBOL
static final Map< Type, String > SAMPLE_INIT_SYMBOL
Definition: BuiltinsDb.java:58
static final Map< Type, String > APPX_MEDIAN_FINALIZE_SYMBOL
static final Map< Type, String > LAST_VALUE_UPDATE_SYMBOL
string name
Definition: cpu-info.cc:50
static final Map< Type, String > SAMPLE_SERIALIZE_SYMBOL
Definition: BuiltinsDb.java:82
static final ScalarType TIMESTAMP
Definition: Type.java:55
static ArrayList< ScalarType > getSupportedTypes()
Definition: Type.java:109
void setIsSystemDb(boolean b)
Definition: Db.java:70