OmniSciDB  c1a53651b2
 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 
19 #include <regex>
20 
21 const std::vector<const Analyzer::ColumnVar*>& GeospatialFunctionFinder::getGeoArgCvs()
22  const {
23  return geo_arg_cvs_;
24 }
25 
26 const std::pair<shared::TableKey, shared::TableKey>
28  // we assume we do not use self geo join and n-ary geo join
29  if (!geo_arg_cvs_.empty()) {
30  std::unordered_set<shared::TableKey> table_keys;
31  std::for_each(geo_arg_cvs_.cbegin(),
32  geo_arg_cvs_.cend(),
33  [&table_keys](const Analyzer::ColumnVar* cv) {
34  table_keys.emplace(cv->getTableKey());
35  });
36  if (table_keys.size() == 2) {
37  const auto inner_table_key = geo_arg_cvs_.front()->getTableKey();
38  shared::TableKey outer_table_key{-1, -1};
39  std::for_each(
40  table_keys.cbegin(),
41  table_keys.cend(),
42  [&inner_table_key, &outer_table_key](const shared::TableKey& table_key) {
43  if (table_key != inner_table_key) {
44  outer_table_key = table_key;
45  }
46  });
47  return std::make_pair(inner_table_key, outer_table_key);
48  }
49  }
50  return std::make_pair(shared::TableKey{-1, -1}, shared::TableKey{-1, -1});
51 }
52 
54  return geo_func_name_;
55 }
56 
58  const Analyzer::FunctionOper* func_oper) const {
59  geo_func_name_ = func_oper->getName();
60  for (size_t i = 0; i < func_oper->getArity(); i++) {
61  if (auto cv = dynamic_cast<const Analyzer::ColumnVar*>(func_oper->getArg(i))) {
62  geo_arg_cvs_.push_back(cv);
63  }
64  }
65  return nullptr;
66 }
67 
69  for (auto arg : geo_expr->getChildExprs()) {
70  if (auto cv = dynamic_cast<const Analyzer::ColumnVar*>(arg)) {
71  geo_arg_cvs_.push_back(cv);
72  }
73  }
74  return nullptr;
75 }
size_t getArity() const
Definition: Analyzer.h:2408
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:2866
void * visitGeoExpr(const Analyzer::GeoExpr *geo_expr) const override
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:2410
std::string getName() const
Definition: Analyzer.h:2406
const std::pair< shared::TableKey, shared::TableKey > getTableIdsOfGeoExpr() const