OmniSciDB  a5dc49c757
 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 char const* Codegen::pointIsNullFunctionName(SQLTypeInfo const& geo_ti) {
70  CHECK_EQ(kPOINT, geo_ti.get_type());
71  return geo_ti.get_compression() == kENCODING_GEOINT ? "point_int32_is_null"
72  : "point_double_is_null";
73 }
74 
75 std::string suffix(SQLTypes type) {
76  if (type == kPOINT) {
77  return std::string("_Point");
78  }
79  if (type == kMULTIPOINT) {
80  return std::string("_MultiPoint");
81  }
82  if (type == kLINESTRING) {
83  return std::string("_LineString");
84  }
85  if (type == kMULTILINESTRING) {
86  return std::string("_MultiLineString");
87  }
88  if (type == kPOLYGON) {
89  return std::string("_Polygon");
90  }
91  if (type == kMULTIPOLYGON) {
92  return std::string("_MultiPolygon");
93  }
94  UNREACHABLE() << "Unsupported argument to suffix: " << toString(type);
95  return "";
96 }
97 
98 } // namespace spatial_type
#define CHECK_EQ(x, y)
Definition: Logger.h:301
SQLTypes
Definition: sqltypes.h:65
#define UNREACHABLE()
Definition: Logger.h:338
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:391
static char const * pointIsNullFunctionName(SQLTypeInfo const &)
Definition: Codegen.cpp:69
std::string suffix(SQLTypes type)
Definition: Codegen.cpp:75
const std::string & getName() const
Definition: Analyzer.h:3298
auto isNullable() const
Definition: Codegen.h:32
std::string toString(const Executor::ExtModuleKinds &kind)
Definition: Execute.h:1703
virtual SQLTypeInfo getNullType() const =0
#define CHECK_LT(x, y)
Definition: Logger.h:303
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:399
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:69
size_t size() const
Definition: Analyzer.cpp:4211
#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:4215
static std::unique_ptr< Codegen > init(const Analyzer::GeoOperator *geo_operator)
Definition: Codegen.cpp:22