OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FileRegions.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2022 HEAVY.AI, Inc.
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 
17 #include "FileRegions.h"
18 
19 #include "Shared/JsonUtils.h"
20 
21 namespace foreign_storage {
22 // Serialization functions for FileRegion
23 void set_value(rapidjson::Value& json_val,
24  const FileRegion& file_region,
25  rapidjson::Document::AllocatorType& allocator) {
26  json_val.SetObject();
28  json_val, file_region.first_row_file_offset, "first_row_file_offset", allocator);
30  json_val, file_region.first_row_index, "first_row_index", allocator);
32  json_val, file_region.region_size, "region_size", allocator);
34  json_val, file_region.row_count, "row_count", allocator);
35  if (file_region.file_path.size()) {
37  json_val, file_region.file_path, "file_path", allocator);
38  }
39 }
40 
41 void get_value(const rapidjson::Value& json_val, FileRegion& file_region) {
42  CHECK(json_val.IsObject());
44  json_val, file_region.first_row_file_offset, "first_row_file_offset");
46  json_val, file_region.first_row_index, "first_row_index");
47  json_utils::get_value_from_object(json_val, file_region.region_size, "region_size");
48  json_utils::get_value_from_object(json_val, file_region.row_count, "row_count");
49  if (json_val.HasMember("file_path")) {
50  json_utils::get_value_from_object(json_val, file_region.file_path, "file_path");
51  } else if (json_val.HasMember("filename")) {
52  // Handle legacy "filename" field name
53  json_utils::get_value_from_object(json_val, file_region.file_path, "filename");
54  }
55 }
56 } // namespace foreign_storage
void get_value_from_object(const rapidjson::Value &object, T &value, const std::string &name)
Definition: JsonUtils.h:270
void get_value(const rapidjson::Value &json_val, FileRegion &file_region)
Definition: CsvShared.cpp:44
void add_value_to_object(rapidjson::Value &object, const T &value, const std::string &name, rapidjson::Document::AllocatorType &allocator)
Definition: JsonUtils.h:255
#define CHECK(condition)
Definition: Logger.h:291
void set_value(rapidjson::Value &json_val, const FileRegion &file_region, rapidjson::Document::AllocatorType &allocator)
Definition: CsvShared.cpp:26