Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 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
0ee5d1a
fix(blob): preserve video row metadata and account for index memory
XiaoHongbo-Hope Dec 6, 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``.
Use ``VideoFrameDescriptor::Deserialize()`` for the frame index and MP4 moov range.
Open the encoded video with ``Blob::FromPath()`` using the URI, offset and length
from ``Payload()``.

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
72 changes: 72 additions & 0 deletions include/paimon/data/video_frame_descriptor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* 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 <memory>
#include <string>

#include "paimon/data/blob_descriptor.h"
#include "paimon/visibility.h"

namespace paimon {

/// Wire representation of a frame in an encoded video. The moov range is relative to its payload.
class PAIMON_EXPORT VideoFrameDescriptor {
public:
static Result<std::unique_ptr<VideoFrameDescriptor>> Create(const std::string& uri,
int64_t offset, int64_t length,
int64_t frame_index,
int64_t moov_offset,
int64_t moov_length);

static bool HasMagic(const char* buffer, uint64_t size);
static Result<std::unique_ptr<VideoFrameDescriptor>> Deserialize(const char* buffer,
uint64_t size);

PAIMON_UNIQUE_PTR<Bytes> Serialize(const std::shared_ptr<MemoryPool>& pool) const;

const BlobDescriptor& Payload() const {
return *payload_;
}

int64_t FrameIndex() const {
return frame_index_;
}

int64_t MoovOffset() const {
return moov_offset_;
}

int64_t MoovLength() const {
return moov_length_;
}

private:
VideoFrameDescriptor(std::unique_ptr<BlobDescriptor> payload, int64_t frame_index,
int64_t moov_offset, int64_t moov_length);

std::unique_ptr<BlobDescriptor> payload_;
int64_t frame_index_;
int64_t moov_offset_;
int64_t moov_length_;
};

} // namespace paimon
2 changes: 2 additions & 0 deletions include/paimon/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,8 @@ struct PAIMON_EXPORT Options {
/// serialized BlobViewStruct bytes inline in data files and resolve from upstream tables at
/// read time. No default value.
static const char BLOB_VIEW_FIELD[];
/// Scalar BLOB columns that store video frame descriptors.
static const char VIDEO_FRAME_FIELD[];
/// "blob-view.resolve.enabled" - Whether to resolve blob-view-field values from upstream
/// tables at read time. Set to false to preserve serialized BlobViewStruct bytes when
/// forwarding blob view values to another blob-view table. Default value is "true".
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
1 change: 1 addition & 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
17 changes: 16 additions & 1 deletion src/paimon/common/data/blob_descriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "fmt/format.h"
#include "paimon/common/io/memory_segment_output_stream.h"
#include "paimon/common/memory/memory_segment_utils.h"
#include "paimon/data/video_frame_descriptor.h"
#include "paimon/io/byte_array_input_stream.h"
#include "paimon/io/byte_order.h"
#include "paimon/io/data_input_stream.h"
Expand Down Expand Up @@ -73,6 +74,13 @@ 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 VideoFrameDescriptor::Deserialize");
}
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 +99,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 +114,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
17 changes: 15 additions & 2 deletions src/paimon/common/data/blob_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "paimon/common/utils/checked_cast.h"
#include "paimon/common/utils/string_utils.h"
#include "paimon/data/blob_descriptor.h"
#include "paimon/data/video_frame_descriptor.h"
namespace arrow {
class Array;
}
Expand Down Expand Up @@ -194,8 +195,12 @@ bool BlobUtils::IsBlobMetadata(const std::shared_ptr<const arrow::KeyValueMetada
return extension_name.ValueUnsafe() == BlobDefs::kExtensionTypeValue;
}

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 +211,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 +246,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
5 changes: 5 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,10 @@ 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 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
111 changes: 111 additions & 0 deletions src/paimon/common/data/video_frame_descriptor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* 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 "paimon/data/video_frame_descriptor.h"

#include <algorithm>
#include <limits>
#include <string_view>
#include <utility>

#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"
#include "paimon/io/data_input_stream.h"

