5 #include <thrift/Thrift.h>
6 #include <thrift/protocol/TDebugProtocol.h>
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"
33 using namespace apache::thrift;
34 using namespace impala;
43 jclass fe_class = jni_env->FindClass(
"com/cloudera/impala/service/JniFrontend");
44 jmethodID fe_ctor = jni_env->GetMethodID(fe_class,
"<init>",
"(Z)V");
46 create_exec_request_id_ =
47 jni_env->GetMethodID(fe_class,
"createExecRequest",
"([B)[B");
51 jobject fe = jni_env->NewObject(fe_class, fe_ctor, lazy);
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);
66 jbyteArray request_bytes;
68 jbyteArray result_bytes =
static_cast<jbyteArray
>(
69 jni_env->CallObjectMethod(fe_, create_exec_request_id_, request_bytes));
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);
106 ss <<
"select " << query;
108 TExecRequest request;
119 for (
int i = 0; i < batch_size; ++i) {
128 #define BENCHMARK(name, stmt)\
129 suite->AddBenchmark(name, BenchmarkQueryFn, GenerateBenchmarkExprs(stmt, false))
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'");
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)");
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)");
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))");
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");
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! ')");
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')");
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')");
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')");
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)");
405 BENCHMARK(
"round2",
"round(-10.056789, 4)");
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)");
445 BENCHMARK(
"literal",
"cast('2012-01-01 09:10:11.123456789' as timestamp)");
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)");
471 "unix_timestamp('1970-01-01 00:00:00', 'yyyy-MM-dd HH:mm:ss')");
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))");
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))");
491 "from_utc_timestamp(cast(1.3041352164485E9 as timestamp), 'PST')");
493 "to_utc_timestamp(cast('2011-01-01 01:01:01' as timestamp), 'PST')");
495 BENCHMARK(
"unix_timestamp",
"unix_timestamp()");
500 int main(
int argc,
char** argv) {
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;
#define BENCHMARK(name, stmt)
void BenchmarkQueryFn(int batch_size, void *d)
Benchmark * BenchmarkLike()
#define RETURN_IF_ERROR(stmt)
some generally useful macros
Benchmark * BenchmarkTimestampFunctions()
Benchmark * BenchmarkConditionalFunctions()
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.
Benchmark * BenchmarkCast()
static Status PrepareSelectList(const TExecRequest &request, ExprContext **ctx)
Benchmark * BenchmarkStringFunctions()
TSessionState session_state_
Benchmark * BenchmarkMathFunctions()
jmethodID create_exec_request_id_
Benchmark * BenchmarkArithmetic()
#define EXIT_IF_ERROR(stmt)
Status push(JNIEnv *env, int max_local_ref=10)
This class is thread-safe.
Benchmark * BenchmarkUrlFunctions()
#define RETURN_ERROR_IF_EXC(env)
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)
JNIEnv * getJNIEnv(void)
C linkage for helper functions in hdfsJniHelper.h.