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
3 changes: 3 additions & 0 deletions be/src/exec/schema_scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "exec/schema_scanner/schema_rowsets_scanner.h"
#include "exec/schema_scanner/schema_schema_privileges_scanner.h"
#include "exec/schema_scanner/schema_schemata_scanner.h"
#include "exec/schema_scanner/schema_table_options_scanner.h"
#include "exec/schema_scanner/schema_table_privileges_scanner.h"
#include "exec/schema_scanner/schema_tables_scanner.h"
#include "exec/schema_scanner/schema_user_privileges_scanner.h"
Expand Down Expand Up @@ -170,6 +171,8 @@ std::unique_ptr<SchemaScanner> SchemaScanner::create(TSchemaTableType::type type
return SchemaUserScanner::create_unique();
case TSchemaTableType::SCH_WORKLOAD_POLICY:
return SchemaWorkloadSchedulePolicyScanner::create_unique();
case TSchemaTableType::SCH_TABLE_OPTIONS:
return SchemaTableOptionsScanner::create_unique();
default:
return SchemaDummyScanner::create_unique();
break;
Expand Down
134 changes: 134 additions & 0 deletions be/src/exec/schema_scanner/schema_table_options_scanner.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
// 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_table_options_scanner.h"

#include "runtime/client_cache.h"
#include "runtime/exec_env.h"
#include "runtime/runtime_state.h"
#include "util/thrift_rpc_helper.h"
#include "vec/common/string_ref.h"
#include "vec/core/block.h"
#include "vec/data_types/data_type_factory.hpp"

namespace doris {
std::vector<SchemaScanner::ColumnDesc> SchemaTableOptionsScanner::_s_tbls_columns = {
{"TABLE_NAME", TYPE_VARCHAR, sizeof(StringRef), true},
{"TABLE_CATALOG", TYPE_VARCHAR, sizeof(StringRef), true},
{"TABLE_SCHEMA", TYPE_VARCHAR, sizeof(StringRef), true},
{"TABLE_MODEL", TYPE_STRING, sizeof(StringRef), true},
{"TABLE_MODEL_KEY", TYPE_STRING, sizeof(StringRef), true},
{"DISTRIBUTE_KEY", TYPE_STRING, sizeof(StringRef), true},
{"DISTRIBUTE_TYPE", TYPE_STRING, sizeof(StringRef), true},
{"BUCKETS_NUM", TYPE_INT, sizeof(int32_t), true},
{"PARTITION_NUM", TYPE_INT, sizeof(int32_t), true},
{"PROPERTIES", TYPE_STRING, sizeof(StringRef), true},
};

SchemaTableOptionsScanner::SchemaTableOptionsScanner()
Comment thread
Vallishp marked this conversation as resolved.
Comment thread
Vallishp marked this conversation as resolved.
: SchemaScanner(_s_tbls_columns, TSchemaTableType::SCH_TABLE_OPTIONS) {}

Status SchemaTableOptionsScanner::start(RuntimeState* state) {
_block_rows_limit = state->batch_size();
_rpc_timeout_ms = state->execution_timeout() * 1000;
return Status::OK();
}

Status SchemaTableOptionsScanner::get_block_from_fe() {
TNetworkAddress master_addr = ExecEnv::GetInstance()->master_info()->network_address;

TSchemaTableRequestParams schema_table_request_params;
for (int i = 0; i < _s_tbls_columns.size(); i++) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may need to add a version mechanism to control if the columns in _s_tbls_columns changed in the future, which keeps FE and BE seeing a consistent "table header"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is handled using TSchemaTableRequestParams.
TSchemaTableRequestParams BE will set the BE column names in a list and send to FE. FE handle request in MetadataGenerator and filters out the columns in function filterColumns and fills according to request from BE. so even some column count different between FE and BE, this method would solve it.

schema_table_request_params.__isset.columns_name = true;
schema_table_request_params.columns_name.emplace_back(_s_tbls_columns[i].name);
}
schema_table_request_params.__set_current_user_ident(*_param->common_param->current_user_ident);

TFetchSchemaTableDataRequest request;
request.__set_schema_table_name(TSchemaTableName::TABLE_OPTIONS);
request.__set_schema_table_params(schema_table_request_params);

TFetchSchemaTableDataResult result;

RETURN_IF_ERROR(ThriftRpcHelper::rpc<FrontendServiceClient>(
master_addr.hostname, master_addr.port,
[&request, &result](FrontendServiceConnection& client) {
client->fetchSchemaTableData(result, request);
},
_rpc_timeout_ms));

Status status(Status::create(result.status));
if (!status.ok()) {
LOG(WARNING) << "fetch table options from FE failed, errmsg=" << status;
return status;
}
std::vector<TRow> result_data = result.data_batch;

_tableoptions_block = vectorized::Block::create_unique();
for (int i = 0; i < _s_tbls_columns.size(); ++i) {
TypeDescriptor descriptor(_s_tbls_columns[i].type);
auto data_type = vectorized::DataTypeFactory::instance().create_data_type(descriptor, true);
_tableoptions_block->insert(vectorized::ColumnWithTypeAndName(
data_type->create_column(), data_type, _s_tbls_columns[i].name));
}
_tableoptions_block->reserve(_block_rows_limit);
if (result_data.size() > 0) {
int col_size = result_data[0].column_value.size();
if (col_size != _s_tbls_columns.size()) {
return Status::InternalError<false>("table options schema is not match for FE and BE");
}
}

for (int i = 0; i < result_data.size(); i++) {
TRow row = result_data[i];
for (int j = 0; j < _s_tbls_columns.size(); j++) {
RETURN_IF_ERROR(insert_block_column(row.column_value[j], j, _tableoptions_block.get(),
_s_tbls_columns[j].type));
}
}
return Status::OK();
}

Status SchemaTableOptionsScanner::get_next_block(vectorized::Block* block, bool* eos) {
if (!_is_init) {
return Status::InternalError("Used before initialized.");
}

if (nullptr == block || nullptr == eos) {
return Status::InternalError("input pointer is nullptr.");
}

if (_tableoptions_block == nullptr) {
RETURN_IF_ERROR(get_block_from_fe());
_total_rows = _tableoptions_block->rows();
}

if (_row_idx == _total_rows) {
*eos = true;
return Status::OK();
}

int current_batch_rows = std::min(_block_rows_limit, _total_rows - _row_idx);
vectorized::MutableBlock mblock = vectorized::MutableBlock::build_mutable_block(block);
RETURN_IF_ERROR(mblock.add_rows(_tableoptions_block.get(), _row_idx, current_batch_rows));
_row_idx += current_batch_rows;

*eos = _row_idx == _total_rows;
return Status::OK();
}

} // namespace doris
52 changes: 52 additions & 0 deletions be/src/exec/schema_scanner/schema_table_options_scanner.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// 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.

