@@ -46,7 +46,8 @@ namespace doris {
4646
4747using strings::Substitute;
4848
49- Status convert_to_arrow_type (const TypeDescriptor& type, std::shared_ptr<arrow::DataType>* result) {
49+ Status convert_to_arrow_type (const TypeDescriptor& type, std::shared_ptr<arrow::DataType>* result,
50+ const std::string& timezone) {
5051 switch (type.type ) {
5152 case TYPE_NULL :
5253 *result = arrow::null ();
@@ -96,11 +97,11 @@ Status convert_to_arrow_type(const TypeDescriptor& type, std::shared_ptr<arrow::
9697 break ;
9798 case TYPE_DATETIMEV2 :
9899 if (type.scale > 3 ) {
99- *result = std::make_shared<arrow::TimestampType>(arrow::TimeUnit::MICRO );
100+ *result = std::make_shared<arrow::TimestampType>(arrow::TimeUnit::MICRO , timezone );
100101 } else if (type.scale > 0 ) {
101- *result = std::make_shared<arrow::TimestampType>(arrow::TimeUnit::MILLI );
102+ *result = std::make_shared<arrow::TimestampType>(arrow::TimeUnit::MILLI , timezone );
102103 } else {
103- *result = std::make_shared<arrow::TimestampType>(arrow::TimeUnit::SECOND );
104+ *result = std::make_shared<arrow::TimestampType>(arrow::TimeUnit::SECOND , timezone );
104105 }
105106 break ;
106107 case TYPE_DECIMALV2 :
@@ -120,16 +121,16 @@ Status convert_to_arrow_type(const TypeDescriptor& type, std::shared_ptr<arrow::
120121 case TYPE_ARRAY : {
121122 DCHECK_EQ (type.children .size (), 1 );
122123 std::shared_ptr<arrow::DataType> item_type;
123- static_cast <void >(convert_to_arrow_type (type.children [0 ], &item_type));
124+ static_cast <void >(convert_to_arrow_type (type.children [0 ], &item_type, timezone ));
124125 *result = std::make_shared<arrow::ListType>(item_type);
125126 break ;
126127 }
127128 case TYPE_MAP : {
128129 DCHECK_EQ (type.children .size (), 2 );
129130 std::shared_ptr<arrow::DataType> key_type;
130131 std::shared_ptr<arrow::DataType> val_type;
131- static_cast <void >(convert_to_arrow_type (type.children [0 ], &key_type));
132- static_cast <void >(convert_to_arrow_type (type.children [1 ], &val_type));
132+ static_cast <void >(convert_to_arrow_type (type.children [0 ], &key_type, timezone ));
133+ static_cast <void >(convert_to_arrow_type (type.children [1 ], &val_type, timezone ));
133134 *result = std::make_shared<arrow::MapType>(key_type, val_type);
134135 break ;
135136 }
@@ -138,7 +139,7 @@ Status convert_to_arrow_type(const TypeDescriptor& type, std::shared_ptr<arrow::
138139 std::vector<std::shared_ptr<arrow::Field>> fields;
139140 for (size_t i = 0 ; i < type.children .size (); i++) {
140141 std::shared_ptr<arrow::DataType> field_type;
141- static_cast <void >(convert_to_arrow_type (type.children [i], &field_type));
142+ static_cast <void >(convert_to_arrow_type (type.children [i], &field_type, timezone ));
142143 fields.push_back (std::make_shared<arrow::Field>(type.field_names [i], field_type,
143144 type.contains_nulls [i]));
144145 }
@@ -156,20 +157,22 @@ Status convert_to_arrow_type(const TypeDescriptor& type, std::shared_ptr<arrow::
156157 return Status::OK ();
157158}
158159
159- Status convert_to_arrow_field (SlotDescriptor* desc, std::shared_ptr<arrow::Field>* field) {
160+ Status convert_to_arrow_field (SlotDescriptor* desc, std::shared_ptr<arrow::Field>* field,
161+ const std::string& timezone) {
160162 std::shared_ptr<arrow::DataType> type;
161- RETURN_IF_ERROR (convert_to_arrow_type (desc->type (), &type));
163+ RETURN_IF_ERROR (convert_to_arrow_type (desc->type (), &type, timezone ));
162164 *field = arrow::field (desc->col_name (), type, desc->is_nullable ());
163165 return Status::OK ();
164166}
165167
166168Status convert_block_arrow_schema (const vectorized::Block& block,
167- std::shared_ptr<arrow::Schema>* result) {
169+ std::shared_ptr<arrow::Schema>* result,
170+ const std::string& timezone) {
168171 std::vector<std::shared_ptr<arrow::Field>> fields;
169172 for (const auto & type_and_name : block) {
170173 std::shared_ptr<arrow::DataType> arrow_type;
171174 RETURN_IF_ERROR (convert_to_arrow_type (type_and_name.type ->get_type_as_type_descriptor (),
172- &arrow_type));
175+ &arrow_type, timezone ));
173176 fields.push_back (std::make_shared<arrow::Field>(type_and_name.name , arrow_type,
174177 type_and_name.type ->is_nullable ()));
175178 }
@@ -178,12 +181,13 @@ Status convert_block_arrow_schema(const vectorized::Block& block,
178181}
179182
180183Status convert_to_arrow_schema (const RowDescriptor& row_desc,
181- std::shared_ptr<arrow::Schema>* result) {
184+ std::shared_ptr<arrow::Schema>* result,
185+ const std::string& timezone) {
182186 std::vector<std::shared_ptr<arrow::Field>> fields;
183187 for (auto tuple_desc : row_desc.tuple_descriptors ()) {
184188 for (auto desc : tuple_desc->slots ()) {
185189 std::shared_ptr<arrow::Field> field;
186- RETURN_IF_ERROR (convert_to_arrow_field (desc, &field));
190+ RETURN_IF_ERROR (convert_to_arrow_field (desc, &field, timezone ));
187191 fields.push_back (field);
188192 }
189193 }
@@ -192,12 +196,13 @@ Status convert_to_arrow_schema(const RowDescriptor& row_desc,
192196}
193197
194198Status convert_expr_ctxs_arrow_schema (const vectorized::VExprContextSPtrs& output_vexpr_ctxs,
195- std::shared_ptr<arrow::Schema>* result) {
199+ std::shared_ptr<arrow::Schema>* result,
200+ const std::string& timezone) {
196201 std::vector<std::shared_ptr<arrow::Field>> fields;
197202 for (int i = 0 ; i < output_vexpr_ctxs.size (); i++) {
198203 std::shared_ptr<arrow::DataType> arrow_type;
199204 auto root_expr = output_vexpr_ctxs.at (i)->root ();
200- RETURN_IF_ERROR (convert_to_arrow_type (root_expr->type (), &arrow_type));
205+ RETURN_IF_ERROR (convert_to_arrow_type (root_expr->type (), &arrow_type, timezone ));
201206 auto field_name = root_expr->is_slot_ref () && !root_expr->expr_label ().empty ()
202207 ? root_expr->expr_label ()
203208 : fmt::format (" {}_{}" , root_expr->data_type ()->get_name (), i);
0 commit comments