-
Notifications
You must be signed in to change notification settings - Fork 251
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
[C++] Scan Node reads multiple files #300
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
b02e062
add merge vectors
eddyxu cad48cb
merge mulitple
eddyxu 697b880
add test
eddyxu 7b818de
functional merge
eddyxu d2f28eb
allow scanner node to take mulitple files
eddyxu 345a7a3
clean up
eddyxu 7855087
simplify
eddyxu 93933f1
more docs
eddyxu e6e6b5e
parallel read
eddyxu 807ef49
clean format
eddyxu 0c3fbae
better comments
eddyxu 49302c8
remove old Scan::Make interface
eddyxu a8311ad
remove unnedesary wait
eddyxu bd6cc38
move local copy of file reader
eddyxu 31c36be
move
eddyxu 6f70176
ref to future
eddyxu 1b8cc41
ref
eddyxu c293d7a
test
eddyxu ad123fe
set more cpu
eddyxu 3a100cb
do not set cpu
eddyxu 7a9154c
keep minimal thread counts
eddyxu 8d40c9b
cleanup
eddyxu 0075140
add test for reading several files
eddyxu 283adf9
simply test dont move
eddyxu 638523e
address comments
eddyxu 0d61063
use checkout GHA v3
eddyxu 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 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 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 |
---|---|---|
|
@@ -22,12 +22,15 @@ | |
#include <fmt/ranges.h> | ||
|
||
#include <concepts> | ||
#include <string> | ||
#include <range/v3/action.hpp> | ||
#include <range/v3/view.hpp> | ||
#include <vector> | ||
|
||
#include "lance/arrow/file_lance.h" | ||
#include "lance/arrow/type.h" | ||
|
||
namespace views = ranges::views; | ||
|
||
namespace lance::arrow { | ||
|
||
::arrow::Result<std::shared_ptr<::arrow::RecordBatch>> MergeRecordBatches( | ||
|
@@ -40,6 +43,25 @@ ::arrow::Result<std::shared_ptr<::arrow::RecordBatch>> MergeRecordBatches( | |
return ::arrow::RecordBatch::FromStructArray(struct_arr); | ||
} | ||
|
||
::arrow::Result<std::shared_ptr<::arrow::RecordBatch>> MergeRecordBatches( | ||
const std::vector<std::shared_ptr<::arrow::RecordBatch>>& batches, ::arrow::MemoryPool* pool) { | ||
if (batches.empty()) { | ||
return nullptr; | ||
} | ||
auto batch = batches[0]; | ||
for (auto& b : batches | views::drop(1)) { | ||
if (b->num_rows() != batch->num_rows()) { | ||
return ::arrow::Status::Invalid( | ||
"MergeRecordBatches: attempt to merge batches with different length: ", | ||
b->num_rows(), | ||
" != ", | ||
batch->num_rows()); | ||
} | ||
ARROW_ASSIGN_OR_RAISE(batch, MergeRecordBatches(batch, b, pool)); | ||
} | ||
return batch; | ||
} | ||
|
||
::arrow::Result<std::shared_ptr<::arrow::Array>> MergeListArrays( | ||
const std::shared_ptr<::arrow::Array>& lhs, | ||
const std::shared_ptr<::arrow::Array>& rhs, | ||
|
@@ -97,18 +119,17 @@ ::arrow::Result<std::shared_ptr<::arrow::StructArray>> MergeStructArrays( | |
arrays.emplace_back(left_arr); | ||
} | ||
|
||
for (auto& field : rhs->struct_type()->fields()) { | ||
auto& name = field->name(); | ||
if (lhs->GetFieldByName(name)) { | ||
// We've seen each other before | ||
continue; | ||
} | ||
for (auto name : | ||
rhs->struct_type()->fields() // | ||
| views::filter([&lhs](auto& f) { return !lhs->GetFieldByName(f->name()); }) // | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how do you feel about functional C++? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i wish it is simpler like rust. It simplifies a few for for loops, but not all , 😮💨 |
||
| views::transform([](auto& f) { return f->name(); })) { | ||
names.emplace_back(name); | ||
arrays.emplace_back(rhs->GetFieldByName(name)); | ||
} | ||
return ::arrow::StructArray::Make(arrays, names); | ||
} | ||
|
||
/// Concept of a class that has ".fields()" method. | ||
template <typename T> | ||
concept HasFields = (std::same_as<T, ::arrow::Schema> || std::same_as<T, ::arrow::StructType>); | ||
|
||
|
@@ -129,12 +150,11 @@ ::arrow::Result<std::vector<std::shared_ptr<::arrow::Field>>> MergeFieldWithChil | |
fields.emplace_back(merged); | ||
} | ||
} | ||
for (const auto& field : rhs.fields()) { | ||
auto left_field = lhs.GetFieldByName(field->name()); | ||
if (!left_field) { | ||
fields.emplace_back(field); | ||
} | ||
} | ||
ranges::actions::insert( | ||
fields, | ||
std::end(fields), // | ||
rhs.fields() // | ||
| views::filter([&lhs](auto& f) { return !lhs.GetFieldByName(f->name()); })); | ||
return fields; | ||
}; | ||
|
||
|
This file contains 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 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 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 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 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 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this require that all RecordBatches being merged are of the same length? if so, should it be checked here or in the caller or somewhere else altogether?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good �point. Added a check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It checks the length deep down the stack https://github.com/eto-ai/lance/blob/a6e788c37ea41f37cf0c5b993e041f3b262dafa6/cpp/src/lance/arrow/utils.cc#L69-L71
It is nice to raise here with clear context for sure.