OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Codegen.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 
19 
20 namespace spatial_type {
21 
22 std::unique_ptr<Codegen> Codegen::init(const Analyzer::GeoOperator* geo_operator) {
23  const auto operator_name = geo_operator->getName();
24  if (operator_name == "ST_NRings") {
25  return std::make_unique<NRings>(geo_operator);
26  } else if (operator_name == "ST_NumGeometries") {
27  return std::make_unique<NumGeometries>(geo_operator);
28  } else if (operator_name == "ST_NPoints") {
29  return std::make_unique<NPoints>(geo_operator);
30  } else if (operator_name == "ST_PointN") {
31  return std::make_unique<PointN>(geo_operator);
32  } else if (operator_name == "ST_StartPoint" || operator_name == "ST_EndPoint") {
33  return std::make_unique<StartEndPoint>(geo_operator);
34  } else if (operator_name == "ST_X" || operator_name == "ST_Y") {
35  return std::make_unique<PointAccessors>(geo_operator);
36  } else if (operator_name == "ST_Point") {
37  return std::make_unique<PointConstructor>(geo_operator);
38  } else if (operator_name == "ST_Transform") {
39  return std::make_unique<Transform>(geo_operator);
40  } else if (operator_name == "ST_Perimeter" || operator_name == "ST_Area") {
41  return std::make_unique<AreaPerimeter>(geo_operator);
42  } else if (operator_name == "ST_Centroid") {
43  return std::make_unique<Centroid>(geo_operator);
44  } else if (operator_name == "ST_Distance" || operator_name == "ST_MaxDistance") {
45  return std::make_unique<Distance>(geo_operator);
46  }
47  UNREACHABLE();
48  return nullptr;
49 }
50 
51 std::unique_ptr<CodeGenerator::NullCheckCodegen> Codegen::getNullCheckCodegen(
52  llvm::Value* null_lv,
53  CgenState* cgen_state,
54  Executor* executor) {
55  if (isNullable()) {
56  CHECK(null_lv);
57  return std::make_unique<CodeGenerator::NullCheckCodegen>(
58  cgen_state, executor, null_lv, getNullType(), getName() + "_nullcheck");
59  } else {
60  return nullptr;
61  }
62 }
63 
64 const Analyzer::Expr* Codegen::getOperand(const size_t index) {
65  CHECK_LT(index, operator_->size());
66  return operator_->getOperand(index);
67 }
68 
69 std::string suffix(SQLTypes type) {
70  if (type == kPOINT) {
71  return std::string("_Point");
72  }
73  if (type == kMULTIPOINT) {
74  return std::string("_MultiPoint");
75  }
76  if (type == kLINESTRING) {
77  return std::string("_LineString");
78  }
79  if (type == kMULTILINESTRING) {
80  return std::string("_MultiLineString");
81  }
82  if (type == kPOLYGON) {
83  return std::string("_Polygon");
84  }
85  if (type == kMULTIPOLYGON) {
86  return std::string("_MultiPolygon");
87  }
88  UNREACHABLE() << "Unsupported argument to suffix: " << toString(type);
89  return "";
90 }
91 
92 } // namespace spatial_type
SQLTypes
Definition: sqltypes.h:65
#define UNREACHABLE()
Definition: Logger.h:338
std::string toString(const QueryDescriptionType &type)
Definition: Types.h:64
std::string suffix(SQLTypes type)
Definition: Codegen.cpp:69
const std::string & getName() const
Definition: Analyzer.h:3167
auto isNullable() const
Definition: Codegen.h:32
virtual SQLTypeInfo getNullType() const =0
#define CHECK_LT(x, y)
Definition: Logger.h:303
virtual std::unique_ptr< CodeGenerator::NullCheckCodegen > getNullCheckCodegen(llvm::Value *null_lv, CgenState *cgen_state, Executor *executor)
Definition: Codegen.cpp:51
const Analyzer::GeoOperator * operator_
Definition: Codegen.h:67
size_t size() const
Definition: Analyzer.cpp:4182
#define CHECK(condition)
Definition: Logger.h:291
virtual const Analyzer::Expr * getOperand(const size_t index)
Definition: Codegen.cpp:64
std::string getName() const
Definition: Codegen.h:36
Analyzer::Expr * getOperand(const size_t index) const
Definition: Analyzer.cpp:4186
static std::unique_ptr< Codegen > init(const Analyzer::GeoOperator *geo_operator)
Definition: Codegen.cpp:22