Simple Impala Shell. Implements the context manager interface to ensure client connections and sessions are cleanly torn down. ImpalaShell instances should be used within a "with" statement to ensure correct teardown. Basic usage: type connect to connect to an impalad Then i
| 141 | |
| 142 | # Py3 method resolution order requires 'object' to be last w/ multiple inheritance |
| 143 | class ImpalaShell(cmd.Cmd, object): |
| 144 | """ Simple Impala Shell. |
| 145 | |
| 146 | Implements the context manager interface to ensure client connections and sessions |
| 147 | are cleanly torn down. ImpalaShell instances should be used within a "with" statement |
| 148 | to ensure correct teardown. |
| 149 | |
| 150 | Basic usage: type connect <host:port> to connect to an impalad |
| 151 | Then issue queries or other commands. Tab-completion should show the set of |
| 152 | available commands. |
| 153 | Methods that implement shell commands return a boolean tuple (stop, status) |
| 154 | stop is a flag the command loop uses to continue/discontinue the prompt. |
| 155 | Status tells the caller that the command completed successfully. |
| 156 | """ |
| 157 | |
| 158 | # NOTE: These variables are centrally defined for reuse, but they are also |
| 159 | # used directly in several tests to verify shell behavior (e.g. to |
| 160 | # verify that the shell remained connected or the shell connected |
| 161 | # successfully). |
| 162 | |
| 163 | # If not connected to an impalad, the server version is unknown. |
| 164 | UNKNOWN_SERVER_VERSION = "Not Connected" |
| 165 | PROMPT_FORMAT = "[{host}:{port}] {db}> " |
| 166 | DISCONNECTED_PROMPT = "[Not connected] > " |
| 167 | # Message to display when the connection failed and it is reconnecting. |
| 168 | CONNECTION_LOST_MESSAGE = 'Connection lost, reconnecting...' |
| 169 | # Message to display when there is an exception when connecting. |
| 170 | ERROR_CONNECTING_MESSAGE = "Error connecting " |
| 171 | # Message to display when there is a socket error. |
| 172 | SOCKET_ERROR_MESSAGE = "Socket error" |
| 173 | # Message to display upon successful connection to an Impalad |
| 174 | CONNECTED_TO_MESSAGE = "Connected to" |
| 175 | # Message to display in shell when cancelling a query |
| 176 | CANCELLATION_MESSAGE = ' Cancelling Query' |
| 177 | # Number of times to attempt cancellation before giving up. |
| 178 | CANCELLATION_TRIES = 3 |
| 179 | # Commands are terminated with the following delimiter. |
| 180 | CMD_DELIM = ';' |
| 181 | # Valid variable name pattern |
| 182 | VALID_VAR_NAME_PATTERN = r'[A-Za-z][A-Za-z0-9_]*' |
| 183 | # Pattern for removal of comments preceding SET commands |
| 184 | COMMENTS_BEFORE_SET_PATTERN = r'^(\s*/\*(.|\n)*?\*/|\s*--.*\n)*\s*((un)?set)' |
| 185 | COMMENTS_BEFORE_SET_REPLACEMENT = r'\3' |
| 186 | # Variable names are prefixed with the following string |
| 187 | VAR_PREFIXES = ['VAR', 'HIVEVAR'] |
| 188 | DEFAULT_DB = 'default' |
| 189 | # Regex applied to all tokens of a query to detect DML statements. |
| 190 | DML_REGEX = re.compile("^(insert|upsert|update|delete)$", re.I) |
| 191 | # Seperator for queries in the history file. |
| 192 | HISTORY_FILE_QUERY_DELIM = '_IMP_DELIM_' |
| 193 | # Strings that are interpreted as True for some shell options. |
| 194 | TRUE_STRINGS = ("true", "TRUE", "True", "1") |
| 195 | # List of quit commands |
| 196 | QUIT_COMMANDS = ("quit", "exit") |
| 197 | |
| 198 | VALID_SHELL_OPTIONS = { |
| 199 | 'LIVE_PROGRESS': (lambda x: x in ImpalaShell.TRUE_STRINGS, "live_progress"), |
| 200 | 'LIVE_SUMMARY': (lambda x: x in ImpalaShell.TRUE_STRINGS, "live_summary"), |
no outgoing calls
no test coverage detected