19 #include <boost/scoped_ptr.hpp>
43 #include "gen-cpp/Data_types.h"
44 #include "gen-cpp/Frontend_types.h"
48 using namespace impala;
49 using namespace apache::thrift::server;
55 JNIEXPORT
void JNICALL
57 JNIEnv* env, jclass caller_class) {
59 char*
name =
const_cast<char*
>(
"FeSupport");
71 JNIEXPORT jbyteArray JNICALL
73 JNIEnv* env, jclass caller_class, jbyteArray thrift_expr_batch,
74 jbyteArray thrift_query_ctx_bytes) {
75 jbyteArray result_bytes = NULL;
77 TExprBatch expr_batch;
79 TResultRow expr_results;
84 query_ctx.request.query_options.disable_codegen =
true;
93 vector<TExpr>& texprs = expr_batch.exprs;
95 vector<ExprContext*> expr_ctxs;
96 for (vector<TExpr>::iterator it = texprs.begin(); it != texprs.end(); it++) {
102 expr_ctxs.push_back(ctx);
109 DCHECK_NOTNULL(codegen);
114 vector<TColumnValue> results;
116 for (
int i = 0; i < expr_ctxs.size(); ++i) {
120 expr_ctxs[i]->GetValue(NULL,
false, &val);
121 expr_ctxs[i]->Close(&state);
122 results.push_back(val);
124 expr_results.__set_colVals(results);
132 const vector<ColumnType>& arg_types, TSymbolLookupResult* result) {
134 if (params.fn_binary_type == TFunctionBinaryType::NATIVE ||
135 params.fn_binary_type == TFunctionBinaryType::BUILTIN) {
140 }
else if (params.fn_binary_type == TFunctionBinaryType::IR) {
142 }
else if (params.fn_binary_type == TFunctionBinaryType::HIVE) {
145 DCHECK(
false) << params.fn_binary_type;
149 if (params.fn_binary_type != TFunctionBinaryType::BUILTIN) {
152 string dummy_local_path;
154 params.location, type, &dummy_local_path);
156 result->__set_result_code(TSymbolLookupResultCode::BINARY_NOT_FOUND);
157 result->__set_error_msg(status.
GetDetail());
168 result->__set_result_code(TSymbolLookupResultCode::SYMBOL_FOUND);
169 result->__set_symbol(params.symbol);
173 if (params.fn_binary_type == TFunctionBinaryType::HIVE ||
179 result->__set_result_code(TSymbolLookupResultCode::SYMBOL_NOT_FOUND);
181 ss <<
"Could not find symbol '" << params.symbol <<
"' in: " << params.location;
182 result->__set_error_msg(ss.str());
183 VLOG(1) << ss.str() << endl << status.
GetDetail();
187 string symbol = params.symbol;
189 if (params.__isset.ret_arg_type) ret_type =
ColumnType(params.ret_arg_type);
192 DCHECK_NE(params.fn_binary_type, TFunctionBinaryType::HIVE);
193 if (params.symbol_type == TSymbolType::UDF_EVALUATE) {
195 arg_types, params.has_var_args, params.__isset.ret_arg_type ? &ret_type : NULL);
197 DCHECK(params.symbol_type == TSymbolType::UDF_PREPARE ||
198 params.symbol_type == TSymbolType::UDF_CLOSE);
205 result->__set_result_code(TSymbolLookupResultCode::SYMBOL_NOT_FOUND);
207 ss <<
"Could not find function " << params.symbol <<
"(";
209 if (params.symbol_type == TSymbolType::UDF_EVALUATE) {
210 for (
int i = 0; i < arg_types.size(); ++i) {
211 ss << arg_types[i].DebugString();
212 if (i != arg_types.size() - 1) ss <<
", ";
215 ss <<
"impala_udf::FunctionContext*, "
216 <<
"impala_udf::FunctionContext::FunctionStateScope";
220 if (params.__isset.ret_arg_type) ss <<
" returns " << ret_type.
DebugString();
221 ss <<
" in: " << params.location;
222 if (params.__isset.ret_arg_type) {
223 ss <<
"\nCheck that function name, arguments, and return type are correct.";
225 ss <<
"\nCheck that symbol and argument types are correct.";
227 result->__set_error_msg(ss.str());
232 result->__set_result_code(TSymbolLookupResultCode::SYMBOL_FOUND);
233 result->__set_symbol(symbol);
237 JNIEXPORT jbyteArray JNICALL
239 JNIEnv* env, jclass caller_class, jbyteArray thrift_struct) {
240 TCacheJarParams params;
243 TCacheJarResult result;
248 if (status.
ok()) result.__set_local_path(local_path);
250 jbyteArray result_bytes = NULL;
257 JNIEXPORT jbyteArray JNICALL
259 JNIEnv* env, jclass caller_class, jbyteArray thrift_struct) {
260 TSymbolLookupParams lookup;
263 vector<ColumnType> arg_types;
264 for (
int i = 0; i < lookup.arg_types.size(); ++i) {
265 arg_types.push_back(
ColumnType(lookup.arg_types[i]));
268 TSymbolLookupResult result;
271 jbyteArray result_bytes = NULL;
280 JNIEXPORT jbyteArray JNICALL
282 JNIEnv* env, jclass caller_class, jbyteArray thrift_struct) {
283 TPrioritizeLoadRequest request;
287 TPrioritizeLoadResponse result;
292 Status catalog_service_status(result.status);
297 jbyteArray result_bytes = NULL;
304 JNIEXPORT jbyteArray JNICALL
306 jclass caller_class) {
307 TStartupOptions options;
311 jbyteArray result_bytes = NULL;
321 (
char*)
"NativeFeTestInit", (
char*)
"()V",
325 (
char*)
"NativeEvalConstExprs", (
char*)
"([B[B)[B",
329 (
char*)
"NativeCacheJar", (
char*)
"([B)[B",
333 (
char*)
"NativeLookupSymbol", (
char*)
"([B)[B",
337 (
char*)
"NativePrioritizeLoad", (
char*)
"([B)[B",
341 (
char*)
"NativeGetStartupOptions", (
char*)
"()[B",
348 jclass native_backend_cl = env->FindClass(
"com/cloudera/impala/service/FeSupport");
Status CheckSymbolExists(const std::string &hdfs_lib_file, LibType type, const std::string &symbol, bool quiet=false)
const std::string GetDetail() const
JNIEXPORT jbyteArray JNICALL Java_com_cloudera_impala_service_FeSupport_NativeEvalConstExprs(JNIEnv *env, jclass caller_class, jbyteArray thrift_expr_batch, jbyteArray thrift_query_ctx_bytes)
bool codegen_created() const
static JNINativeMethod native_methods[]
Status InitForFeTests()
Initializes the exec env for running FE tests.
void InitMemTrackers(const TUniqueId &query_id, const std::string *request_pool, int64_t query_bytes_limit, int64_t query_rm_reservation_limit_bytes=-1)
void InitCommonRuntime(int argc, char **argv, bool init_jvm, TestInfo::Mode m=TestInfo::NON_TEST)
MemTracker * query_mem_tracker()
static jclass internal_exc_class()
Global reference to InternalException class.
void MergeStatus(const Status &status)
JNIEXPORT jbyteArray JNICALL Java_com_cloudera_impala_service_FeSupport_NativeLookupSymbol(JNIEnv *env, jclass caller_class, jbyteArray thrift_struct)
bool IsLineageLoggingEnabled()
Returns true if lineage logging is enabled, false otherwise.
ImpalaServer * impala_server()
ObjectPool * obj_pool()
Returns a local object pool.
Status Prepare(RuntimeState *state, const RowDescriptor &row_desc, MemTracker *tracker)
LLVM code generator. This is the top level object to generate jitted code.
static std::string ManglePrepareOrCloseFunction(const std::string &fn_name)
std::string DebugString() const
static bool IsMangled(const std::string &symbol)
Returns true if this symbol is mangled.
#define THROW_IF_ERROR_RET(stmt, env, impala_exc_cl, ret)
void ToThrift(TStatus *status) const
Convert into TStatus.
Status GetLocalLibPath(const std::string &hdfs_lib_file, LibType type, std::string *local_path)
static LibCache * instance()
Status push(JNIEnv *env, int max_local_ref=10)
JNIEXPORT jbyteArray JNICALL Java_com_cloudera_impala_service_FeSupport_NativePrioritizeLoad(JNIEnv *env, jclass caller_class, jbyteArray thrift_struct)
static Status CreateExprTree(ObjectPool *pool, const TExpr &texpr, ExprContext **ctx)
static void ResolveSymbolLookup(const TSymbolLookupParams params, const vector< ColumnType > &arg_types, TSymbolLookupResult *result)
static ExecEnv * GetInstance()
static void InitializeLlvm(bool load_backend=false)
void SetNeedsRefresh(const std::string &hdfs_lib_file)
Status GetCodegen(LlvmCodeGen **codegen, bool initialize=true)
Status PrioritizeLoad(const TPrioritizeLoadRequest &req, TPrioritizeLoadResponse *result)
Status DeserializeThriftMsg(JNIEnv *env, jbyteArray serialized_msg, T *deserialized_msg)
static std::string MangleUserFunction(const std::string &fn_name, const std::vector< ColumnType > &arg_types, bool has_var_args=false, ColumnType *ret_argument=NULL)
Status SerializeThriftMsg(JNIEnv *env, T *msg, jbyteArray *serialized_msg)
void EnableOptimizations(bool enable)
Turns on/off optimization passes.
JNIEXPORT void JNICALL Java_com_cloudera_impala_service_FeSupport_NativeFeTestInit(JNIEnv *env, jclass caller_class)
JNIEXPORT jbyteArray JNICALL Java_com_cloudera_impala_service_FeSupport_NativeCacheJar(JNIEnv *env, jclass caller_class, jbyteArray thrift_struct)
JNIEnv * getJNIEnv(void)
C linkage for helper functions in hdfsJniHelper.h.
JNIEXPORT jbyteArray JNICALL Java_com_cloudera_impala_service_FeSupport_NativeGetStartupOptions(JNIEnv *env, jclass caller_class)