-
Notifications
You must be signed in to change notification settings - Fork 0
Building arrow core via bazel #21
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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,124 @@ | ||
| #include <arrow/api.h> | ||
| #include <arrow/c/bridge.h> | ||
|
|
||
| #include <cstring> | ||
| #include <memory> | ||
| #include <string> | ||
| #include <utility> | ||
| #include <vector> | ||
|
|
||
| #if defined(_WIN32) | ||
| #define UDF_RUNNER_CPP_V2_EXPORT __declspec(dllexport) | ||
| #else | ||
| #define UDF_RUNNER_CPP_V2_EXPORT __attribute__((visibility("default"))) | ||
| #endif | ||
|
|
||
| namespace { | ||
|
|
||
| thread_local std::string g_last_error; | ||
|
|
||
| void SetLastError(const arrow::Status& status) { | ||
| g_last_error = status.ToString(); | ||
| } | ||
|
|
||
| arrow::Result<std::shared_ptr<arrow::RecordBatch>> MakeDemoRecordBatch() { | ||
| arrow::Int64Builder id_builder; | ||
| arrow::StringBuilder name_builder; | ||
|
|
||
| ARROW_RETURN_NOT_OK(id_builder.Append(1)); | ||
| ARROW_RETURN_NOT_OK(id_builder.Append(2)); | ||
| ARROW_RETURN_NOT_OK(id_builder.Append(3)); | ||
| ARROW_RETURN_NOT_OK(id_builder.Append(4)); | ||
|
|
||
| ARROW_RETURN_NOT_OK(name_builder.Append("alpha")); | ||
| ARROW_RETURN_NOT_OK(name_builder.Append("beta")); | ||
| ARROW_RETURN_NOT_OK(name_builder.Append("gamma")); | ||
| ARROW_RETURN_NOT_OK(name_builder.Append("delta")); | ||
|
|
||
| std::shared_ptr<arrow::Array> ids; | ||
| std::shared_ptr<arrow::Array> names; | ||
| ARROW_RETURN_NOT_OK(id_builder.Finish(&ids)); | ||
| ARROW_RETURN_NOT_OK(name_builder.Finish(&names)); | ||
| const int64_t num_rows = ids->length(); | ||
|
|
||
| auto schema = arrow::schema({ | ||
| arrow::field("id", arrow::int64()), | ||
| arrow::field("name", arrow::utf8()), | ||
| }); | ||
| return arrow::RecordBatch::Make(schema, num_rows, {std::move(ids), std::move(names)}); | ||
| } | ||
|
|
||
| arrow::Status ExportDemoRecordBatch(ArrowArray* out_array, ArrowSchema* out_schema) { | ||
| if (out_array == nullptr || out_schema == nullptr) { | ||
| return arrow::Status::Invalid("output ArrowArray and ArrowSchema pointers must not be null"); | ||
| } | ||
|
|
||
| std::memset(out_array, 0, sizeof(*out_array)); | ||
| std::memset(out_schema, 0, sizeof(*out_schema)); | ||
|
|
||
| auto maybe_batch = MakeDemoRecordBatch(); | ||
| if (!maybe_batch.ok()) { | ||
| return maybe_batch.status(); | ||
| } | ||
| ARROW_RETURN_NOT_OK(arrow::ExportRecordBatch(*maybe_batch.ValueOrDie(), out_array, out_schema)); | ||
| return arrow::Status::OK(); | ||
| } | ||
|
|
||
| arrow::Status ConsumeDemoRecordBatch(ArrowArray* array, ArrowSchema* schema, | ||
| int64_t* out_row_count, int64_t* out_id_sum) { | ||
| if (array == nullptr || schema == nullptr || out_row_count == nullptr || | ||
| out_id_sum == nullptr) { | ||
| return arrow::Status::Invalid("input and output pointers must not be null"); | ||
| } | ||
|
|
||
| ARROW_ASSIGN_OR_RAISE(auto batch, arrow::ImportRecordBatch(array, schema)); | ||
| if (batch->num_columns() != 2) { | ||
| return arrow::Status::Invalid("expected two columns"); | ||
| } | ||
| if (batch->schema()->field(0)->name() != "id" || | ||
| batch->schema()->field(1)->name() != "name") { | ||
| return arrow::Status::Invalid("unexpected schema"); | ||
| } | ||
|
|
||
| auto ids = std::static_pointer_cast<arrow::Int64Array>(batch->column(0)); | ||
| int64_t sum = 0; | ||
| for (int64_t index = 0; index < ids->length(); ++index) { | ||
| if (!ids->IsNull(index)) { | ||
| sum += ids->Value(index); | ||
| } | ||
| } | ||
|
|
||
| *out_row_count = batch->num_rows(); | ||
| *out_id_sum = sum; | ||
| return arrow::Status::OK(); | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| extern "C" UDF_RUNNER_CPP_V2_EXPORT int udf_runner_cpp_v2_demo_export_record_batch( | ||
| ArrowArray* out_array, ArrowSchema* out_schema) { | ||
| const arrow::Status status = ExportDemoRecordBatch(out_array, out_schema); | ||
| if (!status.ok()) { | ||
| SetLastError(status); | ||
| return 1; | ||
| } | ||
| g_last_error.clear(); | ||
| return 0; | ||
| } | ||
|
|
||
| extern "C" UDF_RUNNER_CPP_V2_EXPORT int udf_runner_cpp_v2_demo_consume_record_batch( | ||
| ArrowArray* array, ArrowSchema* schema, int64_t* out_row_count, | ||
| int64_t* out_id_sum) { | ||
| const arrow::Status status = | ||
| ConsumeDemoRecordBatch(array, schema, out_row_count, out_id_sum); | ||
| if (!status.ok()) { | ||
| SetLastError(status); | ||
| return 1; | ||
| } | ||
| g_last_error.clear(); | ||
| return 0; | ||
| } | ||
|
|
||
| extern "C" UDF_RUNNER_CPP_V2_EXPORT const char* udf_runner_cpp_v2_demo_last_error(void) { | ||
| return g_last_error.c_str(); | ||
| } | ||
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,9 @@ | ||
| { | ||
| global: | ||
| udf_runner_cpp_v2_demo_export_record_batch; | ||
| udf_runner_cpp_v2_demo_consume_record_batch; | ||
| udf_runner_cpp_v2_demo_last_error; | ||
| local: | ||
| *; | ||
| }; | ||
|
|
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,29 @@ | ||
| #pragma once | ||
|
|
||
| #include <arrow/c/abi.h> | ||
|
|
||
| #include <stdint.h> | ||
|
|
||
| #if defined(_WIN32) | ||
| #define UDF_RUNNER_CPP_V2_EXPORT __declspec(dllexport) | ||
| #else | ||
| #define UDF_RUNNER_CPP_V2_EXPORT __attribute__((visibility("default"))) | ||
| #endif | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| UDF_RUNNER_CPP_V2_EXPORT int udf_runner_cpp_v2_demo_export_record_batch( | ||
| struct ArrowArray* out_array, struct ArrowSchema* out_schema); | ||
|
|
||
| UDF_RUNNER_CPP_V2_EXPORT int udf_runner_cpp_v2_demo_consume_record_batch( | ||
| struct ArrowArray* array, struct ArrowSchema* schema, int64_t* out_row_count, | ||
| int64_t* out_id_sum); | ||
|
|
||
| UDF_RUNNER_CPP_V2_EXPORT const char* udf_runner_cpp_v2_demo_last_error(void); | ||
|
|
||
| #ifdef __cplusplus | ||
| } // extern "C" | ||
| #endif | ||
|
|
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.
When a caller supplies a valid C Data record batch whose fields are named
idandnamebut whose first column is notint64(for example, UTF-8), the name-only schema check passes and this uncheckedstatic_pointer_casttreats another array implementation asInt64Array. SubsequentValue()calls can read the wrong buffer layout, producing incorrect sums or undefined behavior instead of returning an error; check the field type before casting.Useful? React with 👍 / 👎.