22 namespace spatial_type {
28 size_t size() const final {
return 1; }
38 geo_ti_ = operand->get_type_info();
41 if (
auto col_var = dynamic_cast<const Analyzer::ColumnVar*>(operand)) {
43 auto column_key = col_var->getColumnKey();
44 column_key.column_id = column_key.column_id + 1;
48 coords_cd->columnType, column_key, col_var->get_rte_idx());
55 const std::vector<llvm::Value*>& arg_lvs,
56 const std::vector<llvm::Value*>& pos_lvs,
58 llvm::Value* coords_arr_sz_lv{
nullptr};
59 if (
auto geo_constant = dynamic_cast<const Analyzer::GeoConstant*>(
getOperand(0))) {
62 std::regex regex(
"-?[0-9]*\\.?[0-9]+\\s+-?[0-9]*\\.?[0-9]+");
63 auto target = geo_constant->getWKTString();
64 auto pt_begin = std::sregex_iterator(target.begin(), target.end(), regex);
65 auto pt_end = std::sregex_iterator();
66 auto num_pts = std::distance(pt_begin, pt_end);
68 coords_arr_sz_lv = cgen_state->llInt(16 * num_pts);
69 }
else if (arg_lvs.size() == size_t(1)) {
70 std::string fn_name(
"array_size");
72 if (
auto col_var = dynamic_cast<const Analyzer::ColumnVar*>(
getOperand(0))) {
73 auto column_key = col_var->getColumnKey();
74 column_key.column_id = column_key.column_id - 1;
77 if (type_cd->columnType.get_type() ==
kPOINT) {
78 fn_name =
"point_coord_array_size";
81 auto& argument_lv = arg_lvs.front();
83 std::vector<llvm::Value*> array_size_args{
86 cgen_state->llInt(
log2_bytes(elem_ti.get_logical_size()))};
88 fn_name +=
"_nullable";
89 array_size_args.push_back(cgen_state->inlineIntNull(
getTypeInfo()));
91 coords_arr_sz_lv = cgen_state->emitExternalCall(
92 fn_name,
get_int_type(32, cgen_state->context_), array_size_args);
93 }
else if (arg_lvs.size() == size_t(2)) {
96 CHECK(child_geo_oper);
97 if (child_geo_oper->getName() ==
"ST_Point") {
98 coords_arr_sz_lv = cgen_state->ir_builder_.CreateSelect(
99 cgen_state->emitCall(
"point_double_is_null", {arg_lvs.front()}),
101 cgen_state->llInt(static_cast<int32_t>(16)));
103 CHECK(
false) <<
"Not supported geo operator w/ ST_NPoints: "
104 << child_geo_oper->getName();
107 CHECK(coords_arr_sz_lv);
108 return std::make_tuple(std::vector<llvm::Value*>{coords_arr_sz_lv}, coords_arr_sz_lv);
111 std::vector<llvm::Value*>
codegen(
const std::vector<llvm::Value*>&
args,
118 auto& builder = cgen_state->ir_builder_;
119 llvm::Value* conversion_constant{
nullptr};
121 conversion_constant = cgen_state->llInt(4);
123 conversion_constant = cgen_state->llInt(8);
125 CHECK(conversion_constant);
126 const auto total_num_pts = builder.CreateUDiv(
args.front(), conversion_constant);
127 const auto ret = builder.CreateUDiv(total_num_pts, cgen_state->llInt(2));
129 CHECK(nullcheck_codegen);
130 return {nullcheck_codegen->finalize(cgen_state->inlineIntNull(getTypeInfo()), ret)};
size_t size() const final
SQLTypeInfo getNullType() const final
llvm::Type * get_int_type(const int width, llvm::LLVMContext &context)
const Analyzer::Expr * getOperand(const size_t index) final
const ColumnDescriptor * get_column_descriptor(const shared::ColumnKey &column_key)
const SQLTypeInfo & get_type_info() const
std::unique_ptr< Analyzer::ColumnVar > col_var_owned_
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
NPoints(const Analyzer::GeoOperator *geo_operator)
std::vector< llvm::Value * > codegen(const std::vector< llvm::Value * > &args, CodeGenerator::NullCheckCodegen *nullcheck_codegen, CgenState *cgen_state, const CompilationOptions &co) final
const Analyzer::GeoOperator * operator_
Analyzer::Expr * getOperand(const size_t index) const
uint32_t log2_bytes(const uint32_t bytes)
HOST DEVICE bool get_notnull() const
SQLTypeInfo get_elem_type() const