diff --git a/be/src/exec/CMakeLists.txt b/be/src/exec/CMakeLists.txt index 5bf54673cb144d..3e093e3f53ee74 100644 --- a/be/src/exec/CMakeLists.txt +++ b/be/src/exec/CMakeLists.txt @@ -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 diff --git a/be/src/exec/schema_scanner.cpp b/be/src/exec/schema_scanner.cpp index 3fc048cc469162..4cbbb31fb9eaf2 100644 --- a/be/src/exec/schema_scanner.cpp +++ b/be/src/exec/schema_scanner.cpp @@ -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 { diff --git a/be/src/exec/schema_scanner/schema_columns_scanner.cpp b/be/src/exec/schema_scanner/schema_columns_scanner.cpp index 3bef284b865aa7..b248c4b49113fd 100644 --- a/be/src/exec/schema_scanner/schema_columns_scanner.cpp +++ b/be/src/exec/schema_scanner/schema_columns_scanner.cpp @@ -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: diff --git a/be/src/exec/schema_scanner/schema_statistics_scanner.cpp b/be/src/exec/schema_scanner/schema_statistics_scanner.cpp new file mode 100644 index 00000000000000..995178edc751ea --- /dev/null +++ b/be/src/exec/schema_scanner/schema_statistics_scanner.cpp @@ -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() { + +} + +} diff --git a/be/src/exec/schema_scanner/schema_statistics_scanner.h b/be/src/exec/schema_scanner/schema_statistics_scanner.h new file mode 100644 index 00000000000000..fd5a8e0c184a4a --- /dev/null +++ b/be/src/exec/schema_scanner/schema_statistics_scanner.h @@ -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 diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/PrimitiveType.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/PrimitiveType.java index 0972009d79cde5..40f994e40f4821 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/PrimitiveType.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/PrimitiveType.java @@ -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: @@ -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; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/SchemaTable.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/SchemaTable.java index 01da908510df2c..ade3ef356bcebf 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/SchemaTable.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/SchemaTable.java @@ -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 { diff --git a/fe/fe-core/src/main/java/org/apache/doris/mysql/MysqlSerializer.java b/fe/fe-core/src/main/java/org/apache/doris/mysql/MysqlSerializer.java index 27d4b495ff5572..a9701e80e4ac4d 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/mysql/MysqlSerializer.java +++ b/fe/fe-core/src/main/java/org/apache/doris/mysql/MysqlSerializer.java @@ -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 @@ -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; + } + } }