-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Arrow] Move
ArrowUtil
to its own file (#13990)
Nothing major, this is just a chore. For probably over 80% of our classes we have them live in their own files, when I see `ArrowUtil` I would like to automatically navigate to the correct file, the current structure breaks my path assumption.
- Loading branch information
Showing
13 changed files
with
101 additions
and
68 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#include "duckdb/common/arrow/arrow_util.hpp" | ||
#include "duckdb/common/arrow/arrow_appender.hpp" | ||
#include "duckdb/common/types/data_chunk.hpp" | ||
|
||
namespace duckdb { | ||
|
||
bool ArrowUtil::TryFetchChunk(ChunkScanState &scan_state, ClientProperties options, idx_t batch_size, ArrowArray *out, | ||
idx_t &count, ErrorData &error) { | ||
count = 0; | ||
ArrowAppender appender(scan_state.Types(), batch_size, std::move(options)); | ||
auto remaining_tuples_in_chunk = scan_state.RemainingInChunk(); | ||
if (remaining_tuples_in_chunk) { | ||
// We start by scanning the non-finished current chunk | ||
idx_t cur_consumption = MinValue(remaining_tuples_in_chunk, batch_size); | ||
count += cur_consumption; | ||
auto ¤t_chunk = scan_state.CurrentChunk(); | ||
appender.Append(current_chunk, scan_state.CurrentOffset(), scan_state.CurrentOffset() + cur_consumption, | ||
current_chunk.size()); | ||
scan_state.IncreaseOffset(cur_consumption); | ||
} | ||
while (count < batch_size) { | ||
if (!scan_state.LoadNextChunk(error)) { | ||
if (scan_state.HasError()) { | ||
error = scan_state.GetError(); | ||
} | ||
return false; | ||
} | ||
if (scan_state.ChunkIsEmpty()) { | ||
// The scan was successful, but an empty chunk was returned | ||
break; | ||
} | ||
auto ¤t_chunk = scan_state.CurrentChunk(); | ||
if (scan_state.Finished() || current_chunk.size() == 0) { | ||
break; | ||
} | ||
// The amount we still need to append into this chunk | ||
auto remaining = batch_size - count; | ||
|
||
// The amount remaining, capped by the amount left in the current chunk | ||
auto to_append_to_batch = MinValue(remaining, scan_state.RemainingInChunk()); | ||
appender.Append(current_chunk, 0, to_append_to_batch, current_chunk.size()); | ||
count += to_append_to_batch; | ||
scan_state.IncreaseOffset(to_append_to_batch); | ||
} | ||
if (count > 0) { | ||
*out = appender.Finalize(); | ||
} | ||
return true; | ||
} | ||
|
||
idx_t ArrowUtil::FetchChunk(ChunkScanState &scan_state, ClientProperties options, idx_t chunk_size, ArrowArray *out) { | ||
ErrorData error; | ||
idx_t result_count; | ||
if (!TryFetchChunk(scan_state, std::move(options), chunk_size, out, result_count, error)) { | ||
error.Throw(); | ||
} | ||
return result_count; | ||
} | ||
|
||
} // namespace duckdb |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
//===----------------------------------------------------------------------===// | ||
// DuckDB | ||
// | ||
// duckdb/common/arrow/arrow_util.hpp | ||
// | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#pragma once | ||
#include "duckdb/common/arrow/arrow.hpp" | ||
#include "duckdb/main/chunk_scan_state.hpp" | ||
#include "duckdb/main/client_properties.hpp" | ||
#include "duckdb/common/helper.hpp" | ||
#include "duckdb/common/error_data.hpp" | ||
|
||
namespace duckdb { | ||
|
||
class QueryResult; | ||
class DataChunk; | ||
|
||
class ArrowUtil { | ||
public: | ||
static bool TryFetchChunk(ChunkScanState &scan_state, ClientProperties options, idx_t chunk_size, ArrowArray *out, | ||
idx_t &result_count, ErrorData &error); | ||
static idx_t FetchChunk(ChunkScanState &scan_state, ClientProperties options, idx_t chunk_size, ArrowArray *out); | ||
|
||
private: | ||
static bool TryFetchNext(QueryResult &result, unique_ptr<DataChunk> &out, ErrorData &error); | ||
}; | ||
|
||
} // namespace duckdb |
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
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