yinzhijian commented on code in PR #9856:
URL: https://github.com/apache/incubator-doris/pull/9856#discussion_r886622380


##########
be/src/vec/data_types/data_type_factory.hpp:
##########
@@ -49,22 +49,33 @@ class DataTypeFactory {
         static std::once_flag oc;
         static DataTypeFactory instance;
         std::call_once(oc, []() {
-            instance.register_data_type("UInt8", 
std::make_shared<DataTypeUInt8>());
-            instance.register_data_type("UInt16", 
std::make_shared<DataTypeUInt16>());
-            instance.register_data_type("UInt32", 
std::make_shared<DataTypeUInt32>());
-            instance.register_data_type("UInt64", 
std::make_shared<DataTypeUInt64>());
-            instance.register_data_type("Int8", 
std::make_shared<DataTypeInt8>());
-            instance.register_data_type("Int16", 
std::make_shared<DataTypeInt16>());
-            instance.register_data_type("Int32", 
std::make_shared<DataTypeInt32>());
-            instance.register_data_type("Int64", 
std::make_shared<DataTypeInt64>());
-            instance.register_data_type("Int128", 
std::make_shared<DataTypeInt128>());
-            instance.register_data_type("Float32", 
std::make_shared<DataTypeFloat32>());
-            instance.register_data_type("Float64", 
std::make_shared<DataTypeFloat64>());
-            instance.register_data_type("Date", 
std::make_shared<DataTypeDate>());
-            instance.register_data_type("DateTime", 
std::make_shared<DataTypeDateTime>());
-            instance.register_data_type("String", 
std::make_shared<DataTypeString>());
-            instance.register_data_type("Decimal",
-                                        
std::make_shared<DataTypeDecimal<Decimal128>>(27, 9));
+            std::unordered_map<std::string, DataTypePtr> base_type_map {
+                    {"UInt8", std::make_shared<DataTypeUInt8>()},
+                    {"UInt16", std::make_shared<DataTypeUInt16>()},
+                    {"UInt32", std::make_shared<DataTypeUInt32>()},
+                    {"UInt64", std::make_shared<DataTypeUInt64>()},
+                    {"Int8", std::make_shared<DataTypeInt8>()},
+                    {"Int16", std::make_shared<DataTypeInt16>()},
+                    {"Int32", std::make_shared<DataTypeInt32>()},
+                    {"Int64", std::make_shared<DataTypeInt64>()},
+                    {"Int128", std::make_shared<DataTypeInt128>()},
+                    {"Float32", std::make_shared<DataTypeFloat32>()},
+                    {"Float64", std::make_shared<DataTypeFloat64>()},
+                    {"Date", std::make_shared<DataTypeDate>()},
+                    {"DateTime", std::make_shared<DataTypeDateTime>()},
+                    {"String", std::make_shared<DataTypeString>()},
+                    {"Decimal", 
std::make_shared<DataTypeDecimal<Decimal128>>(27, 9)},
+
+            };
+            for (auto const& [key, val] : base_type_map) {
+                instance.register_data_type(key, val);
+                instance.register_data_type("Array(" + key + ")",
+                                            
std::make_shared<vectorized::DataTypeArray>(val));
+                instance.register_data_type(
+                        "Array(Nullable(" + key + "))",
+                        std::make_shared<vectorized::DataTypeArray>(
+                                
std::make_shared<vectorized::DataTypeNullable>(val)));
+            }

Review Comment:
   1. This map is used to convert string structures such as: 
(Array(Nullable(Varchar))) to a DataType structure, which is not the same as 
create_data_type
   
   2. Finding and returning pre-created structures from the map is currently 
the most efficient way to do String <=> DataType



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to