OmniSciDB  c0231cc57d
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GeospatialFunctionFinder.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 
18 #include <regex>
19 
20 const std::vector<const Analyzer::ColumnVar*>& GeospatialFunctionFinder::getGeoArgCvs()
21  const {
22  return geo_arg_cvs_;
23 }
24 
25 const std::pair<int, int> GeospatialFunctionFinder::getTableIdsOfGeoExpr() const {
26  // we assume we do not use self geo join and n-ary geo join
27  if (!geo_arg_cvs_.empty()) {
28  std::unordered_set<int> tableIds;
29  std::for_each(geo_arg_cvs_.cbegin(),
30  geo_arg_cvs_.cend(),
31  [&tableIds](const Analyzer::ColumnVar* cv) {
32  tableIds.emplace(cv->get_table_id());
33  });
34  if (tableIds.size() == 2) {
35  const int inner_table_id = geo_arg_cvs_.front()->get_table_id();
36  int outer_table_id = -1;
37  std::for_each(tableIds.cbegin(),
38  tableIds.cend(),
39  [&inner_table_id, &outer_table_id](const int table_id) {
40  if (table_id != inner_table_id) {
41  outer_table_id = table_id;
42  }
43  });
44  return std::make_pair(inner_table_id, outer_table_id);
45  }
46  }
47  return std::make_pair(-1, -1);
48 }
49 
51  return geo_func_name_;
52 }
53 
55  const Analyzer::FunctionOper* func_oper) const {
56  geo_func_name_ = func_oper->getName();
57  for (size_t i = 0; i < func_oper->getArity(); i++) {
58  if (auto cv = dynamic_cast<const Analyzer::ColumnVar*>(func_oper->getArg(i))) {
59  geo_arg_cvs_.push_back(cv);
60  }
61  }
62  return nullptr;
63 }
64 
66  for (auto arg : geo_expr->getChildExprs()) {
67  if (auto cv = dynamic_cast<const Analyzer::ColumnVar*>(arg)) {
68  geo_arg_cvs_.push_back(cv);
69  }
70  }
71  return nullptr;
72 }
size_t getArity() const
Definition: Analyzer.h:2260
void * visitFunctionOper(const Analyzer::FunctionOper *func_oper) const override
const std::vector< const Analyzer::ColumnVar * > & getGeoArgCvs() const
virtual std::vector< Analyzer::Expr * > getChildExprs() const
Definition: Analyzer.h:2690
void * visitGeoExpr(const Analyzer::GeoExpr *geo_expr) const override
const std::pair< int, int > getTableIdsOfGeoExpr() const
const std::string & getGeoFunctionName() const
std::vector< const Analyzer::ColumnVar * > geo_arg_cvs_
const Analyzer::Expr * getArg(const size_t i) const
Definition: Analyzer.h:2262
std::string getName() const
Definition: Analyzer.h:2258