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
38 changes: 37 additions & 1 deletion be/src/exec/schema_scanner/schema_columns_scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,42 @@ Status SchemaColumnsScanner::start(RuntimeState *state) {
return Status::OK();
}

//For compatibility with mysql the result of DATA_TYPE in information_schema.columns
std::string SchemaColumnsScanner::to_mysql_data_type_string(TColumnDesc &desc) {
switch (desc.columnType) {
case TPrimitiveType::BOOLEAN:
return "tinyint";
case TPrimitiveType::TINYINT:
return "tinyint";
case TPrimitiveType::SMALLINT:
return "smallint";
case TPrimitiveType::INT:
return "int";
case TPrimitiveType::BIGINT:
return "bigint";
case TPrimitiveType::LARGEINT:
return "bigint unsinged";
case TPrimitiveType::FLOAT:
return "float";
case TPrimitiveType::DOUBLE:
return "double";
case TPrimitiveType::VARCHAR:
Copy link
Contributor

Choose a reason for hiding this comment

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

How to display the length of varchar?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the varchar has length display in COLUMN_TYPE, NOT DATA_TYPE

return "varchar";
case TPrimitiveType::CHAR:
return "char";
case TPrimitiveType::DATE:
return "date";
case TPrimitiveType::DATETIME:
return "datetime";
case TPrimitiveType::DECIMALV2:
case TPrimitiveType::DECIMAL: {
return "decimal";
}
default:
return "unknown";
}
}

std::string SchemaColumnsScanner::type_to_string(TColumnDesc &desc) {
switch (desc.columnType) {
case TPrimitiveType::BOOLEAN:
Expand Down Expand Up @@ -208,7 +244,7 @@ Status SchemaColumnsScanner::fill_one_row(Tuple *tuple, MemPool *pool) {
{
void *slot = tuple->get_slot(_tuple_desc->slots()[7]->tuple_offset());
StringValue* str_slot = reinterpret_cast<StringValue*>(slot);
std::string buffer = type_to_string(_desc_result.columns[_column_index].columnDesc);
std::string buffer = to_mysql_data_type_string(_desc_result.columns[_column_index].columnDesc);
str_slot->len = buffer.length();
str_slot->ptr = (char *)pool->allocate(str_slot->len);
memcpy(str_slot->ptr, buffer.c_str(), str_slot->len);
Expand Down
1 change: 1 addition & 0 deletions be/src/exec/schema_scanner/schema_columns_scanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class SchemaColumnsScanner : public SchemaScanner {
Status fill_one_row(Tuple *tuple, MemPool *pool);
Status get_new_desc();
Status get_create_table(std::string *result);
std::string to_mysql_data_type_string(TColumnDesc &desc);
std::string type_to_string(TColumnDesc &desc);

int _db_index;
Expand Down