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