hello-stephen commented on code in PR #71149:
URL: https://github.com/apache/doris/pull/71149#discussion_r4736075037
##########
be/src/core/data_type/data_type_file.cpp:
##########
@@ -146,9 +154,21 @@ char* DataTypeFile::serialize(const IColumn& column, char*
buf, int version) con
size_t rows = 0;
buf = serialize_const_flag_and_row_num(&data, buf, &rows);
const auto& file = assert_cast<const ColumnFile&>(*data);
+ const bool has_blob_ids = file.has_blob_references();
for (size_t i = 0; i < FIELD_COUNT; ++i) {
buf = _elements[i]->serialize(file.get_column(i), buf, version);
}
+ // The presence flag distinguishes bound references from ordinary FILE
values.
+ *buf++ = static_cast<uint8_t>(has_blob_ids);
Review Comment:
[P1] Version the FILE wire format before sending it to older BEs
This appends a trailer for every execution version, while the previous
deserializer returns immediately after the six children. A reachable
mixed-version case is an external scan on upgraded compute nodes
(`prefer_compute_node_for_external_table=true`, with enough compute nodes)
broadcast into an internal-table join on an older storage BE. The scan's
compatibility fence only checks its compute candidates; the OLAP fragment still
uses the old tablet replica. With two FILE columns in that broadcast block, the
old receiver parses the first FILE's trailer as the next column and corrupts
block decoding. Both peers accept execution version 19. Please
negotiate/version this layout and prevent bound FILE references from reaching
incompatible consumers; the changed `collect_list` state needs the same
treatment. The new/new round-trip tests at two version numbers do not exercise
an old peer.
##########
fe/fe-connector/fe-connector-lance/src/main/java/org/apache/doris/connector/lance/LanceTypeMapping.java:
##########
@@ -88,8 +89,20 @@ static boolean requiresCurrentBeReader(Field field) {
return false;
}
+ static boolean isBlob(Field field) {
+ return LANCE_BLOB_EXTENSION.equals(extensionNameOf(field));
+ }
+
/** Converts one Arrow field, including Null leaves in complex types. */
static ConnectorType toConnectorType(Field field) {
+ return toConnectorType(field, true);
+ }
+
+ private static ConnectorType toConnectorType(Field field, boolean
topLevel) {
+ if (isBlob(field)) {
+ return topLevel && field.getType().getTypeID() ==
ArrowType.ArrowTypeID.Struct
Review Comment:
[P2] Include BLOB projections in the current-reader fence
A normal `lance.blob.v2` struct is now exposed as FILE, but
`requiresCurrentBeReader()` still returns false for it and its primitive
children. Consequently the scan omits `REQUIRED_CURRENT_BACKEND_SEMANTICS`, so
the smooth-upgrade check in `PluginDrivenScanNode.createScanRangeLocations()`
does not reject an old source BE. That reader's schema normalizer rejects
`lance.blob.v2` as an unsupported extension. Please opt BLOB projections into
the same fence used for the other newly supported Lance types, and cover the
blob-only projection in the marker tests.
##########
be/src/format_v2/paimon/paimon_file_content_reader.cpp:
##########
@@ -0,0 +1,119 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "format_v2/paimon/paimon_file_content_reader.h"
+
+#include <cstring>
+#include <limits>
+#include <map>
+#include <string>
+#include <tuple>
+
+#include "core/column/column_varbinary.h"
+#include "format_v2/paimon/paimon_blob_helper.h"
+#include "format_v2/paimon/paimon_file_content_reader_range.h"
+#include "gen_cpp/PlanNodes_types.h"
+#include "io/file_factory.h"
+#include "io/io_common.h"
+#include "runtime/file_content_reader.h"
+#include "runtime/file_read_io_context.h"
+#include "runtime/runtime_state.h"
+
+namespace doris::format::paimon {
+namespace {
+Status validate_content_request(const FileReadRequest& read_request, int64_t
max_payload_size) {
+ if (read_request.uri.empty() || read_request.uri.find('\0') !=
std::string_view::npos ||
+ read_request.offset < 0 || read_request.length < 0) {
+ return Status::Corruption("Incomplete Paimon FILE range");
+ }
+ if (read_request.length > max_payload_size ||
+ read_request.length > std::numeric_limits<int32_t>::max()) {
+ return Status::InvalidArgument(
+ "Paimon BLOB inline size {} bytes exceeds
paimon_blob_max_size={} bytes or "
+ "FILE capacity",
+ read_request.length, max_payload_size);
+ }
+ return Status::OK();
+}
+} // namespace
+
+Status PaimonFileContentReader::read_blob(RuntimeState* runtime_state,
+ const TFileReadResource&
file_read_resource,
+ const std::vector<FileReadRequest>&
read_requests,
+ ColumnVarbinary* payload_column) {
+ const auto& paimon_resource = file_read_resource.paimon;
+ PaimonBlobReadMode blob_read_mode;
+ switch (paimon_resource.table_type) {
+ case TPaimonTableType::PRIMARY_KEY:
+ blob_read_mode = PaimonBlobReadMode::RAW_RANGE;
+ break;
+ case TPaimonTableType::APPEND:
+ blob_read_mode = PaimonBlobReadMode::APPEND_RECORD;
+ break;
+ default:
+ return Status::InvalidArgument("Unsupported Paimon table type: {}",
+
static_cast<int>(paimon_resource.table_type));
+ }
+ // Handles and I/O context are call-local. Reuse handles within this batch
and release them
+ // before returning.
+ io::FileSystemProperties filesystem_properties;
+ filesystem_properties.system_type = paimon_resource.file_type;
+ filesystem_properties.properties = paimon_resource.properties;
+ filesystem_properties.hdfs_params = paimon_resource.hdfs_params;
+ filesystem_properties.broker_addresses = paimon_resource.broker_addresses;
+ io::IOContext io_context;
+ init_file_read_io_context(runtime_state, &io_context);
+ io_context.is_disposable =
runtime_state->query_options().disable_file_cache;
+ const std::string filesystem_name;
Review Comment:
[P2] Preserve the HDFS authority when reopening deferred BLOBs
For a Paimon warehouse such as `hdfs://nn:8020/warehouse` without an
explicit `fs.defaultFS`, the scanner gets the namenode from the split's
`fs_name`, but this deferred reader passes an empty name. `FileFactory`'s HDFS
reader only falls back to `hdfs_params.fs_name`; it does not derive the
authority from the blob URI. `convert_path()` then turns that URI into
`/hdfs://nn:8020/...` before opening it. Consequently selecting the FILE
descriptor succeeds but `fl_get_binary()` fails. A URI whose authority differs
from the configured default also suffers this mismatch. Resolve the filesystem
identity from each blob URI, preserving the scan path's behavior.
##########
be/test/format_v2/paimon/paimon_append_blob_file_test.cpp:
##########
@@ -0,0 +1,356 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "format_v2/paimon/paimon_append_blob_file.h"
+
+#include <gtest/gtest.h>
+
+#include <algorithm>
+#include <cstring>
+#include <limits>
+#include <optional>
+#include <string>
+#include <utility>
+#include <vector>
+
+#include "format_v2/paimon/blob_test_util.h"
+#include "io/io_common.h"
+
+namespace doris::format::paimon {
+namespace {
+
+using blob_test::encode_record_lengths;
+using blob_test::finish_blob_file;
+using blob_test::make_blob_file;
+
+class MemoryBlobFile final : public io::FileReader {
+public:
+ // A nonzero offset represents a sparse file: only its index/footer are
backed by memory.
+ explicit MemoryBlobFile(std::string bytes, size_t content_offset = 0)
+ : _bytes(std::move(bytes)), _content_offset(content_offset) {}
+
+ Status close() override {
+ _closed = true;
+ return Status::OK();
+ }
+ const io::Path& path() const override { return _path; }
+ size_t size() const override { return _content_offset + _bytes.size(); }
+ bool closed() const override { return _closed; }
+ int64_t mtime() const override { return 0; }
+
+ std::vector<std::pair<size_t, size_t>> read_requests;
+ std::optional<size_t> short_read_offset;
+ std::optional<size_t> error_offset;
+
+protected:
+ Status read_at_impl(size_t offset, Slice result, size_t* bytes_read,
+ const io::IOContext*) override {
+ read_requests.emplace_back(offset, result.size);
+ if (error_offset == offset || offset < _content_offset) {
+ return Status::IOError("Injected BLOB read failure");
+ }
+ *bytes_read = std::min(result.size, size() - offset);
+ if (short_read_offset == offset && *bytes_read > 0) {
+ --*bytes_read;
+ }
+ if (*bytes_read > 0) {
+ std::memcpy(result.data, _bytes.data() + offset - _content_offset,
*bytes_read);
+ }
+ return Status::OK();
+ }
+
+private:
+ io::Path _path {"memory.blob"};
+ std::string _bytes;
+ size_t _content_offset;
+ bool _closed = false;
+};
+
+TEST(PaimonAppendBlobFileReaderTest, ReadsPaimon142WriterBytes) {
+ // Generated with Paimon 1.4.2 BlobFormatWriter for ["hello", NULL, empty,
00FF].
+ // Fixed bytes independently pin little-endian framing, CRC32 and
NULL/empty index deltas.
+ const std::string bytes = std::string(
+ "\xcf\x11\x4e\x58hello\x15\x00\x00\x00\x00\x00\x00\x00"
+ "\xc8\xf6\xa7\x51\xcf\x11\x4e\x58\x10\x00\x00\x00"
+ "\x00\x00\x00\x00\x53\x7f\xdf\x03\xcf\x11\x4e\x58"
+ "\x00\xff\x12\x00\x00\x00\x00\x00\x00\x00\xef\xc8"
+ "\x8a\x40\x2a\x2b\x22\x04\x04\x00\x00\x00\x01",
+ 64);
+ EXPECT_EQ(bytes, make_blob_file({"hello", std::nullopt, "",
std::string("\0\xff", 2)}));
+ auto file = std::make_shared<MemoryBlobFile>(bytes);
+ PaimonAppendBlobFileReader reader;
+ ASSERT_TRUE(reader.open(file, 4, nullptr).ok());
+
+ // Descriptor access reads only the footer and index, never record bytes.
+ ASSERT_EQ(file->read_requests.size(), 2);
+ EXPECT_EQ(file->read_requests[0], std::make_pair(size_t {59}, size_t {5}));
+ EXPECT_EQ(file->read_requests[1], std::make_pair(size_t {55}, size_t {4}));
+ std::optional<PaimonAppendBlobFileReader::ByteRange> range;
+ ASSERT_TRUE(reader.get_range(0, &range).ok());
+ ASSERT_TRUE(range.has_value());
+ EXPECT_EQ(range->offset, 4);
+ EXPECT_EQ(range->size, 5);
+ PODArray<char> payload;
+ ASSERT_TRUE(reader.read_payload(*range, &payload, nullptr).ok());
+ EXPECT_EQ(std::string(payload.data(), payload.size()), "hello");
+
+ ASSERT_TRUE(reader.get_range(1, &range).ok());
+ EXPECT_FALSE(range.has_value());
+ ASSERT_TRUE(reader.get_range(2, &range).ok());
+ ASSERT_TRUE(range.has_value());
+ EXPECT_EQ(range->offset, 25);
+ EXPECT_EQ(range->size, 0);
+ ASSERT_TRUE(reader.read_payload(*range, &payload, nullptr).ok());
+ EXPECT_TRUE(payload.empty());
+ ASSERT_TRUE(reader.get_range(3, &range).ok());
+ ASSERT_TRUE(range.has_value());
+ EXPECT_EQ(range->offset, 41);
+ EXPECT_EQ(range->size, 2);
+ ASSERT_TRUE(reader.read_payload(*range, &payload, nullptr).ok());
+ EXPECT_EQ(std::string(payload.data(), payload.size()),
std::string("\0\xff", 2));
+}
+
+TEST(PaimonAppendBlobFileReaderTest, BinaryPayloadsAndVarintLengthTransitions)
{
+ std::vector<std::optional<std::string>> values {std::nullopt, ""};
+ for (const size_t size : {47, 48, 49, 111, 112, 113, 127, 128, 129, 8175,
8176, 8177}) {
+ values.emplace_back(std::string(size, 'x'));
+ }
+ values.emplace_back(std::nullopt);
+ values.emplace_back("");
+ values.emplace_back("short");
+ std::string all_bytes;
+ for (int byte = 0; byte < 256; ++byte) {
+ all_bytes.push_back(static_cast<char>(byte));
+ }
+ values.emplace_back(all_bytes);
+ values.emplace_back("你好Doris🌍");
+ PaimonAppendBlobFileReader reader;
+
ASSERT_TRUE(reader.open(std::make_shared<MemoryBlobFile>(make_blob_file(values)),
+ static_cast<int64_t>(values.size()), nullptr)
+ .ok());
+ PODArray<char> payload;
+ int64_t record_offset = 0;
+ for (size_t row = 0; row < values.size(); ++row) {
+ SCOPED_TRACE(row);
+ std::optional<PaimonAppendBlobFileReader::ByteRange> range;
+ ASSERT_TRUE(reader.get_range(static_cast<int64_t>(row), &range).ok());
+ if (!values[row]) {
+ EXPECT_FALSE(range.has_value());
+ continue;
+ }
+ ASSERT_TRUE(range.has_value());
+ EXPECT_EQ(range->offset, record_offset + 4);
+ EXPECT_EQ(range->size, values[row]->size());
+ ASSERT_TRUE(reader.read_payload(*range, &payload, nullptr).ok());
+ EXPECT_EQ(std::string(payload.data(), payload.size()), *values[row]);
+ record_offset += static_cast<int64_t>(values[row]->size()) + 16;
+ }
+}
+
+TEST(PaimonAppendBlobFileReaderTest, EmptyAndAllNullFiles) {
+ for (const size_t row_count : {0, 4}) {
+ SCOPED_TRACE(row_count);
+ auto file = std::make_shared<MemoryBlobFile>(
+
make_blob_file(std::vector<std::optional<std::string>>(row_count)));
+ PaimonAppendBlobFileReader reader;
+ ASSERT_TRUE(reader.open(file, static_cast<int64_t>(row_count),
nullptr).ok());
+ for (size_t row = 0; row < row_count; ++row) {
+ std::optional<PaimonAppendBlobFileReader::ByteRange> range;
+ ASSERT_TRUE(reader.get_range(static_cast<int64_t>(row),
&range).ok());
+ EXPECT_FALSE(range.has_value());
+ }
+ EXPECT_EQ(file->read_requests.size(), 2);
+ }
+}
+
+TEST(PaimonAppendBlobFileReaderTest, ReopeningClearsPreviousIndex) {
+ PaimonAppendBlobFileReader reader;
+
ASSERT_TRUE(reader.open(std::make_shared<MemoryBlobFile>(make_blob_file({"old",
"", "end"})), 3,
+ nullptr)
+ .ok());
+
ASSERT_TRUE(reader.open(std::make_shared<MemoryBlobFile>(make_blob_file({"new"})),
1, nullptr)
+ .ok());
+ std::optional<PaimonAppendBlobFileReader::ByteRange> range;
+ EXPECT_TRUE(reader.get_range(1, &range).is<ErrorCode::CORRUPTION>());
+ ASSERT_TRUE(reader.get_range(0, &range).ok());
+ ASSERT_TRUE(range.has_value());
+ PODArray<char> payload;
+ ASSERT_TRUE(reader.read_payload(*range, &payload, nullptr).ok());
+ EXPECT_EQ(std::string(payload.data(), payload.size()), "new");
+}
+
+TEST(PaimonAppendBlobFileReaderTest, RejectsOutOfBoundsRows) {
+ PaimonAppendBlobFileReader reader;
+ ASSERT_TRUE(
+
reader.open(std::make_shared<MemoryBlobFile>(make_blob_file({"a"})), 1,
nullptr).ok());
+ for (const int64_t row : {int64_t {-1}, int64_t {1},
std::numeric_limits<int64_t>::max()}) {
+ std::optional<PaimonAppendBlobFileReader::ByteRange> range;
+ EXPECT_TRUE(reader.get_range(row, &range).is<ErrorCode::CORRUPTION>());
+ }
+}
+
+TEST(PaimonAppendBlobFileReaderTest, RejectsInvalidFileSizeAndRowCount) {
+ PaimonAppendBlobFileReader reader;
+ EXPECT_TRUE(reader.open(nullptr, 1, nullptr).is<ErrorCode::CORRUPTION>());
+ EXPECT_TRUE(reader.open(std::make_shared<MemoryBlobFile>("1234"), 0,
nullptr)
+ .is<ErrorCode::CORRUPTION>());
+
EXPECT_TRUE(reader.open(std::make_shared<MemoryBlobFile>(make_blob_file({"a"})),
-1, nullptr)
+ .is<ErrorCode::CORRUPTION>());
+}
+
+TEST(PaimonAppendBlobFileReaderTest, RejectsUnknownVersion) {
+ std::string bytes = make_blob_file({"a"});
+ bytes.back() = '\2';
+ PaimonAppendBlobFileReader reader;
+ const auto status = reader.open(std::make_shared<MemoryBlobFile>(bytes),
1, nullptr);
+ EXPECT_TRUE(status.is<ErrorCode::NOT_IMPLEMENTED_ERROR>()) << status;
+}
+
+TEST(PaimonAppendBlobFileReaderTest, RejectsInvalidIndexLength) {
+ for (const uint32_t index_size : {0U, 100U,
std::numeric_limits<uint32_t>::max()}) {
+ SCOPED_TRACE(index_size);
+ std::string bytes = make_blob_file({"a"});
+ bytes.resize(bytes.size() - 5);
+ blob_test::append_little_endian(&bytes, index_size, 4);
+ bytes.push_back('\1');
+ PaimonAppendBlobFileReader reader;
+ EXPECT_TRUE(reader.open(std::make_shared<MemoryBlobFile>(bytes), 1,
nullptr)
+ .is<ErrorCode::CORRUPTION>());
+ }
+}
+
+TEST(PaimonAppendBlobFileReaderTest, RejectsTruncatedAndOverflowingVarints) {
+ const std::vector<std::string> indexes {std::string(1, '\x80'),
std::string(9, '\x80') + '\x02',
+ std::string(10, '\x80')};
+ for (const auto& index : indexes) {
+ PaimonAppendBlobFileReader reader;
+ const auto status = reader.open(
+ std::make_shared<MemoryBlobFile>(finish_blob_file("", index)),
1, nullptr);
+ EXPECT_TRUE(status.is<ErrorCode::CORRUPTION>()) << status;
+ }
+}
+
+TEST(PaimonAppendBlobFileReaderTest, RejectsInvalidRecordLengths) {
+ for (const int64_t length : {-2, 0, 15, 17}) {
+ SCOPED_TRACE(length);
+ PaimonAppendBlobFileReader reader;
+ const auto status =
+ reader.open(std::make_shared<MemoryBlobFile>(finish_blob_file(
+ std::string(16, '\0'),
encode_record_lengths({length}))),
+ 1, nullptr);
+ EXPECT_TRUE(status.is<ErrorCode::CORRUPTION>()) << status;
+ }
+ // The second delta would overflow the signed record length when added to
the first.
+ const std::string index = encode_record_lengths({16}) +
+
encode_record_lengths({std::numeric_limits<int64_t>::max()});
+ PaimonAppendBlobFileReader reader;
+ EXPECT_TRUE(reader.open(std::make_shared<MemoryBlobFile>(
+ finish_blob_file(std::string(16, '\0'),
index)),
+ 2, nullptr)
+ .is<ErrorCode::CORRUPTION>());
+}
+
+TEST(PaimonAppendBlobFileReaderTest, RejectsManifestRowCountAndUnindexedData) {
+ const auto bytes = make_blob_file({"a", std::nullopt, ""});
+ for (const int64_t rows : {0, 2, 4}) {
+ PaimonAppendBlobFileReader reader;
+ EXPECT_TRUE(reader.open(std::make_shared<MemoryBlobFile>(bytes), rows,
nullptr)
+ .is<ErrorCode::CORRUPTION>());
+ }
+ PaimonAppendBlobFileReader reader;
+ EXPECT_TRUE(reader.open(std::make_shared<MemoryBlobFile>(finish_blob_file(
+ std::string(17, '\0'),
encode_record_lengths({16}))),
+ 1, nullptr)
+ .is<ErrorCode::CORRUPTION>());
+}
+
+TEST(PaimonAppendBlobFileReaderTest,
ValidatesMagicStoredLengthPayloadAndChecksum) {
+ // Corrupt one field at a time. Opening and descriptor access still
succeed: records
+ // are deliberately read and validated only when inline output is
requested.
+ for (const size_t corrupt_offset : {0, 9, 4, 20}) {
+ SCOPED_TRACE(corrupt_offset);
+ auto bytes = make_blob_file({"hello"});
+ bytes[corrupt_offset] ^= 1;
+ PaimonAppendBlobFileReader reader;
+ ASSERT_TRUE(reader.open(std::make_shared<MemoryBlobFile>(bytes), 1,
nullptr).ok());
+ std::optional<PaimonAppendBlobFileReader::ByteRange> range;
+ ASSERT_TRUE(reader.get_range(0, &range).ok());
+ ASSERT_TRUE(range.has_value());
+ PODArray<char> payload;
+ const auto status = reader.read_payload(*range, &payload, nullptr);
+ EXPECT_TRUE(status.is<ErrorCode::CORRUPTION>()) << status;
+ EXPECT_NE(status.to_string().find(corrupt_offset == 0 ||
corrupt_offset == 9 ? "framing"
+
: "checksum"),
+ std::string::npos);
+ }
+}
+
+TEST(PaimonAppendBlobFileReaderTest, DetectsShortFooterIndexAndRecordReads) {
+ const auto bytes = make_blob_file({"hello"});
+ for (const size_t offset : {bytes.size() - 5, bytes.size() - 6, size_t
{0}}) {
+ SCOPED_TRACE(offset);
+ auto file = std::make_shared<MemoryBlobFile>(bytes);
+ file->short_read_offset = offset;
+ PaimonAppendBlobFileReader reader;
+ auto status = reader.open(file, 1, nullptr);
+ if (offset == 0) {
+ ASSERT_TRUE(status.ok());
+ std::optional<PaimonAppendBlobFileReader::ByteRange> range;
+ ASSERT_TRUE(reader.get_range(0, &range).ok());
+ ASSERT_TRUE(range.has_value());
+ PODArray<char> payload;
+ status = reader.read_payload(*range, &payload, nullptr);
+ }
+ EXPECT_TRUE(status.is<ErrorCode::CORRUPTION>()) << status;
+ EXPECT_NE(status.to_string().find("Truncated BLOB file"),
std::string::npos);
Review Comment:
[P2] Match the record-short-read error in the final iteration
When `offset == 0`, `open()` succeeds and `read_payload()` reaches
`read_record()`. The fake shortens that record read, which returns
`Corruption("Short read of Paimon BLOB record")`, so this unconditional search
for `"Truncated BLOB file"` fails every time. That message is only used by the
footer/index reader. Assert the corresponding record error for this iteration,
or check the error category without requiring the footer message.
--
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]