diff --git a/be/src/exec/schema_scanner/schema_columns_scanner.cpp b/be/src/exec/schema_scanner/schema_columns_scanner.cpp index affeac34382e50..416df14dc75eae 100644 --- a/be/src/exec/schema_scanner/schema_columns_scanner.cpp +++ b/be/src/exec/schema_scanner/schema_columns_scanner.cpp @@ -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()); @@ -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(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"); + 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 { @@ -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(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(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; } else { tuple->set_null(_tuple_desc->slots()[9]->null_indicator_offset()); - } + } } else { tuple->set_null(_tuple_desc->slots()[9]->null_indicator_offset()); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/service/FrontendServiceImpl.java b/fe/fe-core/src/main/java/org/apache/doris/service/FrontendServiceImpl.java index c44d2730351f79..4f6158cc24fc67 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/service/FrontendServiceImpl.java +++ b/fe/fe-core/src/main/java/org/apache/doris/service/FrontendServiceImpl.java @@ -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) { diff --git a/gensrc/thrift/FrontendService.thrift b/gensrc/thrift/FrontendService.thrift index 71b969c79bb798..cd77f053002703 100644 --- a/gensrc/thrift/FrontendService.thrift +++ b/gensrc/thrift/FrontendService.thrift @@ -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 statements. A column