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
1 change: 1 addition & 0 deletions be/src/exec/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ set(EXEC_FILES
schema_scanner/schema_collations_scanner.cpp
schema_scanner/schema_helper.cpp
schema_scanner/schema_views_scanner.cpp
schema_scanner/schema_statistics_scanner.cpp
schema_scanner/schema_table_privileges_scanner.cpp
schema_scanner/schema_schema_privileges_scanner.cpp
schema_scanner/schema_user_privileges_scanner.cpp
Expand Down
1 change: 1 addition & 0 deletions be/src/exec/schema_scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "exec/schema_scanner/schema_user_privileges_scanner.h"
#include "exec/schema_scanner/schema_variables_scanner.h"
#include "exec/schema_scanner/schema_views_scanner.h"
#include "exec/schema_scanner/schema_statistics_scanner.h"

namespace doris {

Expand Down
2 changes: 1 addition & 1 deletion be/src/exec/schema_scanner/schema_columns_scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ std::string SchemaColumnsScanner::to_mysql_data_type_string(TColumnDesc& desc) {
std::string SchemaColumnsScanner::type_to_string(TColumnDesc& desc) {
switch (desc.columnType) {
case TPrimitiveType::BOOLEAN:
return "tinyint(4)";
return "tinyint(1)";
case TPrimitiveType::TINYINT:
return "tinyint(4)";
case TPrimitiveType::SMALLINT:
Expand Down
52 changes: 52 additions & 0 deletions be/src/exec/schema_scanner/schema_statistics_scanner.cpp
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.

#include "exec/schema_scanner/schema_statistics_scanner.h"
#include "runtime/primitive_type.h"
#include "runtime/string_value.h"

namespace doris {

SchemaScanner::ColumnDesc SchemaStatisticsScanner::_s_cols_statistics[] = {
// name, type, size, is_null
{ "TABLE_CATALOG", TYPE_VARCHAR, sizeof(StringValue), true },
{ "TABLE_SCHEMA", TYPE_VARCHAR, sizeof(StringValue), false },
{ "TABLE_NAME", TYPE_VARCHAR, sizeof(StringValue), false },
{ "NON_UNIQUE", TYPE_BIGINT, sizeof(int64_t), false },
{ "INDEX_SCHEMA", TYPE_VARCHAR, sizeof(StringValue), false },
{ "INDEX_NAME", TYPE_VARCHAR, sizeof(StringValue), false },
{ "SEQ_IN_INDEX", TYPE_BIGINT, sizeof(int64_t), false },
{ "COLUMN_NAME", TYPE_VARCHAR, sizeof(StringValue), false },
{ "COLLATION", TYPE_VARCHAR, sizeof(StringValue), true },
{ "CARDINALITY", TYPE_BIGINT, sizeof(int64_t), true },
{ "SUB_PART", TYPE_BIGINT, sizeof(int64_t), true },
{ "PACKED", TYPE_VARCHAR, sizeof(StringValue), true },
{ "NULLABLE", TYPE_VARCHAR, sizeof(StringValue), false },
{ "INDEX_TYPE", TYPE_VARCHAR, sizeof(StringValue), false },
{ "COMMENT", TYPE_VARCHAR, sizeof(StringValue), true },
};

SchemaStatisticsScanner::SchemaStatisticsScanner() :
SchemaScanner(_s_cols_statistics, sizeof(_s_cols_statistics) / sizeof(SchemaScanner::ColumnDesc)) {

}

SchemaStatisticsScanner::~SchemaStatisticsScanner() {

}

}
36 changes: 36 additions & 0 deletions be/src/exec/schema_scanner/schema_statistics_scanner.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// 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_STATISTICS_SCANNER_H
#define DORIS_BE_SRC_QUERY_EXEC_SCHEMA_SCANNER_SCHEMA_STATISTICS_SCANNER_H

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

namespace doris {
class SchemaStatisticsScanner : public SchemaScanner {
public:
SchemaStatisticsScanner();
virtual ~SchemaStatisticsScanner();

private:
static SchemaScanner::ColumnDesc _s_cols_statistics[];

};
}

#endif // DORIS_BE_SRC_QUERY_EXEC_SCHEMA_SCANNER_SCHEMA_STATISTICS_SCANNER_H
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,13 @@ public void setTimeType() {
isTimeType = true;
}

/**
* @return
*/
public boolean isTimeType() {
return isTimeType;
}

public static PrimitiveType fromThrift(TPrimitiveType tPrimitiveType) {
switch (tPrimitiveType) {
case INVALID_TYPE:
Expand Down Expand Up @@ -710,7 +717,7 @@ public MysqlColType toMysqlType() {
}
case DECIMAL:
case DECIMALV2:
return MysqlColType.MYSQL_TYPE_DECIMAL;
return MysqlColType.MYSQL_TYPE_NEWDECIMAL;
default:
return MysqlColType.MYSQL_TYPE_STRING;
}
Expand Down
23 changes: 23 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 @@ -322,7 +322,30 @@ public static Builder builder() {
.column("CHARACTER_SET_CLIENT", ScalarType.createVarchar(32))
.column("COLLATION_CONNECTION", ScalarType.createVarchar(32))
.build()))
.put("statistics",
new SchemaTable(
SystemIdGenerator.getNextId(),
"statistics",
TableType.SCHEMA,
builder()
.column("TABLE_CATALOG", ScalarType.createVarchar(512))
.column("TABLE_SCHEMA", ScalarType.createVarchar(64))
.column("TABLE_NAME", ScalarType.createVarchar(64))
.column("NON_UNIQUE", ScalarType.createType(PrimitiveType.BIGINT))
.column("INDEX_SCHEMA", ScalarType.createVarchar(64))
.column("INDEX_NAME", ScalarType.createVarchar(64))
.column("SEQ_IN_INDEX", ScalarType.createType(PrimitiveType.BIGINT))
.column("COLUMN_NAME", ScalarType.createVarchar(64))
.column("COLLATION", ScalarType.createVarchar(1))
.column("CARDINALITY", ScalarType.createType(PrimitiveType.BIGINT))
.column("SUB_PART", ScalarType.createType(PrimitiveType.BIGINT))
.column("PACKED", ScalarType.createVarchar(10))
.column("NULLABLE", ScalarType.createVarchar(3))
.column("INDEX_TYPE", ScalarType.createVarchar(16))
.column("COMMENT", ScalarType.createVarchar(16))
.build()))
.build();
// statistics is table provides information about table indexes in mysql: 5.7
// views column is from show create table views in mysql: 5.5.6

public static class Builder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public void writeField(String colName, PrimitiveType type) {
// Character set: two byte integer
writeInt2(33);
// Column length: four byte integer
writeInt4(255);
writeInt4(getMysqlTypeLength(type));
// Column type: one byte integer
writeInt1(type.toMysqlType().getCode());
// Flags: two byte integer
Expand All @@ -224,4 +224,49 @@ public void writeField(String colName, PrimitiveType type) {
// filler: two byte integer
writeInt2(0);
}

/**
* Specify the display width of the returned data according to the MySQL type
* todo:The driver determines the number of bytes per character according to different character sets index
* @param type
* @return
*/
private int getMysqlTypeLength(PrimitiveType type) {
switch (type) {
// MySQL use Tinyint(1) to represent boolean
case BOOLEAN:
return 1;
case TINYINT:
return 4;
case SMALLINT:
return 6;
case INT:
return 11;
case BIGINT:
return 20;
case FLOAT:
return 12;
case DOUBLE:
return 22;
case TIME:
return 10;
case DATE:
return 10;
case DATETIME: {
if (type.isTimeType()) {
return 10;
} else {
return 19;
}
}
// todo:It needs to be obtained according to the field length set during the actual creation,
// todo:which is not supported for the time being.default is 255
// case DECIMAL:
// case DECIMALV2:
// case CHAR:
// case VARCHAR:
default:
return 255;
}
}
}