OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
spatial_type::NumGeometries Class Reference

#include <NumGeometries.h>

+ Inheritance diagram for spatial_type::NumGeometries:
+ Collaboration diagram for spatial_type::NumGeometries:

Public Member Functions

 NumGeometries (const Analyzer::GeoOperator *geo_operator)
 
size_t size () const final
 
SQLTypeInfo getNullType () const final
 
const SQLTypeInfo getOperandTypeInfo (const size_t index)
 
const Analyzer::ExprgetOperand (const size_t index) final
 
std::tuple< std::vector
< llvm::Value * >, llvm::Value * > 
codegenLoads (const std::vector< llvm::Value * > &arg_lvs, const std::vector< llvm::Value * > &pos_lvs, CgenState *cgen_state) final
 
std::vector< llvm::Value * > codegen (const std::vector< llvm::Value * > &args, CodeGenerator::NullCheckCodegen *nullcheck_codegen, CgenState *cgen_state, const CompilationOptions &co) final
 
- Public Member Functions inherited from spatial_type::Codegen
 Codegen (const Analyzer::GeoOperator *geo_operator)
 
auto isNullable () const
 
auto getTypeInfo () const
 
std::string getName () const
 
virtual std::unique_ptr
< CodeGenerator::NullCheckCodegen
getNullCheckCodegen (llvm::Value *null_lv, CgenState *cgen_state, Executor *executor)
 
virtual ~Codegen ()
 

Protected Attributes

std::unique_ptr
< Analyzer::ColumnVar
operand_owned_
 
- Protected Attributes inherited from spatial_type::Codegen
const Analyzer::GeoOperatoroperator_
 
bool is_nullable_ {true}
 

Additional Inherited Members

- Static Public Member Functions inherited from spatial_type::Codegen
static std::unique_ptr< Codegeninit (const Analyzer::GeoOperator *geo_operator)
 
static char const * pointIsNullFunctionName (SQLTypeInfo const &)
 

Detailed Description

Definition at line 23 of file NumGeometries.h.

Constructor & Destructor Documentation

spatial_type::NumGeometries::NumGeometries ( const Analyzer::GeoOperator geo_operator)
inline

Definition at line 25 of file NumGeometries.h.

25 : Codegen(geo_operator) {}
Codegen(const Analyzer::GeoOperator *geo_operator)
Definition: Codegen.h:28

Member Function Documentation

std::vector<llvm::Value*> spatial_type::NumGeometries::codegen ( const std::vector< llvm::Value * > &  args,
CodeGenerator::NullCheckCodegen nullcheck_codegen,
CgenState cgen_state,
const CompilationOptions co 
)
inlinefinalvirtual

Implements spatial_type::Codegen.

Definition at line 154 of file NumGeometries.h.

References run_benchmark_import::args, CHECK, CHECK_EQ, spatial_type::Codegen::getTypeInfo(), and spatial_type::Codegen::isNullable().

157  {
158  CHECK_EQ(args.size(), size_t(1));
159  if (isNullable()) {
160  CHECK(nullcheck_codegen);
161  return {nullcheck_codegen->finalize(cgen_state->inlineIntNull(getTypeInfo()),
162  args.front())};
163  }
164  return {args.front()};
165  }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
auto getTypeInfo() const
Definition: Codegen.h:34
llvm::ConstantInt * inlineIntNull(const SQLTypeInfo &)
Definition: CgenState.cpp:65
auto isNullable() const
Definition: Codegen.h:32
llvm::Value * finalize(llvm::Value *null_lv, llvm::Value *notnull_lv)
Definition: IRCodegen.cpp:1530
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the call graph for this function:

std::tuple<std::vector<llvm::Value*>, llvm::Value*> spatial_type::NumGeometries::codegenLoads ( const std::vector< llvm::Value * > &  arg_lvs,
const std::vector< llvm::Value * > &  pos_lvs,
CgenState cgen_state 
)
inlinefinalvirtual

Implements spatial_type::Codegen.

Definition at line 95 of file NumGeometries.h.

References CHECK, CHECK_EQ, SQLTypeInfo::get_elem_type(), get_int_type(), Analyzer::Expr::get_type_info(), getOperand(), getOperandTypeInfo(), spatial_type::Codegen::getTypeInfo(), IS_GEO_MULTI, spatial_type::Codegen::isNullable(), kENCODING_GEOINT, kMULTIPOINT, kTINYINT, log2_bytes(), and size().

