| 165 | } |
| 166 | |
| 167 | int ZVecCachedSQLParser::traverse_to_replace(Node::Ptr ptr, |
| 168 | Node::Ptr vector_node) { |
| 169 | if (ptr->op() == NodeOp::T_VECTOR_MATRIX_VALUE) { |
| 170 | Node *parent = dynamic_cast<Node *>(ptr->parent()); |
| 171 | if (parent == nullptr) { |
| 172 | LOG_WARN("wrong parent node in cache. [%s]", ptr->to_string().c_str()); |
| 173 | return -1; |
| 174 | } |
| 175 | if (parent->left() == ptr) { |
| 176 | parent->set_left(vector_node); |
| 177 | replace_flag_ = true; |
| 178 | } else if (parent->right() == ptr) { |
| 179 | parent->set_right(vector_node); |
| 180 | replace_flag_ = true; |
| 181 | } else { |
| 182 | LOG_WARN("wrong node in cache. [%s]", ptr->to_string().c_str()); |
| 183 | return -1; |
| 184 | } |
| 185 | return 0; |
| 186 | } |
| 187 | |
| 188 | if (ptr->left() != nullptr) { |
| 189 | if (traverse_to_replace(ptr->left(), vector_node) < 0) { |
| 190 | return -1; |
| 191 | } |
| 192 | if (replace_flag_) { |
| 193 | return 0; |
| 194 | } |
| 195 | } |
| 196 | if (ptr->right() != nullptr) { |
| 197 | if (traverse_to_replace(ptr->right(), vector_node) != 0) { |
| 198 | return -1; |
| 199 | } |
| 200 | if (replace_flag_) { |
| 201 | return 0; |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | return 0; |
| 206 | } |
| 207 | |
| 208 | Node::Ptr ZVecCachedSQLParser::parse_filter(const std::string &filter, |
| 209 | bool need_formatted_tree) { |