OmniSciDB  a5dc49c757
 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 <optional>
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::optional<GeoJoinOperandsTableKeyPair>
28  std::optional<GeoJoinOperandsTableKeyPair> ret;
29  // we assume we do not use self geo join and n-ary geo join
30  if (!geo_arg_cvs_.empty()) {
31  std::unordered_set<shared::TableKey> table_keys;
32  std::for_each(geo_arg_cvs_.cbegin(),
33  geo_arg_cvs_.cend(),
34  [&table_keys](const Analyzer::ColumnVar* cv) {
35  table_keys.emplace(cv->getTableKey());
36  });
37  if (table_keys.size() == 2) {
38  const auto inner_table_key = geo_arg_cvs_.front()->getTableKey();
39  std::for_each(table_keys.cbegin(),
40  table_keys.cend(),
41  [&inner_table_key, &ret](const shared::TableKey& table_key) {
42  if (table_key != inner_table_key) {
43  ret = {inner_table_key, table_key};
44  }
45  });
46  }
47  }
48  return ret;
49 }
50 
52  return geo_func_name_;
53 }
54 
56  const Analyzer::FunctionOper* func_oper) const {
57  geo_func_name_ = func_oper->getName();
58  for (size_t i = 0; i < func_oper->getArity(); i++) {
59  if (auto cv = dynamic_cast<const Analyzer::ColumnVar*>(func_oper->getArg(i))) {
60  geo_arg_cvs_.push_back(cv);
61  }
62  }
63  return nullptr;
64 }
65 
67  for (auto arg : geo_expr->getChildExprs()) {
68  if (auto cv = dynamic_cast<const Analyzer::ColumnVar*>(arg)) {
69  geo_arg_cvs_.push_back(cv);
70  }
71  }
72  return nullptr;
73 }
size_t getArity() const
Definition: Analyzer.h:2746
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:3222
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:2748
const std::optional< GeoJoinOperandsTableKeyPair > getJoinTableKeyPair() const
std::string getName() const
Definition: Analyzer.h:2744