in be/src/service/client-request-state.cc [406:580]
Status ClientRequestState::ExecLocalCatalogOp(
const TCatalogOpRequest& catalog_op) {
switch (catalog_op.op_type) {
case TCatalogOpType::USE: {
lock_guard<mutex> l(session_->lock);
session_->database = exec_request().catalog_op_request.use_db_params.db;
return Status::OK();
}
case TCatalogOpType::SHOW_TABLES:
case TCatalogOpType::SHOW_VIEWS: {
const TShowTablesParams* params = &catalog_op.show_tables_params;
// A NULL pattern means match all tables of the specified table types. However,
// Thrift string types can't be NULL in C++, so we have to test if it's set rather
// than just blindly using the value.
const string* table_name_pattern =
params->__isset.show_pattern ? &(params->show_pattern) : nullptr;
TGetTablesResult table_names;
const set<TImpalaTableType::type>& table_types = params->table_types;
RETURN_IF_ERROR(frontend_->GetTableNames(params->db, table_name_pattern,
&query_ctx_.session, table_types, &table_names));
SetResultSet(table_names.tables);
return Status::OK();
}
case TCatalogOpType::SHOW_METADATA_TABLES: {
const TShowTablesParams* params = &catalog_op.show_tables_params;
// A NULL pattern means match all tables of the specified table types. However,
// Thrift string types can't be NULL in C++, so we have to test if it's set rather
// than just blindly using the value.
const string* metadata_table_name_pattern =
params->__isset.show_pattern ? &(params->show_pattern) : nullptr;
DCHECK(params->__isset.tbl);
const string& table_name = params->tbl;
TGetTablesResult table_names;
RETURN_IF_ERROR(frontend_->GetMetadataTableNames(params->db, table_name,
metadata_table_name_pattern, &query_ctx_.session, &table_names));
SetResultSet(table_names.tables);
return Status::OK();
}
case TCatalogOpType::SHOW_DBS: {
const TShowDbsParams* params = &catalog_op.show_dbs_params;
TGetDbsResult dbs;
const string* db_pattern =
params->__isset.show_pattern ? (¶ms->show_pattern) : NULL;
RETURN_IF_ERROR(
frontend_->GetDbs(db_pattern, &query_ctx_.session, &dbs));
vector<string> names, comments;
names.reserve(dbs.dbs.size());
comments.reserve(dbs.dbs.size());
for (const TDatabase& db: dbs.dbs) {
names.push_back(db.db_name);
comments.push_back(db.metastore_db.description);
}
SetResultSet(names, comments);
return Status::OK();
}
case TCatalogOpType::SHOW_DATA_SRCS: {
const TShowDataSrcsParams* params = &catalog_op.show_data_srcs_params;
TGetDataSrcsResult result;
const string* pattern =
params->__isset.show_pattern ? (¶ms->show_pattern) : NULL;
RETURN_IF_ERROR(
frontend_->GetDataSrcMetadata(pattern, &result));
SetResultSet(result.data_src_names, result.locations, result.class_names,
result.api_versions);
return Status::OK();
}
case TCatalogOpType::SHOW_STATS: {
const TShowStatsParams& params = catalog_op.show_stats_params;
TResultSet response;
RETURN_IF_ERROR(frontend_->GetStats(params, &response));
// Set the result set and its schema from the response.
request_result_set_.reset(new vector<TResultRow>(response.rows));
result_metadata_ = response.schema;
return Status::OK();
}
case TCatalogOpType::SHOW_FUNCTIONS: {
const TShowFunctionsParams* params = &catalog_op.show_fns_params;
TGetFunctionsResult functions;
const string* fn_pattern =
params->__isset.show_pattern ? (¶ms->show_pattern) : NULL;
RETURN_IF_ERROR(frontend_->GetFunctions(
params->category, params->db, fn_pattern, &query_ctx_.session, &functions));
SetResultSet(functions.fn_ret_types, functions.fn_signatures,
functions.fn_binary_types, functions.fn_persistence);
return Status::OK();
}
case TCatalogOpType::SHOW_ROLES: {
const TShowRolesParams& params = catalog_op.show_roles_params;
// If we have made it here, the user has privileges to execute this operation.
// Return the results.
TShowRolesResult result;
RETURN_IF_ERROR(frontend_->ShowRoles(params, &result));
SetResultSet(result.role_names);
return Status::OK();
}
case TCatalogOpType::SHOW_GRANT_PRINCIPAL: {
const TShowGrantPrincipalParams& params = catalog_op.show_grant_principal_params;
TResultSet response;
RETURN_IF_ERROR(frontend_->GetPrincipalPrivileges(params, &response));
// Set the result set and its schema from the response.
request_result_set_.reset(new vector<TResultRow>(response.rows));
result_metadata_ = response.schema;
return Status::OK();
}
case TCatalogOpType::DESCRIBE_HISTORY: {
// This operation is supported for Iceberg tables only.
const TDescribeHistoryParams& params = catalog_op.describe_history_params;
TGetTableHistoryResult result;
RETURN_IF_ERROR(frontend_->GetTableHistory(params, &result));
request_result_set_.reset(new vector<TResultRow>);
request_result_set_->resize(result.result.size());
for (int i = 0; i < result.result.size(); ++i) {
const TGetTableHistoryResultItem item = result.result[i];
TResultRow &result_row = (*request_result_set_.get())[i];
result_row.__isset.colVals = true;
result_row.colVals.resize(4);
const Timezone* local_tz = TimezoneDatabase::FindTimezone(
query_options().timezone);
TimestampValue tv = TimestampValue::FromUnixTimeMicros(
item.creation_time * 1000, local_tz);
result_row.colVals[0].__set_string_val(tv.ToString());
result_row.colVals[1].__set_string_val(std::to_string(item.snapshot_id));
result_row.colVals[2].__set_string_val(
(item.__isset.parent_id) ? std::to_string(item.parent_id) : "NULL");
result_row.colVals[3].__set_string_val(
(item.is_current_ancestor) ? "TRUE" : "FALSE");
}
return Status::OK();
}
case TCatalogOpType::DESCRIBE_DB: {
TDescribeResult response;
RETURN_IF_ERROR(frontend_->DescribeDb(catalog_op.describe_db_params,
&response));
// Set the result set
request_result_set_.reset(new vector<TResultRow>(response.results));
return Status::OK();
}
case TCatalogOpType::DESCRIBE_TABLE: {
TDescribeResult response;
const TDescribeTableParams& params = catalog_op.describe_table_params;
RETURN_IF_ERROR(frontend_->DescribeTable(params, query_ctx_.session, &response));
// Set the result set
request_result_set_.reset(new vector<TResultRow>(response.results));
return Status::OK();
}
case TCatalogOpType::SHOW_CREATE_TABLE: {
string response;
RETURN_IF_ERROR(frontend_->ShowCreateTable(catalog_op.show_create_table_params,
&response));
SetResultSet(vector<string>(1, response));
return Status::OK();
}
case TCatalogOpType::SHOW_CREATE_FUNCTION: {
string response;
RETURN_IF_ERROR(frontend_->ShowCreateFunction(catalog_op.show_create_function_params,
&response));
SetResultSet(vector<string>(1, response));
return Status::OK();
}
case TCatalogOpType::SHOW_FILES: {
TResultSet response;
RETURN_IF_ERROR(frontend_->GetTableFiles(catalog_op.show_files_params, &response));
// Set the result set and its schema from the response.
request_result_set_.reset(new vector<TResultRow>(response.rows));
result_metadata_ = response.schema;
return Status::OK();
}
default: {
stringstream ss;
ss << "Unexpected TCatalogOpType: " << catalog_op.op_type;
return Status(ss.str());
}
}
}