Repository navigation
feat(blob): read Paimon video files #601
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
XiaoHongbo-Hope
wants to merge
20
commits into
apache:main
Choose a base branch
from
XiaoHongbo-Hope:codex/video-read-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,638
−155
Open
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 b4bbe8d
fix(blob): avoid copying optional video read requests
XiaoHongbo-Hope d90c80b
fix(blob): preserve video frame identity and descriptor ABI
XiaoHongbo-Hope a231733
fix(blob): bound video index memory before decoding
XiaoHongbo-Hope c722c4c
fix(blob): bound video row selection and clarify legacy layout errors
XiaoHongbo-Hope 2d701f3
fix(blob): reject ambiguous v1 video layouts
XiaoHongbo-Hope 2a7792d
docs(blob): shorten video read guidance
XiaoHongbo-Hope 7b5f393
test(blob): simplify legacy video layout coverage
XiaoHongbo-Hope 7bd6898
fix(blob): preserve video frame descriptors in blob views
XiaoHongbo-Hope 697f1cd
fix(blob): validate video layouts with one bounded index read
XiaoHongbo-Hope ace18f2
perf(blob): open data evolution blob files by row range
XiaoHongbo-Hope d71e30b
fix(blob): preserve video frame locations and enforce table declarations
XiaoHongbo-Hope abbdbb8
fix(blob): use a C++17 capture for lazy file readers
XiaoHongbo-Hope 4f7f408
fix(blob): preserve frame references across stream wrappers and inlin…
XiaoHongbo-Hope 1c19c12
fix(blob): reject ambiguous four-index video packs
XiaoHongbo-Hope 7e5cb7a
fix(blob): read the moov-based video layout directly
XiaoHongbo-Hope 37f9deb
style(blob): satisfy clang-tidy in varint decoding
XiaoHongbo-Hope 35d2593
fix(blob): handle video-only deltas and release video reader resources
XiaoHongbo-Hope b4848ea
fix(blob): align video delta rows and preserve fallback metadata
XiaoHongbo-Hope 0ee5d1a
fix(blob): preserve video row metadata and account for index memory
XiaoHongbo-Hope File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.