csun5285 commented on code in PR #54044:
URL: https://github.com/apache/doris/pull/54044#discussion_r2241438343


##########
be/src/vec/data_types/data_type_array.cpp:
##########
@@ -364,4 +364,40 @@ Status DataTypeArray::from_string(ReadBuffer& rb, IColumn* 
column) const {
     return Status::OK();
 }
 
+FieldWithDataType DataTypeArray::get_field_with_data_type(const IColumn& 
column,
+                                                          size_t row_num) 
const {
+    const auto& array_column = assert_cast<const ColumnArray&>(column);
+    int precision = -1;
+    int scale = -1;
+    auto nested_type = get_nested_type();
+    PrimitiveType nested_type_id = nested_type->get_primitive_type();
+    uint8_t num_dimensions = 1;
+    while (nested_type_id == TYPE_ARRAY) {
+        nested_type = remove_nullable(nested_type);
+        const auto& nested_array = assert_cast<const 
DataTypeArray&>(*nested_type);
+        nested_type_id = nested_array.get_nested_type()->get_primitive_type();
+        num_dimensions++;
+    }
+    if (is_decimal(nested_type_id)) {
+        precision = nested_type->get_precision();
+        scale = nested_type->get_scale();
+    } else if (nested_type_id == TYPE_DATETIMEV2) {
+        scale = nested_type->get_scale();
+    } else if (nested_type_id == TYPE_JSONB) {
+        // Array<Jsonb> should return JsonbField as element
+        Array arr;

Review Comment:
   这里其实假定了 num_dimensions = 1, array<array<json>> 进来估计就不对了



##########
be/src/vec/core/field.h:
##########
@@ -83,6 +83,27 @@ struct Map : public FieldVector {
     using FieldVector::FieldVector;
 };
 
+struct FieldWithDataType {
+    FieldWithDataType() = default;
+    explicit FieldWithDataType(Field&& f);
+    explicit FieldWithDataType(const Field& f);
+    explicit FieldWithDataType(Field&& f, int precision, int scale,
+                               PrimitiveType base_scalar_type_id = 
PrimitiveType::INVALID_TYPE,
+                               uint8_t num_dimensions = 0);
+    FieldWithDataType(const FieldWithDataType&);
+    FieldWithDataType& operator=(const FieldWithDataType&);
+    FieldWithDataType& operator=(FieldWithDataType&&) = default;
+    FieldWithDataType(FieldWithDataType&&) = default;
+    ~FieldWithDataType() = default;
+
+    std::unique_ptr<Field> field;
+    // used for nested type of array
+    PrimitiveType base_scalar_type_id = PrimitiveType::INVALID_TYPE;

Review Comment:
   这个是不是可以记录 field 的 scalar_type_id,除了 array 的,别的也可以用,这样就可以直接的拿到 field 的类型



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to