OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
StringViewToGeoEncoder.h
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 #pragma once
18 
19 #include "BaseConvertEncoder.h"
21 
23 
24 namespace data_conversion {
25 
28  public:
29  StringViewToGeoEncoder(std::list<Chunk_NS::Chunk>& chunks,
30  std::list<std::unique_ptr<ChunkMetadata>>& chunk_metadata,
31  const bool error_tracking_enabled,
32  const bool geo_validate_geometry)
33  : BaseConvertEncoder(error_tracking_enabled)
34  , foreign_storage::GeospatialEncoder(chunks,
35  chunk_metadata,
36  geo_validate_geometry) {}
37 
38  void encodeAndAppendData(const int8_t* data, const size_t num_elements) override {
39  auto geo_strings = reinterpret_cast<const std::string_view*>(data);
41 
42  for (size_t i = 0; i < num_elements; ++i) {
44  delete_buffer_->push_back(false);
45  }
47  auto& geo_string = geo_strings[i];
48  if (geo_string.empty()) {
50  } else {
51  try {
52  processGeoElement(geo_strings[i]); // this may throw, need to handle error
53  } catch (std::exception& except) {
55  throw;
56  } else {
59  delete_buffer_->back() = true;
60  }
61  }
62  }
63  }
64 
66  appendBaseDataAndUpdateMetadata(num_elements);
67  }
68 };
69 
70 } // namespace data_conversion
void encodeAndAppendData(const int8_t *data, const size_t num_elements) override
void processGeoElement(std::string_view geo_string_view)
std::optional< std::vector< bool > > delete_buffer_
GeospatialEncoder(const bool geo_validate_geometry)
void appendBaseDataAndUpdateMetadata(const int64_t row_count)
StringViewToGeoEncoder(std::list< Chunk_NS::Chunk > &chunks, std::list< std::unique_ptr< ChunkMetadata >> &chunk_metadata, const bool error_tracking_enabled, const bool geo_validate_geometry)