Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
e215adb
feat(blob): read Paimon video files
XiaoHongbo-Hope Nov 26, 2026
b4bbe8d
fix(blob): avoid copying optional video read requests
XiaoHongbo-Hope Nov 26, 2026
d90c80b
fix(blob): preserve video frame identity and descriptor ABI
XiaoHongbo-Hope Nov 28, 2026
a231733
fix(blob): bound video index memory before decoding
XiaoHongbo-Hope Nov 28, 2026
c722c4c
fix(blob): bound video row selection and clarify legacy layout errors
XiaoHongbo-Hope Nov 28, 2026
2d701f3
fix(blob): reject ambiguous v1 video layouts
XiaoHongbo-Hope Nov 28, 2026
2a7792d
docs(blob): shorten video read guidance
XiaoHongbo-Hope Nov 28, 2026
7b5f393
test(blob): simplify legacy video layout coverage
XiaoHongbo-Hope Nov 28, 2026
7bd6898
fix(blob): preserve video frame descriptors in blob views
XiaoHongbo-Hope Nov 29, 2026
697f1cd
fix(blob): validate video layouts with one bounded index read
XiaoHongbo-Hope Dec 1, 2026
ace18f2
perf(blob): open data evolution blob files by row range
XiaoHongbo-Hope Dec 1, 2026
d71e30b
fix(blob): preserve video frame locations and enforce table declarations
XiaoHongbo-Hope Dec 1, 2026
abbdbb8
fix(blob): use a C++17 capture for lazy file readers
XiaoHongbo-Hope Dec 1, 2026
4f7f408
fix(blob): preserve frame references across stream wrappers and inlin…
XiaoHongbo-Hope Dec 1, 2026
1c19c12
fix(blob): reject ambiguous four-index video packs
XiaoHongbo-Hope Dec 1, 2026
7e5cb7a
fix(blob): read the moov-based video layout directly
XiaoHongbo-Hope Dec 2, 2026
37f9deb
style(blob): satisfy clang-tidy in varint decoding
XiaoHongbo-Hope Dec 2, 2026
35d2593
fix(blob): handle video-only deltas and release video reader resources
XiaoHongbo-Hope Dec 2, 2026
b4848ea
fix(blob): align video delta rows and preserve fallback metadata
XiaoHongbo-Hope Dec 3, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions docs/source/user_guide/read.rst
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,25 @@ Implementation Guidance
- Do not assume identical overflow semantics across C++ and Java; tests should validate acceptable ranges and nullability.
- For timestamp handling, consider precision/range constraints in C++ when interoperating with Java-produced data splits.

Reading Video Columns
---------------------

Paimon C++ reads scalar BLOB columns using the same ``moov``-based v1 layout
as Java (29-byte footer). The estimated peak memory for indexes is limited to 64 MiB.

Reimport older ``.video`` files with a Java reader for the original layout and a
current Java writer. Regenerate stored frame descriptors and verify row counts,
frame ordinals and row alignment before switching to the new files.

Non-null rows return frame descriptors even with ``blob-as-descriptor=false``.
Open them with ``Blob::FromDescriptor()``. Use ``FrameIndex()`` for the zero-based
frame ordinal, ``NewInputStream()`` for the encoded payload, and ``MoovOffset()``
and ``MoovLength()`` for the optional MP4 ``moov`` range.

Use Java Paimon to write video columns. C++ rejects writes to
``video-frame-field`` columns and rejects frame descriptors in ordinary BLOB
writes.

.. _data-evolution-deletion-vectors:

