Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions be/src/exec/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ set(EXEC_FILES
schema_scanner/schema_collations_scanner.cpp
schema_scanner/schema_helper.cpp
schema_scanner/schema_views_scanner.cpp
schema_scanner/schema_table_privileges_scanner.cpp
schema_scanner/schema_schema_privileges_scanner.cpp
schema_scanner/schema_user_privileges_scanner.cpp

partitioned_hash_table.cc
partitioned_hash_table_ir.cc
partitioned_aggregation_node.cc
Expand Down
11 changes: 11 additions & 0 deletions be/src/exec/schema_scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
#include "exec/schema_scanner/schema_charsets_scanner.h"
#include "exec/schema_scanner/schema_collations_scanner.h"
#include "exec/schema_scanner/schema_views_scanner.h"
#include "exec/schema_scanner/schema_table_privileges_scanner.h"
#include "exec/schema_scanner/schema_schema_privileges_scanner.h"
#include "exec/schema_scanner/schema_user_privileges_scanner.h"



namespace doris {

Expand Down Expand Up @@ -96,6 +101,12 @@ SchemaScanner* SchemaScanner::create(TSchemaTableType::type type) {
return new(std::nothrow) SchemaVariablesScanner(TVarType::SESSION);
case TSchemaTableType::SCH_VIEWS:
return new(std::nothrow) SchemaViewsScanner();
case TSchemaTableType::SCH_TABLE_PRIVILEGES:
return new(std::nothrow) SchemaTablePrivilegesScanner();
case TSchemaTableType::SCH_SCHEMA_PRIVILEGES:
return new(std::nothrow) SchemaSchemaPrivilegesScanner();
case TSchemaTableType::SCH_USER_PRIVILEGES:
return new(std::nothrow) SchemaUserPrivilegesScanner();
default:
return new(std::nothrow) SchemaDummyScanner();
break;
Expand Down
33 changes: 33 additions & 0 deletions be/src/exec/schema_scanner/schema_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,39 @@ Status SchemaHelper::show_variables(
});
}

Status SchemaHelper::list_table_privilege_status(
const std::string& ip,
const int32_t port,
const TGetTablesParams &request,
TListPrivilegesResult *result) {
return ThriftRpcHelper::rpc<FrontendServiceClient>(ip, port,
[&request, &result] (FrontendServiceConnection& client) {
client->listTablePrivilegeStatus(*result, request);
});
}

Status SchemaHelper::list_schema_privilege_status(
const std::string& ip,
const int32_t port,
const TGetTablesParams &request,
TListPrivilegesResult *result) {
return ThriftRpcHelper::rpc<FrontendServiceClient>(ip, port,
[&request, &result] (FrontendServiceConnection& client) {
client->listSchemaPrivilegeStatus(*result, request);
});
}

Status SchemaHelper::list_user_privilege_status(
const std::string& ip,
const int32_t port,
const TGetTablesParams &request,
TListPrivilegesResult *result) {
return ThriftRpcHelper::rpc<FrontendServiceClient>(ip, port,
[&request, &result] (FrontendServiceConnection& client) {
client->listUserPrivilegeStatus(*result, request);
});
}

std::string SchemaHelper::extract_db_name(const std::string& full_name) {
auto found = full_name.find(':');
if (found == std::string::npos) {
Expand Down
18 changes: 18 additions & 0 deletions be/src/exec/schema_scanner/schema_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,24 @@ class SchemaHelper {
const TShowVariableRequest &var_params,
TShowVariableResult *var_result);

static Status list_table_privilege_status(
const std::string& ip,
const int32_t port,
const TGetTablesParams &table_params,
TListPrivilegesResult *privileges_result);

static Status list_schema_privilege_status(
const std::string& ip,
const int32_t port,
const TGetTablesParams &table_params,
TListPrivilegesResult *privileges_result);

static Status list_user_privilege_status(
const std::string& ip,
const int32_t port,
const TGetTablesParams &table_params,
TListPrivilegesResult *privileges_result);

static std::string extract_db_name(const std::string& full_name);
};

Expand Down
160 changes: 160 additions & 0 deletions be/src/exec/schema_scanner/schema_schema_privileges_scanner.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

#include "exec/schema_scanner/schema_helper.h"
#include "exec/schema_scanner/schema_schema_privileges_scanner.h"
#include "runtime/primitive_type.h"
#include "runtime/string_value.h"
//#include "runtime/datetime_value.h"

namespace doris
{

SchemaScanner::ColumnDesc SchemaSchemaPrivilegesScanner::_s_tbls_columns[] = {
// name, type, size, is_null
{ "GRANTEE", TYPE_VARCHAR, sizeof(StringValue), true},
{ "TABLE_CATALOG", TYPE_VARCHAR, sizeof(StringValue), true},
{ "TABLE_SCHEMA", TYPE_VARCHAR, sizeof(StringValue), false},
{ "PRIVILEGE_TYPE", TYPE_VARCHAR, sizeof(StringValue), false},
{ "IS_GRANTABLE", TYPE_VARCHAR, sizeof(StringValue), true},
};

SchemaSchemaPrivilegesScanner::SchemaSchemaPrivilegesScanner()
: SchemaScanner(_s_tbls_columns,
sizeof(_s_tbls_columns) / sizeof(SchemaScanner::ColumnDesc)),
_priv_index(0) {
}

SchemaSchemaPrivilegesScanner::~SchemaSchemaPrivilegesScanner() {
}

Status SchemaSchemaPrivilegesScanner::start(RuntimeState *state) {
if (!_is_init) {
return Status::InternalError("used before initialized.");
}
RETURN_IF_ERROR(get_new_table());
return Status::OK();
}

Status SchemaSchemaPrivilegesScanner::fill_one_row(Tuple *tuple, MemPool *pool) {
// set all bit to not null
memset((void *)tuple, 0, _tuple_desc->num_null_bytes());
const TPrivilegeStatus& priv_status = _priv_result.privileges[_priv_index];
// grantee
{
Status status = fill_one_col(&priv_status.grantee, pool,
tuple->get_slot(_tuple_desc->slots()[0]->tuple_offset()));
if (!status.ok()) {
return status;
}
}
// catalog
// This value is always def.
{
std::string definer = "def";
Status status = fill_one_col(&definer, pool,
tuple->get_slot(_tuple_desc->slots()[1]->tuple_offset()));
if (!status.ok()) {
return status;
}
}
// schema
{
Status status = fill_one_col(&priv_status.schema, pool,
tuple->get_slot(_tuple_desc->slots()[2]->tuple_offset()));
if (!status.ok()) {
return status;
}
}
// privilege type
{
Status status = fill_one_col(&priv_status.privilege_type, pool,
tuple->get_slot(_tuple_desc->slots()[3]->tuple_offset()));
if (!status.ok()) {
return status;
}
}
// is grantable
{
Status status = fill_one_col(&priv_status.is_grantable, pool,
tuple->get_slot(_tuple_desc->slots()[4]->tuple_offset()));
if (!status.ok()) {
return status;
}
}
_priv_index++;
return Status::OK();
}

Status SchemaSchemaPrivilegesScanner::fill_one_col(const std::string* src,
MemPool *pool, void *slot) {
if (NULL == slot || NULL == pool || NULL == src) {
return Status::InternalError("input pointer is NULL.");
}
StringValue* str_slot = reinterpret_cast<StringValue*>(slot);
str_slot->len = src->length();
str_slot->ptr = (char *)pool->allocate(str_slot->len);
if (NULL == str_slot->ptr) {
return Status::InternalError("Allocate memcpy failed.");
}
memcpy(str_slot->ptr, src->c_str(), str_slot->len);
return Status::OK();
}


Status SchemaSchemaPrivilegesScanner::get_new_table() {
TGetTablesParams table_params;
if (NULL != _param->wild) {
table_params.__set_pattern(*(_param->wild));
}
if (NULL != _param->current_user_ident) {
table_params.__set_current_user_ident(*(_param->current_user_ident));
} else {
if (NULL != _param->user) {
table_params.__set_user(*(_param->user));
}
if (NULL != _param->user_ip) {
table_params.__set_user_ip(*(_param->user_ip));
}
}

if (NULL != _param->ip && 0 != _param->port) {
RETURN_IF_ERROR(SchemaHelper::list_schema_privilege_status(*(_param->ip),
_param->port, table_params, &_priv_result));
} else {
return Status::InternalError("IP or port doesn't exists");
}
_priv_index = 0;
return Status::OK();
}

Status SchemaSchemaPrivilegesScanner::get_next_row(Tuple *tuple, MemPool *pool, bool *eos) {
if (!_is_init) {
return Status::InternalError("Used before initialized.");
}
if (NULL == tuple || NULL == pool || NULL == eos) {
return Status::InternalError("input pointer is NULL.");
}
if (_priv_index >= _priv_result.privileges.size()) {
*eos = true;
return Status::OK();
}
*eos = false;
return fill_one_row(tuple, pool);
}

}
46 changes: 46 additions & 0 deletions be/src/exec/schema_scanner/schema_schema_privileges_scanner.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

#ifndef DORIS_BE_SRC_QUERY_EXEC_SCHEMA_SCANNER_SCHEMA_SCHEMA_PRIVILEGES_SCANNER_H
#define DORIS_BE_SRC_QUERY_EXEC_SCHEMA_SCANNER_SCHEMA_SCHEMA_PRIVILEGES_SCANNER_H

#include "exec/schema_scanner.h"
#include "gen_cpp/FrontendService_types.h"

namespace doris {

class SchemaSchemaPrivilegesScanner : public SchemaScanner {
public:
SchemaSchemaPrivilegesScanner();
virtual ~SchemaSchemaPrivilegesScanner();

virtual Status start(RuntimeState *state);
virtual Status get_next_row(Tuple *tuple, MemPool *pool, bool *eos);

private:
Status get_new_table();
Status fill_one_row(Tuple *tuple, MemPool *pool);
Status fill_one_col(const std::string* src, MemPool *pool, void* slot);

int _priv_index;
TListPrivilegesResult _priv_result;
static SchemaScanner::ColumnDesc _s_tbls_columns[];
};

}

#endif
Loading