#pragma once

#include <vector>

#include "common/status.h"
#include "exec/schema_scanner.h"

namespace doris {
class RuntimeState;
namespace vectorized {
class Block;
} // namespace vectorized

class SchemaTableOptionsScanner : public SchemaScanner {
ENABLE_FACTORY_CREATOR(SchemaTableOptionsScanner);

public:
SchemaTableOptionsScanner();
~SchemaTableOptionsScanner() override = default;

Status start(RuntimeState* state) override;
Status get_next_block(vectorized::Block* block, bool* eos) override;

static std::vector<SchemaScanner::ColumnDesc> _s_tbls_columns;

private:
Status get_block_from_fe();

int _block_rows_limit = 4096;
int _row_idx = 0;
int _total_rows = 0;
std::unique_ptr<vectorized::Block> _tableoptions_block = nullptr;
int _rpc_timeout_ms = 3000;
};
}; // namespace doris
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@ public enum SchemaTableType {
SCH_WORKLOAD_GROUPS("WORKLOAD_GROUPS", "WORKLOAD_GROUPS", TSchemaTableType.SCH_WORKLOAD_GROUPS),
SCHE_USER("user", "user", TSchemaTableType.SCH_USER),
SCH_PROCS_PRIV("procs_priv", "procs_priv", TSchemaTableType.SCH_PROCS_PRIV),

SCH_WORKLOAD_POLICY("WORKLOAD_POLICY", "WORKLOAD_POLICY",
TSchemaTableType.SCH_WORKLOAD_POLICY);
TSchemaTableType.SCH_WORKLOAD_POLICY),
SCH_TABLE_OPTIONS("TABLE_OPTIONS", "TABLE_OPTIONS",
TSchemaTableType.SCH_TABLE_OPTIONS);

private static final String dbName = "INFORMATION_SCHEMA";
private static SelectList fullSelectLists;
Expand Down
14 changes: 14 additions & 0 deletions fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -1995,6 +1995,20 @@ public int getKeysNum() {
return keysNum;
}

public String getKeyColAsString() {
StringBuilder str = new StringBuilder();
str.append("");
for (Column column : getBaseSchema()) {
if (column.isKey()) {
if (str.length() != 0) {
str.append(",");
}
str.append(column.getName());
}
}
return str.toString();
}

public boolean convertHashDistributionToRandomDistribution() {
boolean hasChanged = false;
if (defaultDistributionInfo.getType() == DistributionInfoType.HASH) {
Expand Down
13 changes: 13 additions & 0 deletions fe/fe-core/src/main/java/org/apache/doris/catalog/SchemaTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,19 @@ public class SchemaTable extends Table {
.column("VERSION", ScalarType.createType(PrimitiveType.INT))
.column("WORKLOAD_GROUP", ScalarType.createStringType())
.build()))
.put("table_options",
new SchemaTable(SystemIdGenerator.getNextId(), "table_options", TableType.SCHEMA,
builder().column("TABLE_NAME", ScalarType.createVarchar(NAME_CHAR_LEN))
.column("TABLE_CATALOG", ScalarType.createVarchar(NAME_CHAR_LEN))
.column("TABLE_SCHEMA", ScalarType.createVarchar(NAME_CHAR_LEN))
.column("TABLE_MODEL", ScalarType.createStringType())
.column("TABLE_MODEL_KEY", ScalarType.createStringType())
.column("DISTRIBUTE_KEY", ScalarType.createStringType())
.column("DISTRIBUTE_TYPE", ScalarType.createStringType())
.column("BUCKETS_NUM", ScalarType.createType(PrimitiveType.INT))
.column("PARTITION_NUM", ScalarType.createType(PrimitiveType.INT))
.column("PROPERTIES", ScalarType.createStringType())
.build()))
.build();

protected SchemaTable(long id, String name, TableType type, List<Column> baseSchema) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import org.apache.doris.thrift.TStorageFormat;
import org.apache.doris.thrift.TStorageMedium;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Strings;
import com.google.common.collect.Maps;
import com.google.gson.annotations.SerializedName;
Expand Down Expand Up @@ -663,4 +665,13 @@ public String getStorageVaultName() {
public void setStorageVaultName(String storageVaultName) {
properties.put(PropertyAnalyzer.PROPERTIES_STORAGE_VAULT_NAME, storageVaultName);
}

public String getPropertiesString() throws IOException {
ObjectMapper objectMapper = new ObjectMapper();
try {
return objectMapper.writeValueAsString(properties);
} catch (JsonProcessingException e) {
throw new IOException(e);
}
}
}
Loading