As defined in `ImpalaServer::QUERY_ERROR_FORMAT`, an error message is expected to has the following form: Query failed:\n \n This function returns True if 1. `actual_msg` contains the error prompt "Query failed:\n", and 2. `expected_msg` follows ri
(actual_msg, expected_msg="", query_id=None)
| 803 | |
| 804 | |
| 805 | def error_msg_startswith(actual_msg, expected_msg="", query_id=None): |
| 806 | """ |
| 807 | As defined in `ImpalaServer::QUERY_ERROR_FORMAT`, an error message is expected to |
| 808 | has the following form: |
| 809 | |
| 810 | Query <query_id> failed:\n<error_detail>\n |
| 811 | |
| 812 | This function returns True if |
| 813 | 1. `actual_msg` contains the error prompt "Query <query_id> failed:\n", and |
| 814 | 2. `expected_msg` follows right after the error prompt. |
| 815 | |
| 816 | For `query_id`, |
| 817 | - If the query_id argument is not None, the function checks if the actual error |
| 818 | message contains exactly the query id. |
| 819 | - Otherwise, it checks if the `query_id` part in the actual error message matches the |
| 820 | format using the regular expression. |
| 821 | |
| 822 | `expected_msg` may also be an array of strings, in which case the function checks |
| 823 | whether the actual error message starts with any of the strings in the array. |
| 824 | |
| 825 | NOTE: Messages of errors such as "Invalid session id" do not contain a query id |
| 826 | since such an error may occur before a query id is generated. |
| 827 | """ |
| 828 | if query_id is not None: |
| 829 | ERROR_PROMPT = "Query " + query_id + " failed:\n" |
| 830 | start = actual_msg.find(ERROR_PROMPT) |
| 831 | if start == -1: |
| 832 | return False |
| 833 | start += len(ERROR_PROMPT) |
| 834 | else: |
| 835 | ERROR_PROMPT = "Query " + QUERY_ID_REGEX + " failed:\n" |
| 836 | m = re.search(ERROR_PROMPT, actual_msg) |
| 837 | if m is None: |
| 838 | return False |
| 839 | start = m.end() |
| 840 | for msg in expected_msg if isinstance(expected_msg, list) else [expected_msg]: |
| 841 | if actual_msg.startswith(msg, start): |
| 842 | return True |
| 843 | return False |
| 844 | |
| 845 | |
| 846 | def error_msg_equal(msg1, msg2): |
no test coverage detected