Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 4.3k
GH-45908: [C++][Docs] Rename and expose basic {Array,...}FromJSON helpers as public APIs#46180
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
e6b8267cf808f9644d4076fbb2f3ce373f56479400974afd18b38e85f3d37dc09c6e820a342e33254825b4a9ef42691fe73c06d361bb08eb11da4d428e2c33b1f984c24e757b38a944aa585a1322555c8a965af521d485bfb02952be2cbc14a9bc3e279f5ab5cedcfeb5ed9b196ed729f91dd1cFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| // 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. | ||
| // This example shows how to use some of the *FromJSONString helpers. | ||
| #include <iostream> | ||
| #include <memory> | ||
| #include <arrow/api.h> | ||
| #include <arrow/array/array_base.h> | ||
| #include <arrow/json/from_string.h> | ||
| #include <arrow/status.h> | ||
| using arrow::json::ArrayFromJSONString; | ||
| using arrow::json::ChunkedArrayFromJSONString; | ||
| using arrow::json::DictArrayFromJSONString; | ||
| /** | ||
| * \brief Run Example | ||
| * | ||
| * ./debug/from-json-string-example | ||
| */ | ||
| arrow::Status RunExample() { | ||
| // Simple types | ||
| ARROW_ASSIGN_OR_RAISE(auto int32_array, | ||
| ArrayFromJSONString(arrow::int32(), "[1, 2, 3]")); | ||
| ARROW_ASSIGN_OR_RAISE(auto float64_array, | ||
| ArrayFromJSONString(arrow::float64(), "[4.0, 5.0, 6.0]")); | ||
| ARROW_ASSIGN_OR_RAISE(auto bool_array, | ||
| ArrayFromJSONString(arrow::boolean(), "[true, false, true]")); | ||
| ARROW_ASSIGN_OR_RAISE( | ||
| auto string_array, | ||
| ArrayFromJSONString(arrow::utf8(), R"(["Hello", "World", null])")); | ||
| // Timestamps can be created from string representations | ||
| ARROW_ASSIGN_OR_RAISE( | ||
| auto ts_array, | ||
| ArrayFromJSONString(timestamp(arrow::TimeUnit::SECOND), | ||
| R"(["1970-01-01", "2000-02-29","3989-07-14","1900-02-28"])")); | ||
| // List, Map, Struct | ||
| ARROW_ASSIGN_OR_RAISE( | ||
| auto list_array, | ||
| ArrayFromJSONString(list(arrow::int64()), | ||
| "[[null], [], null, [4, 5, 6, 7, 8], [2, 3]]")); | ||
| ARROW_ASSIGN_OR_RAISE( | ||
| auto map_array, | ||
| ArrayFromJSONString(map(arrow::utf8(), arrow::int32()), | ||
| R"([[["joe", 0], ["mark", null]], null, [["cap", 8]], []])")); | ||
| ARROW_ASSIGN_OR_RAISE( | ||
| auto struct_array, | ||
| ArrayFromJSONString( | ||
| arrow::struct_({field("one", arrow::int32()), field("two", arrow::int32())}), | ||
| "[[11, 22], null, [null, 33]]")); | ||
| // ChunkedArrayFromJSONString | ||
| std::shared_ptr<arrow::ChunkedArray> chunked_array; | ||
| ARROW_RETURN_NOT_OK(ChunkedArrayFromJSONString( | ||
| arrow::int32(), {"[5, 10]", "[null]", "[16]"}, &chunked_array)); | ||
| // DictArrayFromJSONString | ||
| std::shared_ptr<arrow::Array> dict_array; | ||
| ARROW_RETURN_NOT_OK(DictArrayFromJSONString( | ||
| dictionary(arrow::int32(), arrow::utf8()), "[0, 1, 0, 2, 0, 3]", | ||
| R"(["k1", "k2", "k3", "k4"])", &dict_array)); | ||
| return arrow::Status::OK(); | ||
| } | ||
| int main(int argc, char** argv) { | ||
| auto status = RunExample(); | ||
| if (!status.ok()) { | ||
| std::cerr << status.ToString() << std::endl; | ||
| return EXIT_FAILURE; | ||
| } | ||
| return EXIT_SUCCESS; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -2140,8 +2140,8 @@ class WriteFileSystemDatasetMixin : public MakeFileSystemDatasetMixin { | ||
| actual_struct = std::dynamic_pointer_cast<Array>(struct_array); | ||
| } | ||
| auto expected_struct = ArrayFromJSON(struct_(expected_physical_schema_->fields()), | ||
| file_contents->second); | ||
| auto expected_struct = arrow::ArrayFromJSON( | ||
amoeba marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| struct_(expected_physical_schema_->fields()), file_contents->second); | ||
| AssertArraysEqual(*expected_struct, *actual_struct, /*verbose=*/true); | ||
| } | ||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.