Deletion Vectors on Data-Evolution Tables
Expand Down
14 changes: 14 additions & 0 deletions include/paimon/data/blob.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,22 @@ class PAIMON_EXPORT Blob {
/// Gets the URI of the blob.
const std::string& Uri() const;

/// Whether this blob refers to one logical frame in an encoded video payload.
bool IsVideoFrame() const;

/// Zero-based frame ordinal, or -1 for a regular blob.
int64_t FrameIndex() const;

@zjw1111 zjw1111 Dec 4, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you expose VideoFrameDescriptor under include/paimon/data/ and remove the video-specific accessors from Blob? Video callers can parse the frame descriptor directly and open its Payload() through the existing Blob API. Blob::FromDescriptor() and ToDescriptor() can then work with BlobDescriptor alone.


/// Offset and length of the MP4 moov box relative to the encoded video payload.
/// Both values are 0 if absent.
int64_t MoovOffset() const;
int64_t MoovLength() const;

/// Creates an input stream for reading the blob data.
///
/// For a video frame descriptor, the stream contains the encoded video payload.
/// Use `FrameIndex()` to locate the logical frame when decoding the payload.
///
/// @param fs The file system to use for reading.
/// @return A result containing the input stream or an error.
Result<std::unique_ptr<InputStream>> NewInputStream(
Expand Down
2 changes: 2 additions & 0 deletions include/paimon/io/buffered_input_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ class PAIMON_EXPORT BufferedInputStream : public InputStream {
static constexpr int64_t DEFAULT_BUFFER_SIZE = 8192;

private:
friend class FileOffsetInputStream;

/// Fill the internal buffer from the underlying stream.
Status Fill();

Expand Down
41 changes: 41 additions & 0 deletions include/paimon/io/file_offset_input_stream.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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.
*/

#pragma once

#include <cstdint>

#include "paimon/fs/file_system.h"

namespace paimon {

/// A stream whose position zero can be at an offset in the file identified by GetUri().
/// Wrappers that preserve positions forward the backing stream's file offset.
class PAIMON_EXPORT FileOffsetInputStream : public InputStream {
public:
~FileOffsetInputStream() override = default;

/// Returns the nonnegative backing-file offset of position zero.
virtual Result<int64_t> GetFileOffset() const = 0;

/// Ordinary whole-file streams start at offset zero.
static Result<int64_t> GetFileOffset(const InputStream& stream);
};

} // namespace paimon
4 changes: 4 additions & 0 deletions src/paimon/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ set(PAIMON_COMMON_SRCS
common/data/blob_descriptor.cpp
common/data/blob_view.cpp
common/data/blob_view_struct.cpp
common/data/video_frame_descriptor.cpp
common/data/blob_utils.cpp
common/data/columnar/columnar_array.cpp
common/data/columnar/columnar_map.cpp
Expand Down Expand Up @@ -1144,6 +1145,8 @@ if(PAIMON_BUILD_TESTS)
if(PAIMON_ENABLE_OSS OR PAIMON_ENABLE_S3)
list(APPEND PAIMON_OBJECT_STORE_FS_TEST_SOURCES
common/fs/object_store_file_system_test.cpp)
set(PAIMON_OBJECT_STORE_FS_TEST_LINK_LIBS
${PAIMON_BLOB_FILE_FORMAT_STATIC_LINK_LIBS})
endif()

add_paimon_test(fs_test
Expand All @@ -1158,6 +1161,7 @@ if(PAIMON_BUILD_TESTS)
paimon_shared
${PAIMON_LOCAL_FILE_SYSTEM_STATIC_LINK_LIBS}
${PAIMON_JINDO_FS_TEST_LINK_LIBS}
${PAIMON_OBJECT_STORE_FS_TEST_LINK_LIBS}
test_utils_static
${GTEST_LINK_TOOLCHAIN}
EXTRA_INCLUDES
Expand Down
35 changes: 32 additions & 3 deletions src/paimon/common/data/blob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include "arrow/c/bridge.h"
#include "paimon/common/data/blob_utils.h"
#include "paimon/common/data/video_frame_descriptor.h"
#include "paimon/common/io/offset_input_stream.h"
#include "paimon/common/utils/arrow/status_utils.h"
#include "paimon/common/utils/path_util.h"
Expand All @@ -40,21 +41,28 @@ class Blob::Impl {
public:
explicit Impl(std::unique_ptr<BlobDescriptor>&& descriptor)
: descriptor_(std::move(descriptor)) {}
explicit Impl(std::unique_ptr<VideoFrameDescriptor>&& video_frame)
: video_frame_(std::move(video_frame)) {}

PAIMON_UNIQUE_PTR<Bytes> SerializeDescriptor(const std::shared_ptr<MemoryPool>& pool) const {
return descriptor_->Serialize(pool);
return video_frame_ ? video_frame_->Serialize(pool) : descriptor_->Serialize(pool);
}

const BlobDescriptor* GetDescriptor() const {
return descriptor_.get();
return video_frame_ ? &video_frame_->Payload() : descriptor_.get();
}

const std::string& Uri() const {
return descriptor_->Uri();
return GetDescriptor()->Uri();
}

const VideoFrameDescriptor* VideoFrame() const {
return video_frame_.get();
}

private:
std::unique_ptr<BlobDescriptor> descriptor_;
std::unique_ptr<VideoFrameDescriptor> video_frame_;
};

Result<std::unique_ptr<Blob>> Blob::FromPath(const std::string& path) {
Expand All @@ -74,6 +82,11 @@ Blob::Blob(std::unique_ptr<Impl>&& impl) : impl_(std::move(impl)) {}
Blob::~Blob() = default;

Result<std::unique_ptr<Blob>> Blob::FromDescriptor(const char* buffer, uint64_t length) {
if (VideoFrameDescriptor::HasMagic(buffer, length)) {
PAIMON_ASSIGN_OR_RAISE(std::unique_ptr<VideoFrameDescriptor> video_frame,
VideoFrameDescriptor::Deserialize(buffer, length));
return std::unique_ptr<Blob>(new Blob(std::make_unique<Impl>(std::move(video_frame))));
}
PAIMON_ASSIGN_OR_RAISE(std::unique_ptr<BlobDescriptor> descriptor,
BlobDescriptor::Deserialize(buffer, length));

Expand All @@ -89,6 +102,22 @@ const std::string& Blob::Uri() const {
return impl_->Uri();
}

bool Blob::IsVideoFrame() const {
return impl_->VideoFrame() != nullptr;
}

int64_t Blob::FrameIndex() const {
return impl_->VideoFrame() ? impl_->VideoFrame()->FrameIndex() : -1;
}

int64_t Blob::MoovOffset() const {
return impl_->VideoFrame() ? impl_->VideoFrame()->MoovOffset() : 0;
}

int64_t Blob::MoovLength() const {
return impl_->VideoFrame() ? impl_->VideoFrame()->MoovLength() : 0;
}

Result<std::unique_ptr<InputStream>> Blob::NewInputStream(
const std::shared_ptr<FileSystem>& fs) const {
if (fs == nullptr) {
Expand Down
3 changes: 3 additions & 0 deletions src/paimon/common/data/blob_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ class BlobDefs {
/// Metadata value identifying a Paimon Blob extension type field.
static constexpr char kExtensionTypeValue[] = "paimon.type.blob";

/// Java Paimon table option naming scalar BLOB fields stored as video frames.
static constexpr char kVideoFrameFieldOption[] = "video-frame-field";
Comment thread
SteNicholas marked this conversation as resolved.
Resolved

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the definition and parsing of the "video-frame-field" parameter be placed in defs.h/core_options.h?


/// A bin_length value of -1 in the index indicates a null blob entry.
static constexpr int64_t kNullBinLength = -1;
/// A bin_length value of -2 in the index indicates a placeholder blob entry, written by
Expand Down
16 changes: 15 additions & 1 deletion src/paimon/common/data/blob_descriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <utility>

#include "fmt/format.h"
#include "paimon/common/data/video_frame_descriptor.h"
#include "paimon/common/io/memory_segment_output_stream.h"
#include "paimon/common/memory/memory_segment_utils.h"
#include "paimon/io/byte_array_input_stream.h"
Expand Down Expand Up @@ -73,6 +74,12 @@ PAIMON_UNIQUE_PTR<Bytes> BlobDescriptor::Serialize(const std::shared_ptr<MemoryP

Result<std::unique_ptr<BlobDescriptor>> BlobDescriptor::Deserialize(const char* buffer,
uint64_t size) {
if (buffer == nullptr || size == 0) {
return Status::Invalid("empty blob descriptor");
}
if (VideoFrameDescriptor::HasMagic(buffer, size)) {
return Status::Invalid("video frame descriptors must be opened with Blob::FromDescriptor");
}
auto input_stream = std::make_shared<ByteArrayInputStream>(buffer, size);
DataInputStream in(std::move(input_stream));
in.SetOrder(ByteOrder::PAIMON_LITTLE_ENDIAN);
Expand All @@ -91,6 +98,13 @@ Result<std::unique_ptr<BlobDescriptor>> BlobDescriptor::Deserialize(const char*
}
}
PAIMON_ASSIGN_OR_RAISE(int32_t uri_length, in.ReadValue<int32_t>());
PAIMON_ASSIGN_OR_RAISE(int64_t uri_start, in.GetPos());
constexpr uint64_t kTailSize = 2 * sizeof(int64_t);
const uint64_t remaining = size - uri_start;
if (uri_length < 0 || remaining < kTailSize ||
static_cast<uint64_t>(uri_length) > remaining - kTailSize) {
return Status::Invalid("invalid blob descriptor length");
}
std::string uri(uri_length, '\0');
PAIMON_RETURN_NOT_OK(in.Read(uri.data(), uri.size()));
PAIMON_ASSIGN_OR_RAISE(int64_t offset, in.ReadValue<int64_t>());
Expand All @@ -99,7 +113,7 @@ Result<std::unique_ptr<BlobDescriptor>> BlobDescriptor::Deserialize(const char*
}

Result<bool> BlobDescriptor::IsBlobDescriptor(const char* buffer, uint64_t size) {
if (size < kMinDescriptorLength) {
if (buffer == nullptr || size < kMinDescriptorLength) {
return false;
}
auto input_stream = std::make_shared<ByteArrayInputStream>(buffer, size);
Expand Down
32 changes: 30 additions & 2 deletions src/paimon/common/data/blob_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "fmt/format.h"
#include "paimon/common/data/blob_defs.h"
#include "paimon/common/data/blob_view_struct.h"
#include "paimon/common/data/video_frame_descriptor.h"
#include "paimon/common/types/data_field.h"
#include "paimon/common/utils/arrow/status_utils.h"
#include "paimon/common/utils/checked_cast.h"
Expand Down Expand Up @@ -194,8 +195,27 @@ bool BlobUtils::IsBlobMetadata(const std::shared_ptr<const arrow::KeyValueMetada
return extension_name.ValueUnsafe() == BlobDefs::kExtensionTypeValue;
}

std::vector<std::string> BlobUtils::GetVideoFrameFields(
const std::map<std::string, std::string>& options) {
auto it = options.find(BlobDefs::kVideoFrameFieldOption);
if (it == options.end()) {
return {};
}
auto names = StringUtils::Split(it->second, ",");
for (auto& name : names) {
StringUtils::Trim(&name);
}
std::set<std::string> fields(names.begin(), names.end());
fields.erase("");
return {fields.begin(), fields.end()};
}

bool BlobUtils::IsVideoFile(const std::string& file_name) {
return StringUtils::EndsWith(file_name, ".video");
}

bool BlobUtils::IsBlobFile(const std::string& file_name) {
return StringUtils::EndsWith(file_name, ".blob");
return StringUtils::EndsWith(file_name, ".blob") || IsVideoFile(file_name);
Comment thread
SteNicholas marked this conversation as resolved.
Resolved
}

std::shared_ptr<arrow::Field> BlobUtils::ToArrowField(
Expand All @@ -206,6 +226,14 @@ std::shared_ptr<arrow::Field> BlobUtils::ToArrowField(
std::make_shared<arrow::KeyValueMetadata>(metadata));
}

Result<bool> BlobUtils::IsBlobReference(std::string_view bytes) {
if (VideoFrameDescriptor::HasMagic(bytes.data(), bytes.size())) {
PAIMON_RETURN_NOT_OK(VideoFrameDescriptor::Deserialize(bytes.data(), bytes.size()));
return true;
}
return BlobDescriptor::IsBlobDescriptor(bytes.data(), bytes.size());
}

Status BlobUtils::ValidateBlobInlineFields(const std::shared_ptr<arrow::StructArray>& struct_array,
const std::set<std::string>& field_names,
const std::string& config_label) {
Expand Down Expand Up @@ -233,7 +261,7 @@ Status BlobUtils::ValidateBlobInlineFields(const std::shared_ptr<arrow::StructAr
}
auto value = binary_array->GetView(row);
Result<bool> valid = is_descriptor
? BlobDescriptor::IsBlobDescriptor(value.data(), value.size())
? IsBlobReference(value)
: BlobViewStruct::IsBlobViewStruct(value.data(), value.size());
PAIMON_ASSIGN_OR_RAISE(bool is_valid, std::move(valid));
if (!is_valid) {
Expand Down
7 changes: 7 additions & 0 deletions src/paimon/common/data/blob_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
#pragma once

#include <cstdint>
#include <map>
#include <memory>
#include <set>
#include <string>
#include <string_view>
#include <unordered_map>
#include <vector>

Expand Down Expand Up @@ -93,7 +95,12 @@ class PAIMON_EXPORT BlobUtils {
/// BOOLEAN, TINYINT, SMALLINT, INT, BIGINT, DATE, DECIMAL, CHAR/VARCHAR and BINARY/VARBINARY.
static bool IsSupportedMapBlobKeyType(const arrow::DataType& key_type);
static bool IsBlobMetadata(const std::shared_ptr<const arrow::KeyValueMetadata>& metadata);
static std::vector<std::string> GetVideoFrameFields(
const std::map<std::string, std::string>& options);

static bool IsVideoFile(const std::string& file_name);
static bool IsBlobFile(const std::string& file_name);
static Result<bool> IsBlobReference(std::string_view bytes);

static std::shared_ptr<arrow::Field> ToArrowField(
const std::string& field_name, bool nullable = false,
Expand Down
Loading
Loading