This is an automated email from the ASF dual-hosted git repository.

morningman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 18a22bd  [BUG] Fix field error in information_schema.columns (#4858)
18a22bd is described below

commit 18a22bd347b9b16916f3335aa99550f2ec5d7c10
Author: HangyuanLiu <[email protected]>
AuthorDate: Sun Nov 15 22:01:32 2020 +0800

    [BUG] Fix field error in information_schema.columns (#4858)
---
 .../exec/schema_scanner/schema_columns_scanner.cpp | 40 ++++++++++++++++++----
 .../apache/doris/service/FrontendServiceImpl.java  |  1 +
 gensrc/thrift/FrontendService.thrift               |  1 +
 3 files changed, 36 insertions(+), 6 deletions(-)

diff --git a/be/src/exec/schema_scanner/schema_columns_scanner.cpp 
b/be/src/exec/schema_scanner/schema_columns_scanner.cpp
index affeac3..416df14 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<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");
+                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<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;
             } 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 c44d273..4f6158c 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 class FrontendServiceImpl implements 
FrontendService.Iface {
                         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 71b969c..cd77f05 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 <table> statements. 
A column


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to