github-actions[bot] commented on code in PR #67325:
URL: https://github.com/apache/doris/pull/67325#discussion_r3998745488


##########
be/src/format_v2/lance/lance_reader_helper.cpp:
##########
@@ -178,8 +270,404 @@ Status arrow_field_to_doris_type(const 
std::shared_ptr<arrow::Field>& field,
     }
 }
 
+// Determine whether a field subtree contains values that require Lance 
normalization.
+Status field_requires_lance_normalization(const std::shared_ptr<arrow::Field>& 
field,
+                                          bool* requires_normalization) {
+    DORIS_CHECK(field != nullptr);
+    DORIS_CHECK(requires_normalization != nullptr);
+
+    LanceExtensionKind extension_kind;
+    std::shared_ptr<arrow::DataType> storage_type;
+    RETURN_IF_ERROR(get_lance_extension(field, &extension_kind, 
&storage_type));
+    bool required = extension_kind == LanceExtensionKind::BFLOAT16 ||
+                    field->type()->id() == arrow::Type::EXTENSION;
+    for (const auto& child : storage_type->fields()) {
+        bool child_required = false;
+        RETURN_IF_ERROR(field_requires_lance_normalization(child, 
&child_required));
+        required |= child_required;
+    }
+    *requires_normalization = required;
+    return Status::OK();
+}
+
+// Widen little-endian Lance BFloat16 values to Arrow Float32 without 
precision loss.
+Status convert_bfloat16_array(const std::shared_ptr<arrow::Array>& array,
+                              std::shared_ptr<arrow::Array>* normalized) {
+    DORIS_CHECK(array != nullptr);
+    DORIS_CHECK(normalized != nullptr);
+    const auto fixed_binary = 
std::dynamic_pointer_cast<arrow::FixedSizeBinaryArray>(array);
+    if (fixed_binary == nullptr || fixed_binary->byte_width() != 2) {
+        return Status::InvalidArgument("invalid Lance BFloat16 array storage: 
{}",
+                                       array->type()->ToString());
+    }
+    if (config::enable_arrow_input_validation) {
+        check_arrow_fixed_width_buffer(*fixed_binary, sizeof(uint16_t));
+    }
+
+    arrow::FloatBuilder builder;

Review Comment:
   [P2] Charge these normalization buffers to the query memory tracker. This 
parameter-free `FloatBuilder` and `compact_lance_array()`'s `MakeBuilder(..., 
arrow::default_memory_pool())` both materialize a complete Arrow array through 
Arrow's system pool rather than Doris's `ArrowMemoryPool`/`Allocator` path. A 
wide BFloat16 vector or compacted nested slice can therefore hold an extra 
batch-sized buffer outside the query's MemTracker while the destination Doris 
column is allocated, allowing the query to exceed its memory limit instead of 
failing or cancelling at this allocation. Please thread a Doris-tracked Arrow 
pool through both builder paths (with a test-safe fallback or injection) and 
cover the behavior under a low query memory limit.



-- 
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