| 45 | ZVecCachedSQLParser::~ZVecCachedSQLParser() {} |
| 46 | |
| 47 | SQLInfo::Ptr ZVecCachedSQLParser::parse(const std::string &query, |
| 48 | bool need_formatted_tree) { |
| 49 | std::string query_cache_key{""}; |
| 50 | SQLInfo::Ptr cached_sql_info = get_from_cache(query, &query_cache_key); |
| 51 | if (cached_sql_info != nullptr) { |
| 52 | return cached_sql_info; |
| 53 | } |
| 54 | |
| 55 | SQLInfo::Ptr new_sql_info = real_parser_.parse(query, need_formatted_tree); |
| 56 | if (new_sql_info == nullptr) { |
| 57 | // no need to cache parse failed sql. just return. |
| 58 | err_msg_ = real_parser_.err_msg(); |
| 59 | return nullptr; |
| 60 | } |
| 61 | |
| 62 | put_into_cache(query_cache_key, new_sql_info); |
| 63 | |
| 64 | return new_sql_info; |
| 65 | } |
| 66 | |
| 67 | void ZVecCachedSQLParser::put_into_cache(const std::string &query_cache_key, |
| 68 | const SQLInfo::Ptr &new_sql_info) { |