use of org.apache.hive.beeline.hs2connection.BeelineSiteParseException in project hive by apache.
the class BeeLine method getDefaultConnectionUrl.
private String getDefaultConnectionUrl(CommandLine cl) throws BeelineConfFileParseException {
Properties mergedConnectionProperties = new Properties();
JdbcConnectionParams jdbcConnectionParams = null;
BeelineSiteParser beelineSiteParser = getUserBeelineSiteParser();
UserHS2ConnectionFileParser userHS2ConnFileParser = getUserHS2ConnFileParser();
Properties userConnectionProperties = new Properties();
if (!userHS2ConnFileParser.configExists() && !beelineSiteParser.configExists()) {
// or beeline-site.xml in the path
return null;
}
if (beelineSiteParser.configExists()) {
String urlFromCommandLineOption = cl.getOptionValue("u");
if (urlFromCommandLineOption != null) {
throw new BeelineSiteParseException("Not using beeline-site.xml since the user provided the url: " + urlFromCommandLineOption);
}
// Get the named url from user specific config file if present
Properties userNamedConnectionURLs = beelineSiteParser.getConnectionProperties();
if (!userNamedConnectionURLs.isEmpty()) {
String urlName = cl.getOptionValue("c");
String jdbcURL = HS2ConnectionFileUtils.getNamedUrl(userNamedConnectionURLs, urlName);
if (jdbcURL != null) {
try {
jdbcConnectionParams = Utils.extractURLComponents(jdbcURL, new Properties());
} catch (JdbcUriParseException e) {
throw new BeelineSiteParseException("Error in parsing jdbc url: " + jdbcURL + " from beeline-site.xml", e);
}
}
}
}
if (userHS2ConnFileParser.configExists()) {
// get the connection properties from user specific config file
userConnectionProperties = userHS2ConnFileParser.getConnectionProperties();
}
if (jdbcConnectionParams != null) {
String userName = cl.getOptionValue("n");
if (userName != null) {
jdbcConnectionParams.getSessionVars().put(JdbcConnectionParams.AUTH_USER, userName);
}
String password = cl.getOptionValue("p");
if (password != null) {
jdbcConnectionParams.getSessionVars().put(JdbcConnectionParams.AUTH_PASSWD, password);
}
String auth = cl.getOptionValue("a");
if (auth != null) {
jdbcConnectionParams.getSessionVars().put(JdbcConnectionParams.AUTH_TYPE, auth);
}
mergedConnectionProperties = HS2ConnectionFileUtils.mergeUserConnectionPropertiesAndBeelineSite(userConnectionProperties, jdbcConnectionParams);
} else {
mergedConnectionProperties = userConnectionProperties;
}
// load the HS2 connection url properties from hive-site.xml if it is present in the classpath
HS2ConnectionFileParser hiveSiteParser = getHiveSiteHS2ConnectionFileParser();
Properties hiveSiteConnectionProperties = hiveSiteParser.getConnectionProperties();
// add/override properties found from hive-site with user-specific properties
for (String key : mergedConnectionProperties.stringPropertyNames()) {
if (hiveSiteConnectionProperties.containsKey(key)) {
debug("Overriding connection url property " + key + " from user connection configuration file");
}
hiveSiteConnectionProperties.setProperty(key, mergedConnectionProperties.getProperty(key));
}
// return the url based on the aggregated connection properties
return HS2ConnectionFileUtils.getUrl(hiveSiteConnectionProperties);
}
Aggregations