OmniSciDB  a987f07e93
 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 Catalog_Namespace::Catalog* catalog) {
24  const auto operator_name = geo_operator->getName();
25  if (operator_name == "ST_NRings") {
26  return std::make_unique<NRings>(geo_operator, catalog);
27  } else if (operator_name == "ST_NumGeometries") {
28  return std::make_unique<NumGeometries>(geo_operator, catalog);
29  } else if (operator_name == "ST_NPoints") {
30  return std::make_unique<NPoints>(geo_operator, catalog);
31  } else if (operator_name == "ST_PointN") {
32  return std::make_unique<PointN>(geo_operator, catalog);
33  } else if (operator_name == "ST_StartPoint" || operator_name == "ST_EndPoint") {
34  return std::make_unique<StartEndPoint>(geo_operator, catalog);
35  } else if (operator_name == "ST_X" || operator_name == "ST_Y") {
36  return std::make_unique<PointAccessors>(geo_operator, catalog);
37  } else if (operator_name == "ST_Point") {
38  return std::make_unique<PointConstructor>(geo_operator, catalog);
39  } else if (operator_name == "ST_Transform") {
40  return std::make_unique<Transform>(geo_operator, catalog);
41  } else if (operator_name == "ST_Perimeter" || operator_name == "ST_Area") {
42  return std::make_unique<AreaPerimeter>(geo_operator, catalog);
43  } else if (operator_name == "ST_Centroid") {
44  return std::make_unique<Centroid>(geo_operator, catalog);
45  } else if (operator_name == "ST_Distance" || operator_name == "ST_MaxDistance") {
46  return std::make_unique<Distance>(geo_operator, catalog);
47  }
48  UNREACHABLE();
49  return nullptr;
50 }
51 
52 std::unique_ptr<CodeGenerator::NullCheckCodegen> Codegen::getNullCheckCodegen(
53  llvm::Value* null_lv,
54  CgenState* cgen_state,
55  Executor* executor) {
56  if (isNullable()) {
57  CHECK(null_lv);
58  return std::make_unique<CodeGenerator::NullCheckCodegen>(
59  cgen_state, executor, null_lv, getNullType(), getName() + "_nullcheck");
60  } else {
61  return nullptr;
62  }
63 }
64 
65 const Analyzer::Expr* Codegen::getOperand(const size_t index) {
66  CHECK_LT(index, operator_->size());
67  return operator_->getOperand(index);
68 }
69 
70 std::string suffix(SQLTypes type) {
71  if (type == kPOINT) {
72  return std::string("_Point");
73  }
74  if (type == kMULTIPOINT) {
75  return std::string("_MultiPoint");
76  }
77  if (type == kLINESTRING) {
78  return std::string("_LineString");
79  }
80  if (type == kMULTILINESTRING) {
81  return std::string("_MultiLineString");
82  }
83  if (type == kPOLYGON) {
84  return std::string("_Polygon");
85  }
86  if (type == kMULTIPOLYGON) {
87  return std::string("_MultiPolygon");
88  }
89  UNREACHABLE() << "Unsupported argument to suffix: " << toString(type);
90  return "";
91 }
92 
93 } // namespace spatial_type
class for a per-database catalog. also includes metadata for the current database and the current use...
Definition: Catalog.h:132
SQLTypes
Definition: sqltypes.h:53
#define UNREACHABLE()
Definition: Logger.h:333
std::string suffix(SQLTypes type)
Definition: Codegen.cpp:70
const std::string & getName() const
Definition: Analyzer.h:2945
std::string toString(const ExecutorDeviceType &device_type)
auto isNullable() const
Definition: Codegen.h:35
virtual SQLTypeInfo getNullType() const =0
#define CHECK_LT(x, y)
Definition: Logger.h:299
virtual std::unique_ptr< CodeGenerator::NullCheckCodegen > getNullCheckCodegen(llvm::Value *null_lv, CgenState *cgen_state, Executor *executor)
Definition: Codegen.cpp:52
const Analyzer::GeoOperator * operator_
Definition: Codegen.h:70
size_t size() const
Definition: Analyzer.cpp:3967
#define CHECK(condition)
Definition: Logger.h:289
virtual const Analyzer::Expr * getOperand(const size_t index)
Definition: Codegen.cpp:65
std::string getName() const
Definition: Codegen.h:39
Analyzer::Expr * getOperand(const size_t index) const
Definition: Analyzer.cpp:3971
static std::unique_ptr< Codegen > init(const Analyzer::GeoOperator *geo_operator, const Catalog_Namespace::Catalog *catalog)
Definition: Codegen.cpp:22