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
40 changes: 34 additions & 6 deletions be/src/exec/schema_scanner/schema_columns_scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ std::string SchemaColumnsScanner::type_to_string(TColumnDesc &desc) {
}
}

//fill row in the "INFORMATION_SCHEMA COLUMNS"
//Reference from https://dev.mysql.com/doc/refman/8.0/en/information-schema-columns-table.html
Status SchemaColumnsScanner::fill_one_row(Tuple *tuple, MemPool *pool) {
// set all bit to not null
memset((void *)tuple, 0, _tuple_desc->num_null_bytes());
Expand Down Expand Up @@ -236,9 +238,22 @@ Status SchemaColumnsScanner::fill_one_row(Tuple *tuple, MemPool *pool) {
{
void *slot = tuple->get_slot(_tuple_desc->slots()[6]->tuple_offset());
StringValue* str_slot = reinterpret_cast<StringValue*>(slot);
str_slot->len = strlen("NO") + 1;
str_slot->ptr = (char *)pool->allocate(str_slot->len);
memcpy(str_slot->ptr, "NO", str_slot->len);

if (_desc_result.columns[_column_index].columnDesc.__isset.isAllowNull) {
if (_desc_result.columns[_column_index].columnDesc.isAllowNull) {
str_slot->len = strlen("YES");
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to plus 1?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think +1 is necessary here, and +1 will cause the character matching of the SQL result to fail. Such as IS_NULLABLE = "YES" is false

str_slot->ptr = (char *)pool->allocate(str_slot->len);
memcpy(str_slot->ptr, "YES", str_slot->len);
} else {
str_slot->len = strlen("NO");
str_slot->ptr = (char *)pool->allocate(str_slot->len);
memcpy(str_slot->ptr, "NO", str_slot->len);
}
} else {
str_slot->len = strlen("NO");
str_slot->ptr = (char *) pool->allocate(str_slot->len);
memcpy(str_slot->ptr, "NO", str_slot->len);
}
}
// DATA_TYPE
{
Expand All @@ -250,20 +265,33 @@ Status SchemaColumnsScanner::fill_one_row(Tuple *tuple, MemPool *pool) {
memcpy(str_slot->ptr, buffer.c_str(), str_slot->len);
}
// CHARACTER_MAXIMUM_LENGTH
// For string columns, the maximum length in characters.
{
tuple->set_null(_tuple_desc->slots()[8]->null_indicator_offset());
int data_type = _desc_result.columns[_column_index].columnDesc.columnType;
if (data_type == TPrimitiveType::VARCHAR || data_type == TPrimitiveType::CHAR) {
void *slot = tuple->get_slot(_tuple_desc->slots()[8]->tuple_offset());
int64_t* str_slot = reinterpret_cast<int64_t*>(slot);
if (_desc_result.columns[_column_index].columnDesc.__isset.columnLength) {
*str_slot = _desc_result.columns[_column_index].columnDesc.columnLength;
} else {
tuple->set_null(_tuple_desc->slots()[8]->null_indicator_offset());
}
} else {
tuple->set_null(_tuple_desc->slots()[8]->null_indicator_offset());
}
}
// CHARACTER_OCTET_LENGTH
// For string columns, the maximum length in bytes.
{
int data_type = _desc_result.columns[_column_index].columnDesc.columnType;
if (data_type == TPrimitiveType::VARCHAR || data_type == TPrimitiveType::CHAR) {
void *slot = tuple->get_slot(_tuple_desc->slots()[9]->tuple_offset());
int64_t* str_slot = reinterpret_cast<int64_t*>(slot);
if (_desc_result.columns[_column_index].columnDesc.__isset.columnLength) {
*str_slot = _desc_result.columns[_column_index].columnDesc.columnLength;
*str_slot = _desc_result.columns[_column_index].columnDesc.columnLength * 4;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why 4?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For mysql-compatible purposes, we need to multiply this by 4.
According to https://dev.mysql.com/doc/refman/8.0/en/information-schema-columns-table.html. CHARACTER_OCTET_LENGTH stands for maximum length in bytes, while CHARACTER_MAXIMUM_LENGTH stands for maximum length in characters

} else {
tuple->set_null(_tuple_desc->slots()[9]->null_indicator_offset());
}
}
} else {
tuple->set_null(_tuple_desc->slots()[9]->null_indicator_offset());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ public TDescribeTableResult describeTable(TDescribeTableParams params) throws TE
if (decimalDigits != null) {
desc.setColumnScale(decimalDigits);
}
desc.setIsAllowNull(column.isAllowNull());
final TColumnDef colDef = new TColumnDef(desc);
final String comment = column.getComment();
if(comment != null) {
Expand Down
1 change: 1 addition & 0 deletions gensrc/thrift/FrontendService.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ struct TColumnDesc {
3: optional i32 columnLength
4: optional i32 columnPrecision
5: optional i32 columnScale
6: optional bool isAllowNull
}

// A column definition; used by CREATE TABLE and DESCRIBE <table> statements. A column
Expand Down