Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
expr-benchmark.cc
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <iostream>
3 
4 #include <jni.h>
5 #include <thrift/Thrift.h>
6 #include <thrift/protocol/TDebugProtocol.h>
7 
8 #include "exprs/expr.h"
9 #include "exprs/expr-context.h"
10 #include "util/benchmark.h"
11 #include "util/cpu-info.h"
12 #include "util/debug-util.h"
13 #include "rpc/jni-thrift-util.h"
14 
15 #include "gen-cpp/Types_types.h"
16 #include "gen-cpp/ImpalaService.h"
17 #include "gen-cpp/DataSinks_types.h"
18 #include "gen-cpp/Types_types.h"
19 #include "gen-cpp/ImpalaService.h"
20 #include "gen-cpp/ImpalaService_types.h"
21 #include "gen-cpp/ImpalaInternalService.h"
22 #include "gen-cpp/Frontend_types.h"
23 #include "gen-cpp/ImpalaService.h"
24 #include "gen-cpp/ImpalaInternalService.h"
25 #include "gen-cpp/Frontend_types.h"
26 #include "rpc/thrift-server.h"
27 #include "common/object-pool.h"
28 #include "common/status.h"
29 #include "service/impala-server.h"
30 
31 #include "common/names.h"
32 
33 using namespace apache::thrift;
34 using namespace impala;
35 
36 // Utility class to take (ascii) sql and return the plan. This does minimal
37 // error handling.
38 class Planner {
39  public:
40  Planner() {
41  JNIEnv* jni_env = getJNIEnv();
42  // create instance of java class JniFrontend
43  jclass fe_class = jni_env->FindClass("com/cloudera/impala/service/JniFrontend");
44  jmethodID fe_ctor = jni_env->GetMethodID(fe_class, "<init>", "(Z)V");
45  EXIT_IF_EXC(jni_env);
46  create_exec_request_id_ =
47  jni_env->GetMethodID(fe_class, "createExecRequest", "([B)[B");
48  EXIT_IF_EXC(jni_env);
49 
50  jboolean lazy = true;
51  jobject fe = jni_env->NewObject(fe_class, fe_ctor, lazy);
52  EXIT_IF_EXC(jni_env);
53  EXIT_IF_ERROR(JniUtil::LocalToGlobalRef(jni_env, fe, &fe_));
54  }
55 
56  Status GeneratePlan(const string& stmt, TExecRequest* result) {
57  TQueryCtx query_ctx;
58  query_ctx.request.stmt = stmt;
59  query_ctx.request.query_options = query_options_;
60  query_ctx.__set_session(session_state_);
61  ImpalaServer::PrepareQueryContext(&query_ctx);
62 
63  JNIEnv* jni_env = getJNIEnv();
64  JniLocalFrame jni_frame;
65  RETURN_IF_ERROR(jni_frame.push(jni_env));
66  jbyteArray request_bytes;
67  RETURN_IF_ERROR(SerializeThriftMsg(jni_env, &query_ctx, &request_bytes));
68  jbyteArray result_bytes = static_cast<jbyteArray>(
69  jni_env->CallObjectMethod(fe_, create_exec_request_id_, request_bytes));
70  RETURN_ERROR_IF_EXC(jni_env);
71  RETURN_IF_ERROR(DeserializeThriftMsg(jni_env, result_bytes, result));
72  return Status::OK;
73  }
74 
75  private:
76  jobject fe_; // instance of com.cloudera.impala.service.JniFrontend
77  jmethodID create_exec_request_id_; // JniFrontend.createExecRequest()
78 
79  TQueryOptions query_options_;
80  TSessionState session_state_;
81 };
82 
83 struct TestData {
85  int64_t dummy_result;
86 };
87 
91 
92 // Utility function to get prepare select list for exprs. Assumes this is a
93 // constant query
94 static Status PrepareSelectList(const TExecRequest& request, ExprContext** ctx) {
95  const TQueryExecRequest& query_request = request.query_exec_request;
96  vector<TExpr> texprs = query_request.fragments[0].output_exprs;
97  DCHECK_EQ(texprs.size(), 1);
98  RETURN_IF_ERROR(Expr::CreateExprTree(&pool, texprs[0], ctx));
99  RETURN_IF_ERROR((*ctx)->Prepare(NULL, RowDescriptor(), &tracker));
100  return Status::OK;
101 }
102 
103 // TODO: handle codegen. Codegen needs a new driver that is also codegen'd.
104 static TestData* GenerateBenchmarkExprs(const string& query, bool codegen) {
105  stringstream ss;
106  ss << "select " << query;
107  TestData* test_data = new TestData;
108  TExecRequest request;
109  EXIT_IF_ERROR(planner.GeneratePlan(ss.str(), &request));
110  EXIT_IF_ERROR(PrepareSelectList(request, &test_data->ctx));
111  return test_data;
112 }
113 
114 const int ITERATIONS = 256;
115 
116 // Benchmark driver to run expr multiple times.
117 void BenchmarkQueryFn(int batch_size, void* d) {
118  TestData* data = reinterpret_cast<TestData*>(d);
119  for (int i = 0; i < batch_size; ++i) {
120  for (int n = 0; n < ITERATIONS; ++n) {
121  void* value = data->ctx->GetValue(NULL);
122  // Dummy result to prevent this from being optimized away
123  data->dummy_result += reinterpret_cast<int64_t>(value);
124  }
125  }
126 }
127 
128 #define BENCHMARK(name, stmt)\
129  suite->AddBenchmark(name, BenchmarkQueryFn, GenerateBenchmarkExprs(stmt, false))
130 // Machine Info: Intel(R) Core(TM) i7-2600 CPU @ 3.40GHz
131 // Literals: Function Rate Comparison
132 // ----------------------------------------------------------------------
133 // int 2154 1X
134 // float 2155 1.001X
135 // double 2179 1.011X
136 // string 2179 1.011X
138  Benchmark* suite = new Benchmark("Literals");
139  BENCHMARK("int", "1");
140  BENCHMARK("float", "1.1f");
141  BENCHMARK("double", "1.1");
142  BENCHMARK("string", "'1.1'");
143  return suite;
144 }
145 
146 // Arithmetic: Function Rate Comparison
147 // ----------------------------------------------------------------------
148 // int-add 527.5 1X
149 // double-add 528 1.001X
151  Benchmark* suite = new Benchmark("Arithmetic");
152  BENCHMARK("int-add", "1 + 2");
153  BENCHMARK("double-add", "1.1 + 2.2");
154  return suite;
155 }
156 
157 // Machine Info: Intel(R) Core(TM) i7-2600 CPU @ 3.40GHz
158 // Like: Function Rate Comparison
159 // ----------------------------------------------------------------------
160 // equals 203.9 1X
161 // not equals 426.4 2.091X
162 // strstr 142.8 0.7001X
163 // strncmp1 269.7 1.323X
164 // strncmp2 294.1 1.442X
165 // strncmp3 775.7 3.804X
166 // regex 19.7 0.0966X
168  Benchmark* suite = new Benchmark("Like");
169  BENCHMARK("equals", "'abcdefghijklmnopqrstuvwxyz' = 'abcdefghijklmnopqrstuvwxyz'");
170  BENCHMARK("not equals", "'abcdefghijklmnopqrstuvwxyz' = 'lmnopqrstuvwxyz'");
171  BENCHMARK("strstr", "'abcdefghijklmnopqrstuvwxyz' LIKE '%lmnopq%'");
172  BENCHMARK("strncmp1", "'abcdefghijklmnopqrstuvwxyz' LIKE '%xyz'");
173  BENCHMARK("strncmp2", "'abcdefghijklmnopqrstuvwxyz' LIKE 'abc%'");
174  BENCHMARK("strncmp3", "'abcdefghijklmnopqrstuvwxyz' LIKE 'abc'");
175  BENCHMARK("regex", "'abcdefghijklmnopqrstuvwxyz' LIKE 'abc%z'");
176  return suite;
177 }
178 
179 // Cast: Function Rate Comparison
180 // ----------------------------------------------------------------------
181 // int_to_int 824 1X
182 // int_to_bool 878 1.066X
183 // int_to_double 775.4 0.941X
184 // int_to_string 32.47 0.03941X
185 // double_to_boolean 823.5 0.9994X
186 // double_to_bigint 775.4 0.941X
187 // double_to_string 4.682 0.005682X
188 // string_to_int 402.6 0.4886X
189 // string_to_float 145.8 0.1769X
190 // string_to_timestamp 83.76 0.1017X
192  Benchmark* suite = new Benchmark("Cast");
193  BENCHMARK("int_to_int", "cast(1 as INT)");
194  BENCHMARK("int_to_bool", "cast(1 as BOOLEAN)");
195  BENCHMARK("int_to_double", "cast(1 as DOUBLE)");
196  BENCHMARK("int_to_string", "cast(1 as STRING)");
197  BENCHMARK("double_to_boolean", "cast(3.14 as BOOLEAN)");
198  BENCHMARK("double_to_bigint", "cast(3.14 as BIGINT)");
199  BENCHMARK("double_to_string", "cast(3.14 as STRING)");
200  BENCHMARK("string_to_int", "cast('1234' as INT)");
201  BENCHMARK("string_to_float", "cast('1234.5678' as FLOAT)");
202  BENCHMARK("string_to_timestamp", "cast('2011-10-22 09:10:11' as TIMESTAMP)");
203  return suite;
204 }
205 
206 // ConditionalFunctions: Function Rate Comparison
207 // ----------------------------------------------------------------------
208 // not_null 877.8 1X
209 // is null 938.3 1.069X
210 // compound 240.2 0.2736X
211 // int_between 191 0.2176X
212 // timestamp_between 18.5 0.02108X
213 // string_between 93.94 0.107X
214 // bool_in 356.6 0.4063X
215 // int_in 209.7 0.2389X
216 // float_in 216.4 0.2465X
217 // string_in 120.1 0.1368X
218 // timestamp_in 19.79 0.02255X
219 // if_int 506.8 0.5773X
220 // if_string 470.6 0.5361X
221 // if_timestamp 70.19 0.07996X
222 // coalesce_bool 194.2 0.2213X
223 // case_int 259 0.2951X
225 // TODO: expand these cases when the parser issues are fixed (see corresponding tests
226 // in expr-test).
227  Benchmark* suite = new Benchmark("ConditionalFunctions");
228  BENCHMARK("not_null", "!NULL");
229  BENCHMARK("is null", "5 IS NOT NULL");
230  BENCHMARK("compound", "(TRUE && TRUE) || FALSE");
231  BENCHMARK("int_between", "5 between 5 and 6");
232  BENCHMARK("timestamp_between", "cast('2011-10-22 09:10:11' as timestamp) between "
233  "cast('2011-09-22 09:10:11' as timestamp) and "
234  "cast('2011-12-22 09:10:11' as timestamp)");
235  BENCHMARK("string_between", "'abc' between 'aaa' and 'aab'");
236  BENCHMARK("bool_in", "true in (true, false, false)");
237  BENCHMARK("int_in", "1 in (2, 3, 1)");
238  BENCHMARK("float_in","1.1 not in (2, 3, 4.5)");
239  BENCHMARK("string_in", "'ab' in ('cd', 'efg', 'ab', 'h')");
240  BENCHMARK("timestamp_in", "cast('2011-11-23' as timestamp) "
241  "in (cast('2011-11-22 09:10:11' as timestamp), "
242  "cast('2011-11-23 09:11:12' as timestamp), "
243  "cast('2011-11-24 09:12:13' as timestamp))");
244  BENCHMARK("if_int", "if(TRUE, 10, 20)");
245  BENCHMARK("if_string", "if(TRUE, 'abc', 'defgh')");
246  BENCHMARK("if_timestamp", "if(TRUE, cast('2011-01-01 09:01:01' as timestamp), "
247  "cast('1999-06-14 19:07:25' as timestamp))");
248  BENCHMARK("coalesce_bool", "coalesce(if(true, NULL, NULL), if(true, NULL, NULL))");
249  BENCHMARK("case_int", "case 21 when 20 then 1 when 19 then 2 when 21 then 3 end");
250  return suite;
251 }
252 
253 // StringFunctions: Function Rate Comparison
254 // ----------------------------------------------------------------------
255 // length 920.2 1X
256 // substring1 351.4 0.3819X
257 // substring2 327.9 0.3563X
258 // left 508.6 0.5527X
259 // right 508.2 0.5522X
260 // lower 103.9 0.1129X
261 // upper 103.2 0.1121X
262 // reverse 324.9 0.3531X
263 // trim 421.2 0.4578X
264 // ltrim 526.6 0.5723X
265 // rtrim 566.5 0.6156X
266 // space 94.63 0.1028X
267 // ascii 1048 1.139X
268 // instr 175.6 0.1909X
269 // locate 184.7 0.2007X
270 // locate2 175.8 0.1911X
271 // concat 109.5 0.119X
272 // concat2 75.83 0.08241X
273 // concatws 143.4 0.1559X
274 // concatws2 70.38 0.07649X
275 // repeat 98.54 0.1071X
276 // lpad 154.7 0.1681X
277 // rpad 145.6 0.1582X
278 // find_in_set 83.38 0.09061X
279 // regexp_extract 6.42 0.006977X
280 // regexp_replace 0.7435 0.000808X
282  Benchmark* suite = new Benchmark("StringFunctions");
283  BENCHMARK("length", "length('Hello World!')");
284  BENCHMARK("substring1", "substring('Hello World!', 5)");
285  BENCHMARK("substring2", "substring('Hello World!', 5, 5)");
286  BENCHMARK("left", "strleft('Hello World!', 7)");
287  BENCHMARK("right", "strleft('Hello World!', 7)");
288  BENCHMARK("lower", "lower('Hello World!')");
289  BENCHMARK("upper", "upper('Hello World!')");
290  BENCHMARK("reverse", "reverse('Hello World!')");
291  BENCHMARK("trim", "trim(' Hello World! ')");
292  BENCHMARK("ltrim", "ltrim(' Hello World! ')");
293  BENCHMARK("rtrim", "rtrim(' Hello World! ')");
294  BENCHMARK("space", "space(7)");
295  BENCHMARK("ascii", "ascii('abcd')");
296  BENCHMARK("instr", "instr('xyzabc', 'abc')");
297  BENCHMARK("locate", "locate('abc', 'xyzabc')");
298  BENCHMARK("locate2", "locate('abc', 'abcxyzabc', 3)");
299  BENCHMARK("concat", "concat('a', 'bcd')");
300  BENCHMARK("concat2", "concat('a', 'bb', 'ccc', 'dddd')");
301  BENCHMARK("concatws", "concat_ws('a', 'b')");
302  BENCHMARK("concatws2", "concat_ws('a', 'b', 'c', 'd')");
303  BENCHMARK("repeat", "repeat('abc', 7)");
304  BENCHMARK("lpad", "lpad('abc', 7, 'xyz')");
305  BENCHMARK("rpad", "rpad('abc', 7, 'xyz')");
306  BENCHMARK("find_in_set", "find_in_set('ab', 'abc,ad,ab,ade,cde')");
307  BENCHMARK("regexp_extract", "regexp_extract('abxcy1234a', 'a.x.y.*a', 0)");
308  BENCHMARK("regexp_replace", "regexp_replace('axcaycazc', '', 'r')");
309  return suite;
310 }
311 
312 // UrlFunctions: Function Rate Comparison
313 // ----------------------------------------------------------------------
314 // authority 118.1 1X
315 // file 95.52 0.809X
316 // host 94.52 0.8005X
317 // path 98.63 0.8353X
318 // protocol 36.29 0.3073X
319 // user 121.1 1.026X
320 // user_info 121.4 1.029X
321 // query_name 41.34 0.3501X
323  Benchmark* suite = new Benchmark("UrlFunctions");
324  BENCHMARK("authority", "parse_url('http://user:pass@example.com:80/docs/books/tutorial/"
325  "index.html?name=networking#DOWNLOADING', 'AUTHORITY')");
326  BENCHMARK("file", "parse_url('http://example.com/docs/books/tutorial/"
327  "index.html?name=networking ', 'FILE')");
328  BENCHMARK("host", "parse_url('http://example.com:80/docs/books/tutorial/"
329  "index.html?name=networking#DOWNLOADING', 'HOST')");
330  BENCHMARK("path", "parse_url('http://user:pass@example.com/docs/books/tutorial/"
331  "index.html?name=networking#DOWNLOADING', 'PATH')");
332  BENCHMARK("protocol", "parse_url('user:pass@example.com/docs/books/tutorial/"
333  "index.html?name=networking#DOWNLOADING', 'PROTOCOL')");
334  BENCHMARK("user", "parse_url('http://user@example.com/docs/books/tutorial/"
335  "index.html?name=networking#DOWNLOADING', 'USERINFO')");
336  BENCHMARK("user_info", "parse_url('http://user:pass@example.com:80/docs/books/tutorial/"
337  "index.html?name=networking#DOWNLOADING', 'USERINFO')");
338  BENCHMARK("query_name", "parse_url('http://example.com:80/docs/books/tutorial/"
339  "index.htmltest=true&name=networking&op=true', 'QUERY', 'name')");
340  return suite;
341 }
342 
343 // MathFunctions: Function Rate Comparison
344 // ----------------------------------------------------------------------
345 // pi 1642 1X
346 // e 1546 0.9416X
347 // abs 877 0.5342X
348 // ln 110.7 0.06744X
349 // log10 88.48 0.0539X
350 // log2 108.3 0.06597X
351 // log 55.61 0.03387X
352 // pow 53.93 0.03285X
353 // sqrt 629.6 0.3835X
354 // sign 732 0.4459X
355 // sin 176.3 0.1074X
356 // asin 169.6 0.1033X
357 // cos 156.3 0.0952X
358 // acos 167.5 0.102X
359 // tan 176.3 0.1074X
360 // atan 153.8 0.09371X
361 // radians 601.5 0.3664X
362 // degrees 601.5 0.3664X
363 // bin 45 0.02741X
364 // pmod_int 147.3 0.08976X
365 // pmod_float 172.9 0.1053X
366 // positive 877 0.5342X
367 // negative 936.9 0.5707X
368 // ceil 466.7 0.2843X
369 // floor 390.9 0.2381X
370 // round 820.5 0.4998X
371 // round2 220.2 0.1341X
372 // hex_int 5.745 0.0035X
373 // hex_string 4.441 0.002705X
374 // unhex 3.394 0.002067X
375 // conv_int 33.15 0.02019X
376 // conv_string 36.6 0.02229X
378  Benchmark* suite = new Benchmark("MathFunctions");
379  BENCHMARK("pi", "pi()");
380  BENCHMARK("e", "e()");
381  BENCHMARK("abs", "abs(-1.0)");
382  BENCHMARK("ln", "ln(3.14)");
383  BENCHMARK("log10", "log10(3.14)");
384  BENCHMARK("log2", "log2(3.14)");
385  BENCHMARK("log", "log(3.14, 5)");
386  BENCHMARK("pow", "pow(3.14, 5)");
387  BENCHMARK("sqrt", "sqrt(3.14)");
388  BENCHMARK("sign", "sign(1.0)");
389  BENCHMARK("sin", "sin(3.14)");
390  BENCHMARK("asin", "asin(3.14)");
391  BENCHMARK("cos", "cos(3.14)");
392  BENCHMARK("acos", "acos(3.14)");
393  BENCHMARK("tan", "tan(3.14)");
394  BENCHMARK("atan", "atan(3.14)");
395  BENCHMARK("radians", "radians(3.14)");
396  BENCHMARK("degrees", "degrees(3.14)");
397  BENCHMARK("bin", "bin(12345)");
398  BENCHMARK("pmod_int", "pmod(12345, 12)");
399  BENCHMARK("pmod_float", "pmod(12345.678, 12.34)");
400  BENCHMARK("positive", "positive(12345)");
401  BENCHMARK("negative", "negative(12345)");
402  BENCHMARK("ceil", "ceil(-10.05)");
403  BENCHMARK("floor", "floor(-10.05)");
404  BENCHMARK("round", "round(-10.05)");
405  BENCHMARK("round2", "round(-10.056789, 4)");
406  BENCHMARK("hex_int", "hex(16)");
407  BENCHMARK("hex_string", "hex('impala')");
408  BENCHMARK("unhex", "hex('496D70616C61')");
409  BENCHMARK("conv_int", "conv(100101, 2, 36)");
410  BENCHMARK("conv_string", "conv('100101', 2, 36)");
411  return suite;
412 }
413 
414 // TimestampFunctions: Function Rate Comparison
415 // ----------------------------------------------------------------------
416 // literal 68.18 1X
417 // to_string 1.131 0.01659X
418 // add_year 34.57 0.507X
419 // sub_month 33.04 0.4846X
420 // add_weeks 56.15 0.8236X
421 // sub_days 57.21 0.8391X
422 // add 55.85 0.8191X
423 // sub_hours 44.44 0.6519X
424 // add_minutes 43.96 0.6448X
425 // sub_seconds 42.78 0.6274X
426 // add_milli 43.43 0.6371X
427 // sub_micro 43.88 0.6436X
428 // add_nano 41.83 0.6135X
429 // unix_timestamp1 32.74 0.4803X
430 // unix_timestamp2 39.39 0.5778X
431 // from_unix1 1.192 0.01748X
432 // from_unix2 1.602 0.0235X
433 // year 73.4 1.077X
434 // month 72.53 1.064X
435 // day of month 71.98 1.056X
436 // day of year 56.67 0.8312X
437 // week of year 50.68 0.7433X
438 // hour 100.1 1.468X
439 // minute 97.18 1.425X
440 // second 96.7 1.418X
441 // to date 3.075 0.04511X
442 // date diff 39.54 0.5799X
444  Benchmark* suite = new Benchmark("TimestampFunctions");
445  BENCHMARK("literal", "cast('2012-01-01 09:10:11.123456789' as timestamp)");
446  BENCHMARK("to_string",
447  "cast(cast('2012-01-01 09:10:11.123456789' as timestamp) as string)");
448  BENCHMARK("add_year", "date_add(cast('2012-01-01 09:10:11.123456789' "
449  "as timestamp), interval 10 years)");
450  BENCHMARK("sub_month", "date_sub(cast('2012-02-29 09:10:11.123456789' "
451  "as timestamp), interval 1 month)");
452  BENCHMARK("add_weeks", "date_add(cast('2012-01-01 09:10:11.123456789' "
453  "as timestamp), interval 53 weeks)");
454  BENCHMARK("sub_days", "date_sub(cast('2011-12-22 09:10:11.12345678' "
455  "as timestamp), interval 365 days)");
456  BENCHMARK("add", "date_add(cast('2012-01-01 09:10:11.123456789' "
457  "as timestamp), 10)");
458  BENCHMARK("sub_hours", "date_sub(cast('2012-01-02 01:00:00.123456789' "
459  "as timestamp), interval 25 hours)");
460  BENCHMARK("add_minutes", "date_add(cast('2012-01-01 00:00:00.123456789' "
461  "as timestamp), interval 1533 minutes)");
462  BENCHMARK("sub_seconds", "date_sub(cast('2012-01-02 01:00:33.123456789' "
463  "as timestamp), interval 90033 seconds)");
464  BENCHMARK("add_milli", "date_add(cast('2012-01-01 00:00:00.000000001' "
465  "as timestamp), interval 90000033 milliseconds)");
466  BENCHMARK("sub_micro", "date_sub(cast('2012-01-01 00:00:00.001033001' "
467  "as timestamp), interval 1033 microseconds)");
468  BENCHMARK("add_nano", "date_add(cast('2012-01-01 00:00:00.000000001' "
469  "as timestamp), interval 1033 nanoseconds)");
470  BENCHMARK("unix_timestamp1",
471  "unix_timestamp('1970-01-01 00:00:00', 'yyyy-MM-dd HH:mm:ss')");
472  BENCHMARK("unix_timestamp2",
473  "unix_timestamp('1970-10-01', 'yyyy-MM-dd')");
474  BENCHMARK("from_unix1", "from_unixtime(0, 'yyyy-MM-dd HH:mm:ss')");
475  BENCHMARK("from_unix2", "from_unixtime(0, 'yyyy-MM-dd')");
476  BENCHMARK("year", "year(cast('2011-12-22' as timestamp))");
477  BENCHMARK("month", "month(cast('2011-12-22' as timestamp))");
478  BENCHMARK("day of month", "dayofmonth(cast('2011-12-22' as timestamp))");
479  BENCHMARK("day of year", "dayofyear(cast('2011-12-22' as timestamp))");
480  BENCHMARK("week of year", "weekofyear(cast('2011-12-22' as timestamp))");
481  BENCHMARK("hour", "hour(cast('09:10:11.000000' as timestamp))");
482  BENCHMARK("minute", "minute(cast('09:10:11.000000' as timestamp))");
483  BENCHMARK("second", "second(cast('09:10:11.000000' as timestamp))");
484  BENCHMARK("to date",
485  "to_date(cast('2011-12-22 09:10:11.12345678' as timestamp))");
486  BENCHMARK("date diff", "datediff(cast('2011-12-22 09:10:11.12345678' as timestamp), "
487  "cast('2012-12-22' as timestamp))");
488 #if 0
489  // TODO: need to create a valid runtime state for these functions
490  BENCHMARK("from utc",
491  "from_utc_timestamp(cast(1.3041352164485E9 as timestamp), 'PST')");
492  BENCHMARK("to utc",
493  "to_utc_timestamp(cast('2011-01-01 01:01:01' as timestamp), 'PST')");
494  BENCHMARK("now", "now()");
495  BENCHMARK("unix_timestamp", "unix_timestamp()");
496 #endif
497  return suite;
498 }
499 
500 int main(int argc, char** argv) {
501  CpuInfo::Init();
502 
503  // Generate all the tests first (this does the planning)
504  Benchmark* literals = BenchmarkLiterals();
505  Benchmark* arithmetics = BenchmarkArithmetic();
506  Benchmark* like = BenchmarkLike();
507  Benchmark* cast = BenchmarkCast();
508  Benchmark* conditional_fns = BenchmarkConditionalFunctions();
509  Benchmark* string_fns = BenchmarkStringFunctions();
510  Benchmark* url_fns = BenchmarkUrlFunctions();
511  Benchmark* math_fns = BenchmarkMathFunctions();
512  Benchmark* timestamp_fns = BenchmarkTimestampFunctions();
513 
514  cout << Benchmark::GetMachineInfo() << endl;
515  cout << literals->Measure() << endl;
516  cout << arithmetics->Measure() << endl;
517  cout << like->Measure() << endl;
518  cout << cast->Measure() << endl;
519  cout << conditional_fns->Measure() << endl;
520  cout << string_fns->Measure() << endl;
521  cout << url_fns->Measure() << endl;
522  cout << math_fns->Measure() << endl;
523  cout << timestamp_fns->Measure() << endl;
524 
525  return 0;
526 }
#define BENCHMARK(name, stmt)
MemTracker tracker
void BenchmarkQueryFn(int batch_size, void *d)
Benchmark * BenchmarkLike()
#define RETURN_IF_ERROR(stmt)
some generally useful macros
Definition: status.h:242
Benchmark * BenchmarkTimestampFunctions()
Benchmark * BenchmarkConditionalFunctions()
#define EXIT_IF_EXC(env)
Definition: jni-util.h:85
Status GeneratePlan(const string &stmt, TExecRequest *result)
void * GetValue(TupleRow *row)
TQueryOptions query_options_
std::string Measure()
Runs all the benchmarks and returns the result in a formatted string.
Definition: benchmark.cc:83
Benchmark * BenchmarkCast()
const int ITERATIONS
ExprContext * ctx
static Status PrepareSelectList(const TExecRequest &request, ExprContext **ctx)
jobject fe_
Benchmark * BenchmarkStringFunctions()
TSessionState session_state_
Planner planner
Benchmark * BenchmarkMathFunctions()
jmethodID create_exec_request_id_
ObjectPool pool
Benchmark * BenchmarkArithmetic()
#define EXIT_IF_ERROR(stmt)
Definition: status.h:248
Status push(JNIEnv *env, int max_local_ref=10)
Definition: jni-util.cc:34
This class is thread-safe.
Definition: mem-tracker.h:61
Benchmark * BenchmarkUrlFunctions()
#define RETURN_ERROR_IF_EXC(env)
Definition: jni-util.h:99
static TestData * GenerateBenchmarkExprs(const string &query, bool codegen)
bool DeserializeThriftMsg(uint8_t *buf, uint32_t *len, bool compact, T *deserialized_msg)
Status SerializeThriftMsg(JNIEnv *env, T *msg, jbyteArray *serialized_msg)
Benchmark * BenchmarkLiterals()
int main(int argc, char **argv)
int64_t dummy_result
JNIEnv * getJNIEnv(void)
C linkage for helper functions in hdfsJniHelper.h.