OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Conversion.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 "Analyzer/Analyzer.h"
20 #include "Geospatial/Compression.h"
21 
22 // routines for converting from WKB/OGRGeometry to Analyzer Expressions
23 
24 namespace Geospatial {
25 
26 std::shared_ptr<Analyzer::Constant> convert_coords(const std::vector<double>& coords,
27  const SQLTypeInfo& ti) {
28  std::vector<uint8_t> compressed_coords = Geospatial::compress_coords(coords, ti);
29  std::list<std::shared_ptr<Analyzer::Expr>> compressed_coords_exprs;
30  for (auto cc : compressed_coords) {
31  Datum d;
32  d.tinyintval = cc;
33  auto e = makeExpr<Analyzer::Constant>(kTINYINT, false, d);
34  compressed_coords_exprs.push_back(e);
35  }
36  SQLTypeInfo arr_ti = SQLTypeInfo(kARRAY, true);
37  arr_ti.set_subtype(kTINYINT);
38  arr_ti.set_size(compressed_coords.size() * sizeof(int8_t));
39  arr_ti.set_compression(ti.get_compression());
40  arr_ti.set_comp_param((ti.get_compression() == kENCODING_GEOINT) ? 32 : 64);
41  return makeExpr<Analyzer::Constant>(arr_ti, false, compressed_coords_exprs);
42 }
43 
44 std::shared_ptr<Analyzer::Constant> convert_rings(const std::vector<int>& rings) {
45  std::list<std::shared_ptr<Analyzer::Expr>> ring_size_exprs;
46  for (auto c : rings) {
47  Datum d;
48  d.intval = c;
49  auto e = makeExpr<Analyzer::Constant>(kINT, false, d);
50  ring_size_exprs.push_back(e);
51  }
52  SQLTypeInfo arr_ti = SQLTypeInfo(kARRAY, true);
53  arr_ti.set_subtype(kINT);
54  arr_ti.set_size(rings.size() * sizeof(int32_t));
55  return makeExpr<Analyzer::Constant>(arr_ti, false, ring_size_exprs);
56 }
57 
58 } // namespace Geospatial
int8_t tinyintval
Definition: Datum.h:71
Defines data structures for the semantic analysis phase of query processing.
void set_compression(EncodingType c)
Definition: sqltypes.h:479
void set_size(int s)
Definition: sqltypes.h:476
HOST DEVICE void set_subtype(SQLTypes st)
Definition: sqltypes.h:469
int32_t intval
Definition: Datum.h:73
std::vector< uint8_t > compress_coords(const std::vector< double > &coords, const SQLTypeInfo &ti)
Definition: Compression.cpp:52
std::shared_ptr< Analyzer::Constant > convert_rings(const std::vector< int > &rings)
Definition: Conversion.h:44
void set_comp_param(int p)
Definition: sqltypes.h:480
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:399
std::shared_ptr< Analyzer::Constant > convert_coords(const std::vector< double > &coords, const SQLTypeInfo &ti)
Definition: Conversion.h:26
Definition: sqltypes.h:72
Definition: Datum.h:69