98  {
99  CHECK_EQ(pos_lvs.size(), size());
100  CHECK_EQ(arg_lvs.size(), size_t(1));
101 
102  const auto& oper_ti = getOperandTypeInfo(0);
103  auto const is_multi_geo = IS_GEO_MULTI(oper_ti.get_type());
104 
105  // non-MULTI non-nullable geo, just return 1 (no function call)
106  if (!isNullable() && !is_multi_geo) {
107  auto* const one = cgen_state->llInt(1);
108  return {{one}, one};
109  }
110 
111  // will be a function call, the first two arguments
112  std::string fn_name("array_size");
113  auto& argument_lv = arg_lvs.front();
114  std::vector<llvm::Value*> array_size_args = {argument_lv, pos_lvs.front()};
115 
116  if (is_multi_geo) {
117  // MULTI geo, fetch and append element log size argument
118  const auto& elem_ti = getOperand(0)->get_type_info().get_elem_type();
119  uint32_t elem_log_sz_value{};
120  if (oper_ti.get_type() == kMULTIPOINT) {
121  // we must have been passed the coords column
122  CHECK(elem_ti.get_type() == kTINYINT);
123  // we want to return the number of points (two coords),
124  // so divide by either 8 (compressed) or 16 (uncompressed)
125  if (oper_ti.get_compression() == kENCODING_GEOINT) {
126  // number of INT pairs
127  elem_log_sz_value = 3;
128  } else {
129  // number of DOUBLE pairs
130  elem_log_sz_value = 4;
131  }
132  } else {
133  // some other count (ring_sizes or poly_sizes)
134  elem_log_sz_value = log2_bytes(elem_ti.get_logical_size());
135  }
136  array_size_args.push_back(cgen_state->llInt(elem_log_sz_value));
137  } else {
138  // non-MULTI but nullable geo, return 1 or NULL
139  fn_name += "_1";
140  }
141 
142  // nullable, add NULL value
143  if (isNullable()) {
144  fn_name += "_nullable";
145  array_size_args.push_back(cgen_state->inlineIntNull(getTypeInfo()));
146  }
147 
148  const auto total_num_geometries_lv = cgen_state->emitExternalCall(
149  fn_name, get_int_type(32, cgen_state->context_), array_size_args);
150 
151  return {{total_num_geometries_lv}, total_num_geometries_lv};
152  }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
llvm::Type * get_int_type(const int width, llvm::LLVMContext &context)
auto getTypeInfo() const
Definition: Codegen.h:34
llvm::LLVMContext & context_
Definition: CgenState.h:382
llvm::Value * emitExternalCall(const std::string &fname, llvm::Type *ret_type, const std::vector< llvm::Value * > args, const std::vector< llvm::Attribute::AttrKind > &fnattrs={}, const bool has_struct_return=false)
Definition: CgenState.cpp:395
llvm::ConstantInt * inlineIntNull(const SQLTypeInfo &)
Definition: CgenState.cpp:65
const Analyzer::Expr * getOperand(const size_t index) final
Definition: NumGeometries.h:42
auto isNullable() const
Definition: Codegen.h:32
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:79
llvm::ConstantInt * llInt(const T v) const
Definition: CgenState.h:249
#define CHECK(condition)
Definition: Logger.h:291
const SQLTypeInfo getOperandTypeInfo(const size_t index)
Definition: NumGeometries.h:31
uint32_t log2_bytes(const uint32_t bytes)
Definition: Execute.h:198
size_t size() const final
Definition: NumGeometries.h:27
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:977
#define IS_GEO_MULTI(T)
Definition: sqltypes.h:317

+ Here is the call graph for this function:

SQLTypeInfo spatial_type::NumGeometries::getNullType ( ) const
inlinefinalvirtual

Implements spatial_type::Codegen.

Definition at line 29 of file NumGeometries.h.

References kINT.

29 { return SQLTypeInfo(kINT); }
Definition: sqltypes.h:72
const Analyzer::Expr* spatial_type::NumGeometries::getOperand ( const size_t  index)
inlinefinalvirtual

Reimplemented from spatial_type::Codegen.