namespace paimon {
namespace {

constexpr int8_t kVersion = 1;
constexpr std::string_view kMagic = "MRFOEDIV"; // 0x564944454F46524D in little endian
constexpr uint64_t kHeaderSize = sizeof(kVersion) + kMagic.size();
constexpr uint64_t kFixedSize = kHeaderSize + sizeof(int32_t) + 5 * sizeof(int64_t);

} // namespace

VideoFrameDescriptor::VideoFrameDescriptor(std::unique_ptr<BlobDescriptor> payload,
int64_t frame_index, int64_t moov_offset,
int64_t moov_length)
: payload_(std::move(payload)),
frame_index_(frame_index),
moov_offset_(moov_offset),
moov_length_(moov_length) {}

Result<std::unique_ptr<VideoFrameDescriptor>> VideoFrameDescriptor::Create(
const std::string& uri, int64_t offset, int64_t length, int64_t frame_index,
int64_t moov_offset, int64_t moov_length) {
if (frame_index < 0 || moov_offset < 0 || moov_length < 0 ||
uri.size() > std::numeric_limits<int32_t>::max() ||
(moov_length == 0 ? moov_offset != 0
: moov_offset > length || moov_length > length - moov_offset)) {
return Status::Invalid("invalid video frame descriptor range");
}
PAIMON_ASSIGN_OR_RAISE(std::unique_ptr<BlobDescriptor> payload,
BlobDescriptor::Create(uri, offset, length));
return std::unique_ptr<VideoFrameDescriptor>(
new VideoFrameDescriptor(std::move(payload), frame_index, moov_offset, moov_length));
}

bool VideoFrameDescriptor::HasMagic(const char* buffer, uint64_t size) {
return buffer != nullptr && size >= kHeaderSize && buffer[0] == kVersion &&
std::string_view(buffer + sizeof(kVersion), kMagic.size()) == kMagic;
}

Result<std::unique_ptr<VideoFrameDescriptor>> VideoFrameDescriptor::Deserialize(const char* buffer,
uint64_t size) {
if (size < kFixedSize || !HasMagic(buffer, size)) {
return Status::Invalid("invalid or unsupported video frame descriptor header");
}
DataInputStream input(std::make_shared<ByteArrayInputStream>(buffer, size));
input.SetOrder(ByteOrder::PAIMON_LITTLE_ENDIAN);
PAIMON_RETURN_NOT_OK(input.Seek(kHeaderSize));
PAIMON_ASSIGN_OR_RAISE(int32_t uri_length, input.ReadValue<int32_t>());
if (uri_length < 0 || static_cast<uint64_t>(uri_length) != size - kFixedSize) {
return Status::Invalid("invalid video frame descriptor length");
}
std::string uri(uri_length, '\0');
PAIMON_RETURN_NOT_OK(input.Read(uri.data(), uri_length));
PAIMON_ASSIGN_OR_RAISE(int64_t offset, input.ReadValue<int64_t>());
PAIMON_ASSIGN_OR_RAISE(int64_t length, input.ReadValue<int64_t>());
PAIMON_ASSIGN_OR_RAISE(int64_t frame_index, input.ReadValue<int64_t>());
PAIMON_ASSIGN_OR_RAISE(int64_t moov_offset, input.ReadValue<int64_t>());
PAIMON_ASSIGN_OR_RAISE(int64_t moov_length, input.ReadValue<int64_t>());
return Create(uri, offset, length, frame_index, moov_offset, moov_length);
}

PAIMON_UNIQUE_PTR<Bytes> VideoFrameDescriptor::Serialize(
const std::shared_ptr<MemoryPool>& pool) const {
const std::string& uri = payload_->Uri();
const int32_t segment_size = std::min<uint64_t>(
kFixedSize + uri.size(), MemorySegmentOutputStream::DEFAULT_SEGMENT_SIZE);
MemorySegmentOutputStream output(segment_size, pool);
output.SetOrder(ByteOrder::PAIMON_LITTLE_ENDIAN);
output.WriteValue<int8_t>(kVersion);
output.Write(kMagic.data(), kMagic.size());
output.WriteValue<int32_t>(uri.size());
output.Write(uri.data(), uri.size());
output.WriteValue<int64_t>(payload_->Offset());
output.WriteValue<int64_t>(payload_->Length());
output.WriteValue<int64_t>(frame_index_);
output.WriteValue<int64_t>(moov_offset_);
output.WriteValue<int64_t>(moov_length_);
return MemorySegmentUtils::CopyToBytes(output.Segments(), 0, output.CurrentSize(), pool.get());
}

} // namespace paimon
Loading
Loading