Search in sources :

Example 6 with NestedScriptParser

use of org.apache.hadoop.hive.metastore.tools.schematool.HiveSchemaHelper.NestedScriptParser in project hive by apache.

the class MetastoreSchemaTool method init.

@VisibleForTesting
public void init(String metastoreHome, String[] args, OptionGroup additionalOptions, Configuration conf) throws HiveMetaException {
    try {
        cmdLine = new SchemaToolCommandLine(args, additionalOptions);
    } catch (ParseException e) {
        System.err.println("Failed to parse command line. ");
        throw new HiveMetaException(e);
    }
    if (metastoreHome == null || metastoreHome.isEmpty()) {
        throw new HiveMetaException("No Metastore home directory provided");
    }
    this.conf = conf;
    this.dbType = cmdLine.getDbType();
    this.metaDbType = cmdLine.getMetaDbType();
    NestedScriptParser parser = getDbCommandParser(dbType, metaDbType);
    this.needsQuotedIdentifier = parser.needsQuotedIdentifier();
    this.quoteCharacter = parser.getQuoteCharacter();
    this.metaStoreSchemaInfo = MetaStoreSchemaInfoFactory.get(conf, metastoreHome, dbType);
    // It is overridden by command line options if passed (-url and -driver)
    if (dbType.equalsIgnoreCase(HiveSchemaHelper.DB_HIVE)) {
        this.url = HiveSchemaHelper.EMBEDDED_HS2_URL;
        this.driver = HiveSchemaHelper.HIVE_JDBC_DRIVER;
    }
    if (cmdLine.hasOption("userName")) {
        setUserName(cmdLine.getOptionValue("userName"));
    } else {
        setUserName(getConf().get(MetastoreConf.ConfVars.CONNECTION_USER_NAME.getVarname()));
    }
    if (cmdLine.hasOption("passWord")) {
        setPassWord(cmdLine.getOptionValue("passWord"));
    } else {
        try {
            setPassWord(MetastoreConf.getPassword(getConf(), ConfVars.PWD));
        } catch (IOException err) {
            throw new HiveMetaException("Error getting metastore password", err);
        }
    }
    if (cmdLine.hasOption("url")) {
        setUrl(cmdLine.getOptionValue("url"));
    }
    if (cmdLine.hasOption("driver")) {
        setDriver(cmdLine.getOptionValue("driver"));
    }
    if (cmdLine.hasOption("dryRun")) {
        setDryRun(true);
    }
    if (cmdLine.hasOption("verbose")) {
        setVerbose(true);
    }
    if (cmdLine.hasOption("dbOpts")) {
        setDbOpts(cmdLine.getOptionValue("dbOpts"));
    }
    if (cmdLine.hasOption("validate") && cmdLine.hasOption("servers")) {
        setValidationServers(cmdLine.getOptionValue("servers"));
    }
    if (cmdLine.hasOption("hiveUser")) {
        setHiveUser(cmdLine.getOptionValue("hiveUser"));
    }
    if (cmdLine.hasOption("hivePassword")) {
        setHivePasswd(cmdLine.getOptionValue("hivePassword"));
    }
    if (cmdLine.hasOption("hiveDb")) {
        setHiveDb(cmdLine.getOptionValue("hiveDb"));
    }
}
Also used : HiveMetaException(org.apache.hadoop.hive.metastore.HiveMetaException) ParseException(org.apache.commons.cli.ParseException) IOException(java.io.IOException) NestedScriptParser(org.apache.hadoop.hive.metastore.tools.schematool.HiveSchemaHelper.NestedScriptParser) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

NestedScriptParser (org.apache.hadoop.hive.metastore.tools.schematool.HiveSchemaHelper.NestedScriptParser)6 File (java.io.File)5 Test (org.junit.Test)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 IOException (java.io.IOException)2 HiveMetaException (org.apache.hadoop.hive.metastore.HiveMetaException)2 BufferedReader (java.io.BufferedReader)1 BufferedWriter (java.io.BufferedWriter)1 FileReader (java.io.FileReader)1 FileWriter (java.io.FileWriter)1 SQLException (java.sql.SQLException)1 SQLFeatureNotSupportedException (java.sql.SQLFeatureNotSupportedException)1 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 ParseException (org.apache.commons.cli.ParseException)1