Definition at line 42 of file NumGeometries.h.

References CHECK, CHECK_EQ, get_column_descriptor(), spatial_type::Codegen::getName(), Analyzer::GeoOperator::getOperand(), spatial_type::Codegen::is_nullable_, kLINESTRING, kMULTILINESTRING, kMULTIPOINT, kMULTIPOLYGON, kPOINT, kPOLYGON, operand_owned_, spatial_type::Codegen::operator_, and UNREACHABLE.

Referenced by codegenLoads().

42  {
43  CHECK_EQ(index, size_t(0));
44  if (operand_owned_) {
45  return operand_owned_.get();
46  }
47 
48  const auto operand = operator_->getOperand(0);
49  auto col_var = dynamic_cast<const Analyzer::ColumnVar*>(operand);
50  if (!col_var) {
51  throw std::runtime_error(getName() +
52  " requires a geo column as its input argument.");
53  }
54 
55  const auto& geo_ti = col_var->get_type_info();
56  if (!geo_ti.is_geometry()) {
57  throw std::runtime_error(getName() +
58  " requires a geo column as its input argument.");
59  }
60  is_nullable_ = !geo_ti.get_notnull();
61 
62  auto const geo_type = geo_ti.get_type();
63  int column_offset{};
64  switch (geo_type) {
65  case kMULTIPOLYGON:
66  column_offset = 3; // poly_rings
67  break;
68  case kMULTILINESTRING:
69  column_offset = 2; // ring_sizes
70  break;
71  case kMULTIPOINT:
72  column_offset = 1; // points
73  break;
74  case kPOINT:
75  case kLINESTRING:
76  case kPOLYGON:
77  column_offset = 1; // nothing to count, but allow through
78  break;
79  default:
80  UNREACHABLE();
81  }
82 
83  // create a new operand which is just the column to count, and codegen it
84  const auto column_id = col_var->getColumnKey().column_id + column_offset;
85  shared::ColumnKey column_key{col_var->getTableKey(), column_id};
86  const auto cd = get_column_descriptor(column_key);
87  CHECK(cd);
88 
89  operand_owned_ = std::make_unique<Analyzer::ColumnVar>(
90  cd->columnType, column_key, col_var->get_rte_idx());
91  return operand_owned_.get();
92  }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
#define UNREACHABLE()
Definition: Logger.h:338
std::unique_ptr< Analyzer::ColumnVar > operand_owned_
const ColumnDescriptor * get_column_descriptor(const shared::ColumnKey &column_key)
Definition: Execute.h:213
const Analyzer::GeoOperator * operator_
Definition: Codegen.h:69
#define CHECK(condition)
Definition: Logger.h:291
std::string getName() const
Definition: Codegen.h:36
Analyzer::Expr * getOperand(const size_t index) const
Definition: Analyzer.cpp:4215

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const SQLTypeInfo spatial_type::NumGeometries::getOperandTypeInfo ( const size_t  index)
inline

Definition at line 31 of file NumGeometries.h.

References CHECK_EQ, spatial_type::Codegen::getName(), Analyzer::GeoOperator::getOperand(), and spatial_type::Codegen::operator_.

Referenced by codegenLoads().

31  {
32  CHECK_EQ(index, size_t(0));
33  const auto operand = operator_->getOperand(0);
34  auto col_var = dynamic_cast<const Analyzer::ColumnVar*>(operand);
35  if (!col_var) {
36  throw std::runtime_error(getName() +
37  " requires a geo column as its input argument.");
38  }
39  return col_var->get_type_info();
40  }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
const Analyzer::GeoOperator * operator_
Definition: Codegen.h:69
std::string getName() const
Definition: Codegen.h:36
Analyzer::Expr * getOperand(const size_t index) const
Definition: Analyzer.cpp:4215

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

size_t spatial_type::NumGeometries::size ( ) const
inlinefinalvirtual

Implements spatial_type::Codegen.

Definition at line 27 of file NumGeometries.h.

Referenced by codegenLoads().

27 { return 1; }

+ Here is the caller graph for this function:

Member Data Documentation

std::unique_ptr<Analyzer::ColumnVar> spatial_type::NumGeometries::operand_owned_
protected

Definition at line 168 of file NumGeometries.h.

Referenced by getOperand().


The documentation for this class was generated from the following file: