@@ -19,6 +19,7 @@ limitations under the License.
1919#include < type_traits>
2020
2121#include " flex/codegen/src/string_utils.h"
22+ #include " flex/proto_generated_gie/basic_type.pb.h"
2223#include " flex/proto_generated_gie/common.pb.h"
2324#include " glog/logging.h"
2425#include " google/protobuf/any.h"
@@ -63,62 +64,109 @@ inline bool operator==(const ParamConst& lhs, const ParamConst& rhs) {
6364
6465} // namespace codegen
6566
66- static codegen::DataType common_data_type_pb_2_data_type (
67- const common::DataType& data_type ) {
68- switch (data_type ) {
69- case common::DataType::INT32 :
67+ static codegen::DataType primitive_type_to_data_type (
68+ const common::PrimitiveType& type ) {
69+ switch (type ) {
70+ case common::PrimitiveType::DT_SIGNED_INT32 :
7071 return codegen::DataType::kInt32 ;
71- case common::DataType::INT64 :
72+ case common::PrimitiveType::DT_SIGNED_INT64 :
7273 return codegen::DataType::kInt64 ;
73- case common::DataType::DOUBLE:
74+ case common::PrimitiveType::DT_FLOAT:
75+ return codegen::DataType::kFloat ;
76+ case common::PrimitiveType::DT_DOUBLE:
7477 return codegen::DataType::kDouble ;
75- case common::DataType::STRING:
76- return codegen::DataType::kString ;
77- case common::DataType::INT64_ARRAY:
78- return codegen::DataType::kInt64Array ;
79- case common::DataType::INT32_ARRAY:
80- return codegen::DataType::kInt32Array ;
81- case common::DataType::BOOLEAN:
78+ case common::PrimitiveType::DT_BOOL:
8279 return codegen::DataType::kBoolean ;
83- case common::DataType::DATE32:
80+ default :
81+ // LOG(FATAL) << "unknown primitive type";
82+ throw std::runtime_error (
83+ " unknown primitive type when converting primitive type to data type:" +
84+ std::to_string (static_cast <int >(type)));
85+ }
86+ }
87+
88+ static codegen::DataType temporal_type_to_data_type (
89+ const common::Temporal& type) {
90+ switch (type.item_case ()) {
91+ case common::Temporal::ItemCase::kDate :
8492 return codegen::DataType::kDate ;
85- case common::DataType::TIME32 :
93+ case common::Temporal::ItemCase:: kTime :
8694 return codegen::DataType::kTime ;
87- case common::DataType::TIMESTAMP :
95+ case common::Temporal:: kTimestamp :
8896 return codegen::DataType::kTimeStamp ;
97+ default :
98+ throw std::runtime_error (
99+ " unknown temporal type when converting temporal type to data type:" +
100+ std::to_string (static_cast <int >(type.item_case ())));
101+ }
102+ }
103+
104+ static codegen::DataType common_data_type_pb_2_data_type (
105+ const common::DataType& data_type) {
106+ switch (data_type.item_case ()) {
107+ case common::DataType::ItemCase::kPrimitiveType :
108+ return primitive_type_to_data_type (data_type.primitive_type ());
109+ case common::DataType::ItemCase::kDecimal :
110+ LOG (FATAL) << " Not support decimal type" ;
111+ case common::DataType::ItemCase::kString :
112+ return codegen::DataType::kString ;
113+ case common::DataType::ItemCase::kTemporal :
114+ return temporal_type_to_data_type (data_type.temporal ());
115+ case common::DataType::ItemCase::kArray :
116+ case common::DataType::ItemCase::kMap :
117+ LOG (FATAL) << " Not support array or map type" ;
89118 default :
90119 // LOG(FATAL) << "unknown data type";
91120 throw std::runtime_error (
92121 " unknown data type when converting common_data_type to inner data "
93122 " type:" +
94- std::to_string ( static_cast < int >( data_type) ));
123+ data_type. DebugString ( ));
95124 }
96125}
97126
98- static std::string single_common_data_type_pb_2_str (
99- const common::DataType& data_type) {
100- switch (data_type) {
101- case common::DataType::BOOLEAN:
102- return " bool" ;
103- case common::DataType::INT32:
127+ static std::string primitive_type_to_str (const common::PrimitiveType& type) {
128+ switch (type) {
129+ case common::PrimitiveType::DT_SIGNED_INT32:
104130 return " int32_t" ;
105- case common::DataType::INT64:
131+ case common::PrimitiveType::DT_UNSIGNED_INT32:
132+ return " uint32_t" ;
133+ case common::PrimitiveType::DT_SIGNED_INT64:
106134 return " int64_t" ;
107- case common::DataType::DOUBLE:
135+ case common::PrimitiveType::DT_UNSIGNED_INT64:
136+ return " uint64_t" ;
137+ case common::PrimitiveType::DT_FLOAT:
138+ return " float" ;
139+ case common::PrimitiveType::DT_DOUBLE:
108140 return " double" ;
109- case common::DataType::STRING:
141+ case common::PrimitiveType::DT_BOOL:
142+ return " bool" ;
143+ default :
144+ // LOG(FATAL) << "unknown primitive type";
145+ throw std::runtime_error (
146+ " unknown primitive type when converting primitive type to string:" +
147+ std::to_string (static_cast <int >(type)));
148+ }
149+ }
150+
151+ static std::string single_common_data_type_pb_2_str (
152+ const common::DataType& data_type) {
153+ switch (data_type.item_case ()) {
154+ case common::DataType::ItemCase::kPrimitiveType :
155+ return primitive_type_to_str (data_type.primitive_type ());
156+ case common::DataType::ItemCase::kDecimal :
157+ LOG (FATAL) << " Not support decimal type" ;
158+ case common::DataType::ItemCase::kString :
110159 return " std::string_view" ;
111- case common::DataType::INT64_ARRAY:
112- return " std::vector<int64_t>" ;
113- case common::DataType::INT32_ARRAY:
114- return " std::vector<int32_t>" ;
115- case common::DataType::DATE32:
116- return " Date" ;
160+ case common::DataType::ItemCase::kTemporal :
161+ LOG (FATAL) << " Not support temporal type" ;
162+ case common::DataType::ItemCase::kArray :
163+ case common::DataType::ItemCase::kMap :
164+ LOG (FATAL) << " Not support array or map type" ;
117165 // TODO: support time32 and timestamp
118166 default :
119167 throw std::runtime_error (
120168 " unknown data type when convert common data type to string:" +
121- std::to_string ( static_cast < int >( data_type) ));
169+ data_type. DebugString ( ));
122170 }
123171}
124172
@@ -266,21 +314,22 @@ static std::string data_type_2_rust_string(const codegen::DataType& data_type) {
266314}
267315
268316static common::DataType common_value_2_data_type (const common::Value& value) {
317+ common::DataType ret;
269318 switch (value.item_case ()) {
270319 case common::Value::kI32 :
271- return common::DataType::INT32 ;
320+ ret. set_primitive_type ( common::PrimitiveType::DT_SIGNED_INT32) ;
272321 case common::Value::kI64 :
273- return common::DataType::INT64 ;
322+ ret. set_primitive_type ( common::PrimitiveType::DT_SIGNED_INT64) ;
274323 case common::Value::kBoolean :
275- return common::DataType::BOOLEAN ;
324+ ret. set_primitive_type ( common::PrimitiveType::DT_BOOL) ;
276325 case common::Value::kF64 :
277- return common::DataType::DOUBLE ;
326+ ret. set_primitive_type ( common::PrimitiveType::DT_DOUBLE) ;
278327 case common::Value::kStr :
279- return common::DataType::STRING ;
328+ ret. mutable_string ()-> mutable_long_text () ;
280329 default :
281330 LOG (FATAL) << " unknown value" << value.DebugString ();
282331 }
283- return common::DataType::NONE ;
332+ return ret ;
284333}
285334
286335static void parse_param_const_from_pb (
0 commit comments