There are two types of options: shell options and query_options. Both can be set on the command line, which override default options. Specifically, if there exists a global config file (default path: /etc/impalarc) then options are loaded from that file. If there exists a user config file (
()
| 2224 | |
| 2225 | |
| 2226 | def impala_shell_main(): |
| 2227 | """ |
| 2228 | There are two types of options: shell options and query_options. Both can be set on the |
| 2229 | command line, which override default options. Specifically, if there exists a global |
| 2230 | config file (default path: /etc/impalarc) then options are loaded from that file. If |
| 2231 | there exists a user config file (~/.impalarc), then options are loaded in from that |
| 2232 | file and override any options already loaded from the global impalarc. The default shell |
| 2233 | options come from impala_shell_config_defaults.py. Query options have no defaults within |
| 2234 | the impala-shell, but they do have defaults on the server. Query options can be also |
| 2235 | changed in impala-shell with the 'set' command. |
| 2236 | """ |
| 2237 | # pass defaults into option parser |
| 2238 | global options, parser |
| 2239 | parser = get_option_parser(impala_shell_defaults) |
| 2240 | options, args = parser.parse_args() |
| 2241 | |
| 2242 | # by default, use the impalarc in the user's home directory |
| 2243 | # and superimpose it on the global impalarc config |
| 2244 | global_config = os.path.expanduser( |
| 2245 | os.environ.get(ImpalaShell.GLOBAL_CONFIG_FILE, |
| 2246 | impala_shell_defaults['global_config_default_path'])) |
| 2247 | if os.path.isfile(global_config): |
| 2248 | # Always output the source of the global config if verbose |
| 2249 | if options.verbose: |
| 2250 | print( |
| 2251 | "Loading in options from global config file: %s \n" % global_config, |
| 2252 | file=sys.stderr) |
| 2253 | elif global_config != impala_shell_defaults['global_config_default_path']: |
| 2254 | print('%s not found.\n' % global_config, file=sys.stderr) |
| 2255 | raise FatalShellException() |
| 2256 | # Override the default user config by a custom config if necessary |
| 2257 | user_config = impala_shell_defaults.get("config_file") |
| 2258 | input_config = os.path.expanduser(options.config_file) |
| 2259 | # verify input_config, if found |
| 2260 | if input_config != user_config: |
| 2261 | if os.path.isfile(input_config): |
| 2262 | if options.verbose: |
| 2263 | print("Loading in options from config file: %s \n" % input_config, |
| 2264 | file=sys.stderr) |
| 2265 | # command line overrides loading ~/.impalarc |
| 2266 | user_config = input_config |
| 2267 | else: |
| 2268 | print('%s not found.\n' % input_config, file=sys.stderr) |
| 2269 | raise FatalShellException() |
| 2270 | configs_to_load = [global_config, user_config] |
| 2271 | |
| 2272 | # load shell and query options from the list of config files |
| 2273 | # in ascending order of precedence |
| 2274 | try: |
| 2275 | loaded_shell_options = {} |
| 2276 | query_options = {} |
| 2277 | for config_file in configs_to_load: |
| 2278 | s_options, q_options = get_config_from_file(config_file, |
| 2279 | parser.option_list) |
| 2280 | loaded_shell_options.update(s_options) |
| 2281 | query_options.update(q_options) |
| 2282 | |
| 2283 | impala_shell_defaults.update(loaded_shell_options) |
no test coverage detected