json/json.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021-2024, NVIDIA CORPORATION.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #pragma once
17 
20 
21 #include <rmm/mr/device/per_device_resource.hpp>
22 #include <rmm/resource_ref.hpp>
23 
24 #include <thrust/optional.h>
25 
26 namespace cudf {
27 
38  // allow single quotes to represent strings in JSON
39  bool allow_single_quotes = false;
40 
41  // individual string values are returned with quotes stripped.
42  bool strip_quotes_from_single_strings = true;
43 
44  // Whether to return nulls when an object does not contain the requested field.
45  bool missing_fields_as_nulls = false;
46 
47  public:
51  explicit get_json_object_options() = default;
52 
59  [[nodiscard]] CUDF_HOST_DEVICE inline bool get_allow_single_quotes() const
60  {
61  return allow_single_quotes;
62  }
63 
88  [[nodiscard]] CUDF_HOST_DEVICE inline bool get_strip_quotes_from_single_strings() const
89  {
90  return strip_quotes_from_single_strings;
91  }
92 
114  [[nodiscard]] CUDF_HOST_DEVICE inline bool get_missing_fields_as_nulls() const
115  {
116  return missing_fields_as_nulls;
117  }
118 
124  void set_allow_single_quotes(bool _allow_single_quotes)
125  {
126  allow_single_quotes = _allow_single_quotes;
127  }
128 
134  void set_strip_quotes_from_single_strings(bool _strip_quotes_from_single_strings)
135  {
136  strip_quotes_from_single_strings = _strip_quotes_from_single_strings;
137  }
138 
144  void set_missing_fields_as_nulls(bool _missing_fields_as_nulls)
145  {
146  missing_fields_as_nulls = _missing_fields_as_nulls;
147  }
148 };
149 
168 std::unique_ptr<cudf::column> get_json_object(
169  cudf::strings_column_view const& col,
170  cudf::string_scalar const& json_path,
172  rmm::cuda_stream_view stream = cudf::get_default_stream(),
173  rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource());
174  // end of doxygen group
176 } // namespace cudf
Settings for get_json_object().
Definition: json/json.hpp:37
CUDF_HOST_DEVICE bool get_allow_single_quotes() const
Returns true/false depending on whether single-quotes for representing strings are allowed.
Definition: json/json.hpp:59
void set_strip_quotes_from_single_strings(bool _strip_quotes_from_single_strings)
Set whether individually returned string values have their quotes stripped.
Definition: json/json.hpp:134
void set_allow_single_quotes(bool _allow_single_quotes)
Set whether single-quotes for strings are allowed.
Definition: json/json.hpp:124
get_json_object_options()=default
Default constructor.
void set_missing_fields_as_nulls(bool _missing_fields_as_nulls)
Set whether missing fields are interpreted as null.
Definition: json/json.hpp:144
CUDF_HOST_DEVICE bool get_strip_quotes_from_single_strings() const
Returns true/false depending on whether individually returned string values have their quotes strippe...
Definition: json/json.hpp:88
CUDF_HOST_DEVICE bool get_missing_fields_as_nulls() const
Whether a field not contained by an object is to be interpreted as null.
Definition: json/json.hpp:114
An owning class to represent a string in device memory.
Definition: scalar.hpp:430
Given a column-view of strings type, an instance of this class provides a wrapper on this compound co...
rmm::cuda_stream_view const get_default_stream()
Get the current default stream.
std::unique_ptr< cudf::column > get_json_object(cudf::strings_column_view const &col, cudf::string_scalar const &json_path, get_json_object_options options=get_json_object_options{}, rmm::cuda_stream_view stream=cudf::get_default_stream(), rmm::device_async_resource_ref mr=rmm::mr::get_current_device_resource())
Apply a JSONPath string to all rows in an input strings column.
cuDF interfaces
Definition: aggregation.hpp:34
Class definition for cudf::strings_column_view.
#define CUDF_HOST_DEVICE
Indicates that the function or method is usable on host and device.
Definition: types.hpp:32