diff --git beeline/src/java/org/apache/hive/beeline/HiveSchemaHelper.java beeline/src/java/org/apache/hive/beeline/HiveSchemaHelper.java index a21fa652e9c1aa3fd763afa4136f6fcb7c7b7459..5bbc300337d9016b933c0aaba859b9209ab5905c 100644 --- beeline/src/java/org/apache/hive/beeline/HiveSchemaHelper.java +++ beeline/src/java/org/apache/hive/beeline/HiveSchemaHelper.java @@ -17,7 +17,15 @@ */ package org.apache.hive.beeline; +import com.google.common.collect.Lists; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.sql.Connection; import java.util.IllegalFormatException; +import java.util.List; public class HiveSchemaHelper { public static final String DB_DERBY = "derby"; @@ -57,7 +65,7 @@ public boolean isNestedScript(String dbCommand); /*** - * Find if the given command is should be passed to DB + * Find if the given command should not be passed to DB * @param dbCommand * @return */ @@ -80,8 +88,16 @@ * @return */ public boolean needsQuotedIdentifier(); - } + /*** + * Flatten the nested upgrade script into a buffer + * @param scriptDir upgrade script directory + * @param scriptFile upgrade script file + * @return string of sql commands + */ + public String buildCommand(String scriptDir, String scriptFile) + throws IllegalFormatException, IOException; + } /*** * Base implemenation of NestedScriptParser @@ -89,6 +105,13 @@ * */ private static abstract class AbstractCommandParser implements NestedScriptParser { + private List dbOpts; + private Connection metastoreConn; + + public AbstractCommandParser(String dbOpts, Connection metastoreConn) { + setDbOpts(dbOpts); + this.metastoreConn = metastoreConn; + } @Override public boolean isPartialCommand(String dbCommand) throws IllegalArgumentException{ @@ -127,13 +150,75 @@ public String cleanseCommand(String dbCommand) { public boolean needsQuotedIdentifier() { return false; } - } + @Override + public String buildCommand( + String scriptDir, String scriptFile) throws IllegalFormatException, IOException { + BufferedReader bfReader = + new BufferedReader(new FileReader(scriptDir + File.separatorChar + scriptFile)); + String currLine; + StringBuilder sb = new StringBuilder(); + String currentCommand = null; + while ((currLine = bfReader.readLine()) != null) { + currLine = currLine.trim(); + if (currLine.isEmpty()) { + continue; // skip empty lines + } + + if (currentCommand == null) { + currentCommand = currLine; + } else { + currentCommand = currentCommand + " " + currLine; + } + if (isPartialCommand(currLine)) { + // if its a partial line, continue collecting the pieces + continue; + } + + // if this is a valid executable command then add it to the buffer + if (!isNonExecCommand(currentCommand)) { + currentCommand = cleanseCommand(currentCommand); + + if (isNestedScript(currentCommand)) { + // if this is a nested sql script then flatten it + String currScript = getScriptName(currentCommand); + sb.append(buildCommand(scriptDir, currScript)); + } else { + // Now we have a complete statement, process it + // write the line to buffer + sb.append(currentCommand); + sb.append(System.getProperty("line.separator")); + } + } + currentCommand = null; + } + bfReader.close(); + return sb.toString(); + } + + private void setDbOpts(String dbOpts) { + if (dbOpts != null) { + this.dbOpts = Lists.newArrayList(dbOpts.split(",")); + } + } + + protected List getDbOpts() { + return dbOpts; + } + + protected Connection getMetastoreConnection() { + return metastoreConn; + } + } // Derby commandline parser public static class DerbyCommandParser extends AbstractCommandParser { private static String DERBY_NESTING_TOKEN = "RUN"; + public DerbyCommandParser(String dbOpts, Connection metastoreConn) { + super(dbOpts, metastoreConn); + } + @Override public String getScriptName(String dbCommand) throws IllegalArgumentException { @@ -161,6 +246,10 @@ public boolean isNestedScript(String dbCommand) { private static final String DELIMITER_TOKEN = "DELIMITER"; private String delimiter = DEFAUTL_DELIMITER; + public MySqlCommandParser(String dbOpts, Connection metastoreConn) { + super(dbOpts, metastoreConn); + } + @Override public boolean isPartialCommand(String dbCommand) throws IllegalArgumentException{ boolean isPartial = super.isPartialCommand(dbCommand); @@ -213,6 +302,10 @@ public String cleanseCommand(String dbCommand) { public static class PostgresCommandParser extends AbstractCommandParser { private static String POSTGRES_NESTING_TOKEN = "\\i"; + public PostgresCommandParser(String dbOpts, Connection metastoreConn) { + super(dbOpts, metastoreConn); + } + @Override public String getScriptName(String dbCommand) throws IllegalArgumentException { String[] tokens = dbCommand.split(" "); @@ -237,6 +330,11 @@ public boolean needsQuotedIdentifier() { //Oracle specific parser public static class OracleCommandParser extends AbstractCommandParser { private static String ORACLE_NESTING_TOKEN = "@"; + + public OracleCommandParser(String dbOpts, Connection metastoreConn) { + super(dbOpts, metastoreConn); + } + @Override public String getScriptName(String dbCommand) throws IllegalArgumentException { if (!isNestedScript(dbCommand)) { @@ -255,6 +353,11 @@ public boolean isNestedScript(String dbCommand) { //MSSQL specific parser public static class MSSQLCommandParser extends AbstractCommandParser { private static String MSSQL_NESTING_TOKEN = ":r"; + + public MSSQLCommandParser(String dbOpts, Connection metastoreConn) { + super(dbOpts, metastoreConn); + } + @Override public String getScriptName(String dbCommand) throws IllegalArgumentException { String[] tokens = dbCommand.split(" "); @@ -270,17 +373,18 @@ public boolean isNestedScript(String dbCommand) { } } - public static NestedScriptParser getDbCommandParser(String dbName) { + public static NestedScriptParser getDbCommandParser(String dbName, + String dbOpts, Connection metastoreConn) { if (dbName.equalsIgnoreCase(DB_DERBY)) { - return new DerbyCommandParser(); + return new DerbyCommandParser(dbOpts, metastoreConn); } else if (dbName.equalsIgnoreCase(DB_MSSQL)) { - return new MSSQLCommandParser(); + return new MSSQLCommandParser(dbOpts, metastoreConn); } else if (dbName.equalsIgnoreCase(DB_MYSQL)) { - return new MySqlCommandParser(); + return new MySqlCommandParser(dbOpts, metastoreConn); } else if (dbName.equalsIgnoreCase(DB_POSTGRACE)) { - return new PostgresCommandParser(); + return new PostgresCommandParser(dbOpts, metastoreConn); } else if (dbName.equalsIgnoreCase(DB_ORACLE)) { - return new OracleCommandParser(); + return new OracleCommandParser(dbOpts, metastoreConn); } else { throw new IllegalArgumentException("Unknown dbType " + dbName); } diff --git beeline/src/java/org/apache/hive/beeline/HiveSchemaTool.java beeline/src/java/org/apache/hive/beeline/HiveSchemaTool.java index c376687cb47332323912e4c6dbe713b7b37ae834..70f15842add6c2ac1d43d6b8fae491ab2de6de78 100644 --- beeline/src/java/org/apache/hive/beeline/HiveSchemaTool.java +++ beeline/src/java/org/apache/hive/beeline/HiveSchemaTool.java @@ -17,10 +17,8 @@ */ package org.apache.hive.beeline; -import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; -import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.PrintStream; @@ -30,7 +28,6 @@ import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; -import java.util.IllegalFormatException; import java.util.List; import org.apache.commons.cli.CommandLine; @@ -56,6 +53,7 @@ private String passWord = null; private boolean dryRun = false; private boolean verbose = false; + private String dbOpts = null; private final HiveConf hiveConf; private final String dbType; private final MetaStoreSchemaInfo metaStoreSchemaInfo; @@ -101,6 +99,14 @@ public void setVerbose(boolean verbose) { this.verbose = verbose; } + public String getDbOpts() { + return dbOpts; + } + + public void setDbOpts(String dbOpts) { + this.dbOpts = dbOpts; + } + private static void printAndExit(Options cmdLineOptions) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("schemaTool", cmdLineOptions); @@ -123,7 +129,8 @@ public void showInfo() throws HiveMetaException { private String getMetaStoreSchemaVersion(Connection metastoreConn) throws HiveMetaException { String versionQuery; - if (HiveSchemaHelper.getDbCommandParser(dbType).needsQuotedIdentifier()) { + if (HiveSchemaHelper.getDbCommandParser(dbType, null, metastoreConn) + .needsQuotedIdentifier()) { versionQuery = "select t.\"SCHEMA_VERSION\" from \"VERSION\" t"; } else { versionQuery = "select t.SCHEMA_VERSION from VERSION t"; @@ -240,6 +247,7 @@ public void doUpgrade(String fromSchemaVer) throws HiveMetaException { for (String scriptFile : upgradeScripts) { System.out.println("Upgrade script " + scriptFile); if (!dryRun) { + runPreUpgrade(scriptDir, scriptFile); runBeeLine(scriptDir, scriptFile); System.out.println("Completed " + scriptFile); } @@ -291,58 +299,46 @@ public void doInit(String toVersion) throws HiveMetaException { } } - // Flatten the nested upgrade script into a buffer - public static String buildCommand(NestedScriptParser dbCommandParser, - String scriptDir, String scriptFile) throws IllegalFormatException, IOException { - - BufferedReader bfReader = - new BufferedReader(new FileReader(scriptDir + File.separatorChar + scriptFile)); - String currLine; - StringBuilder sb = new StringBuilder(); - String currentCommand = null; - while ((currLine = bfReader.readLine()) != null) { - currLine = currLine.trim(); - if (currLine.isEmpty()) { - continue; // skip empty lines - } - - if (currentCommand == null) { - currentCommand = currLine; - } else { - currentCommand = currentCommand + " " + currLine; - } - if (dbCommandParser.isPartialCommand(currLine)) { - // if its a partial line, continue collecting the pieces - continue; + /** + * Run pre-upgrade scripts corresponding to a given upgrade script, + * if any exist. The errors from pre-upgrade are ignored. + * Pre-upgrade scripts typically contain setup statements which + * may fail on some database versions and failure is ignorable. + * + * @param scriptDir upgrade script directory name + * @param scriptFile upgrade script file name + */ + private void runPreUpgrade(String scriptDir, String scriptFile) { + for (int i = 0;; i++) { + String preUpgradeScript = + MetaStoreSchemaInfo.getPreUpgradeScriptName(i, scriptFile); + File preUpgradeScriptFile = new File(scriptDir, preUpgradeScript); + if (!preUpgradeScriptFile.isFile()) { + break; } - // if this is a valid executable command then add it to the buffer - if (!dbCommandParser.isNonExecCommand(currentCommand)) { - currentCommand = dbCommandParser.cleanseCommand(currentCommand); - - if (dbCommandParser.isNestedScript(currentCommand)) { - // if this is a nested sql script then flatten it - String currScript = dbCommandParser.getScriptName(currentCommand); - sb.append(buildCommand(dbCommandParser, scriptDir, currScript)); - } else { - // Now we have a complete statement, process it - // write the line to buffer - sb.append(currentCommand); - sb.append(System.getProperty("line.separator")); + try { + runBeeLine(scriptDir, preUpgradeScript); + System.out.println("Completed " + preUpgradeScript); + } catch (Exception e) { + // Ignore the pre-upgrade script errors + System.err.println("Warning in pre-upgrade script " + preUpgradeScript + ": " + + e.getMessage()); + if (verbose) { + e.printStackTrace(); } } - currentCommand = null; } - bfReader.close(); - return sb.toString(); } - // run beeline on the given metastore scrip, flatten the nested scripts into single file - private void runBeeLine(String scriptDir, String scriptFile) throws IOException { + // run beeline on the given metastore script, flatten the nested scripts into single file + private void runBeeLine(String scriptDir, String scriptFile) + throws IOException, HiveMetaException { NestedScriptParser dbCommandParser = - HiveSchemaHelper.getDbCommandParser(dbType); + HiveSchemaHelper.getDbCommandParser(dbType, getDbOpts(), + getConnectionToMetastore(false)); // expand the nested script - String sqlCommands = buildCommand(dbCommandParser, scriptDir, scriptFile); + String sqlCommands = dbCommandParser.buildCommand(scriptDir, scriptFile); File tmpFile = File.createTempFile("schematool", ".sql"); tmpFile.deleteOnExit(); @@ -423,6 +419,9 @@ private static void initOptions(Options cmdLineOptions) { Option dbTypeOpt = OptionBuilder.withArgName("databaseType") .hasArgs().withDescription("Metastore database type") .create("dbType"); + Option dbOpts = OptionBuilder.withArgName("databaseOpts") + .hasArgs().withDescription("Backend DB specific options") + .create("dbOpts"); Option dryRunOpt = new Option("dryRun", "list SQL scripts (no execute)"); Option verboseOpt = new Option("verbose", "only print SQL statements"); @@ -432,6 +431,7 @@ private static void initOptions(Options cmdLineOptions) { cmdLineOptions.addOption(passwdOpt); cmdLineOptions.addOption(dbTypeOpt); cmdLineOptions.addOption(verboseOpt); + cmdLineOptions.addOption(dbOpts); cmdLineOptions.addOptionGroup(optGroup); } @@ -488,7 +488,9 @@ public static void main(String[] args) { if (line.hasOption("verbose")) { schemaTool.setVerbose(true); } - + if (line.hasOption("dbOpts")) { + schemaTool.setDbOpts(line.getOptionValue("dbOpts")); + } if (line.hasOption("info")) { schemaTool.showInfo(); } else if (line.hasOption("upgradeSchema")) { diff --git itests/hive-unit/src/test/java/org/apache/hive/beeline/TestSchemaTool.java itests/hive-unit/src/test/java/org/apache/hive/beeline/TestSchemaTool.java index 749fb9e86b4f74f768da356cf82f621fdef399cd..b3107aba527f4acf5125915d9d47fb0315c20eb9 100644 --- itests/hive-unit/src/test/java/org/apache/hive/beeline/TestSchemaTool.java +++ itests/hive-unit/src/test/java/org/apache/hive/beeline/TestSchemaTool.java @@ -19,9 +19,12 @@ package org.apache.hive.beeline; import java.io.BufferedWriter; +import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileWriter; import java.io.IOException; +import java.io.OutputStream; +import java.io.PrintStream; import java.util.Random; import junit.framework.TestCase; @@ -31,14 +34,14 @@ import org.apache.hadoop.hive.conf.HiveConf; import org.apache.hadoop.hive.metastore.HiveMetaException; import org.apache.hadoop.hive.metastore.MetaStoreSchemaInfo; -import org.apache.hive.beeline.HiveSchemaHelper; import org.apache.hive.beeline.HiveSchemaHelper.NestedScriptParser; -import org.apache.hive.beeline.HiveSchemaTool; public class TestSchemaTool extends TestCase { private HiveSchemaTool schemaTool; private HiveConf hiveConf; private String testMetastoreDB; + private PrintStream errStream; + private PrintStream outStream; @Override protected void setUp() throws Exception { @@ -48,8 +51,11 @@ protected void setUp() throws Exception { System.setProperty(HiveConf.ConfVars.METASTORECONNECTURLKEY.varname, "jdbc:derby:" + testMetastoreDB + ";create=true"); hiveConf = new HiveConf(this.getClass()); - schemaTool = new HiveSchemaTool(System.getProperty("test.tmp.dir"), hiveConf, "derby"); + schemaTool = new HiveSchemaTool( + System.getProperty("test.tmp.dir", "target/tmp"), hiveConf, "derby"); System.setProperty("beeLine.system.exit", "true"); + errStream = System.err; + outStream = System.out; } @Override @@ -58,6 +64,8 @@ protected void tearDown() throws Exception { if (metaStoreDir.exists()) { FileUtils.forceDeleteOnExit(metaStoreDir); } + System.setOut(outStream); + System.setErr(errStream); } /** @@ -121,12 +129,42 @@ public void testSchemaUpgrade() throws Exception { foundException = true; } if (!foundException) { - throw new Exception("Hive operations shouldn't pass with older version schema"); + throw new Exception( + "Hive operations shouldn't pass with older version schema"); } - // upgrade schema from 0.7.0 to latest + // Generate dummy pre-upgrade script with errors + String invalidPreUpgradeScript = writeDummyPreUpgradeScript( + 0, "upgrade-0.11.0-to-0.12.0.derby.sql", "foo bar;"); + // Generate dummy pre-upgrade scripts with valid SQL + String validPreUpgradeScript0 = writeDummyPreUpgradeScript( + 0, "upgrade-0.12.0-to-0.13.0.derby.sql", + "CREATE TABLE schema_test0 (id integer);"); + String validPreUpgradeScript1 = writeDummyPreUpgradeScript( + 1, "upgrade-0.12.0-to-0.13.0.derby.sql", + "CREATE TABLE schema_test1 (id integer);"); + + // Capture system out and err + schemaTool.setVerbose(true); + OutputStream stderr = new ByteArrayOutputStream(); + PrintStream errPrintStream = new PrintStream(stderr); + System.setErr(errPrintStream); + OutputStream stdout = new ByteArrayOutputStream(); + PrintStream outPrintStream = new PrintStream(stdout); + System.setOut(outPrintStream); + + // Upgrade schema from 0.7.0 to latest schemaTool.doUpgrade("0.7.0"); - // verify that driver works fine with latest schema + + // Verify that the schemaTool ran pre-upgrade scripts and ignored errors + assertTrue(stderr.toString().contains(invalidPreUpgradeScript)); + assertTrue(stderr.toString().contains("foo")); + assertFalse(stderr.toString().contains(validPreUpgradeScript0)); + assertFalse(stderr.toString().contains(validPreUpgradeScript1)); + assertTrue(stdout.toString().contains(validPreUpgradeScript0)); + assertTrue(stdout.toString().contains(validPreUpgradeScript1)); + + // Verify that driver works fine with latest schema schemaTool.verifySchemaVersion(); } @@ -152,9 +190,9 @@ public void testScripts() throws Exception { String expectedSQL = StringUtils.join(resultScript, System.getProperty("line.separator")) + System.getProperty("line.separator"); File testScriptFile = generateTestScript(testScript); - String flattenedSql = HiveSchemaTool.buildCommand( - HiveSchemaHelper.getDbCommandParser("derby"), - testScriptFile.getParentFile().getPath(), testScriptFile.getName()); + String flattenedSql = HiveSchemaHelper.getDbCommandParser("derby", null, null) + .buildCommand(testScriptFile.getParentFile().getPath(), + testScriptFile.getName()); assertEquals(expectedSQL, flattenedSql); } @@ -194,9 +232,9 @@ public void testNestedScriptsForDerby() throws Exception { }; File testScriptFile = generateTestScript(parentTestScript); - String flattenedSql = HiveSchemaTool.buildCommand( - HiveSchemaHelper.getDbCommandParser("derby"), - testScriptFile.getParentFile().getPath(), testScriptFile.getName()); + String flattenedSql = HiveSchemaHelper.getDbCommandParser("derby", null, null) + .buildCommand(testScriptFile.getParentFile().getPath(), + testScriptFile.getName()); assertFalse(flattenedSql.contains("RUN")); assertFalse(flattenedSql.contains("comment")); assertTrue(flattenedSql.contains(childTab1)); @@ -239,9 +277,9 @@ public void testNestedScriptsForMySQL() throws Exception { }; File testScriptFile = generateTestScript(parentTestScript); - String flattenedSql = HiveSchemaTool.buildCommand( - HiveSchemaHelper.getDbCommandParser("mysql"), - testScriptFile.getParentFile().getPath(), testScriptFile.getName()); + String flattenedSql = HiveSchemaHelper.getDbCommandParser("mysql", null, null) + .buildCommand(testScriptFile.getParentFile().getPath(), + testScriptFile.getName()); assertFalse(flattenedSql.contains("RUN")); assertFalse(flattenedSql.contains("comment")); assertTrue(flattenedSql.contains(childTab1)); @@ -281,9 +319,9 @@ public void testScriptWithDelimiter() throws Exception { String expectedSQL = StringUtils.join(resultScript, System.getProperty("line.separator")) + System.getProperty("line.separator"); File testScriptFile = generateTestScript(testScript); - NestedScriptParser testDbParser = HiveSchemaHelper.getDbCommandParser("mysql"); - String flattenedSql = HiveSchemaTool.buildCommand(testDbParser, - testScriptFile.getParentFile().getPath(), testScriptFile.getName()); + NestedScriptParser testDbParser = HiveSchemaHelper.getDbCommandParser("mysql", null, null); + String flattenedSql = testDbParser.buildCommand(testScriptFile.getParentFile().getPath(), + testScriptFile.getName()); assertEquals(expectedSQL, flattenedSql); } @@ -316,9 +354,9 @@ public void testScriptMultiRowComment() throws Exception { String expectedSQL = StringUtils.join(parsedScript, System.getProperty("line.separator")) + System.getProperty("line.separator"); File testScriptFile = generateTestScript(testScript); - NestedScriptParser testDbParser = HiveSchemaHelper.getDbCommandParser("mysql"); - String flattenedSql = HiveSchemaTool.buildCommand(testDbParser, - testScriptFile.getParentFile().getPath(), testScriptFile.getName()); + NestedScriptParser testDbParser = HiveSchemaHelper.getDbCommandParser("mysql", null, null); + String flattenedSql = testDbParser.buildCommand(testScriptFile.getParentFile().getPath(), + testScriptFile.getName()); assertEquals(expectedSQL, flattenedSql); } @@ -358,9 +396,9 @@ public void testNestedScriptsForOracle() throws Exception { }; File testScriptFile = generateTestScript(parentTestScript); - String flattenedSql = HiveSchemaTool.buildCommand( - HiveSchemaHelper.getDbCommandParser("oracle"), - testScriptFile.getParentFile().getPath(), testScriptFile.getName()); + String flattenedSql = HiveSchemaHelper.getDbCommandParser("oracle", null, null) + .buildCommand(testScriptFile.getParentFile().getPath(), + testScriptFile.getName()); assertFalse(flattenedSql.contains("@")); assertFalse(flattenedSql.contains("comment")); assertTrue(flattenedSql.contains(childTab1)); @@ -380,4 +418,21 @@ private File generateTestScript(String [] stmts) throws IOException { out.close(); return testScriptFile; } -} + + /** + * Write out a dummy pre-upgrade script with given SQL statement. + */ + private String writeDummyPreUpgradeScript(int index, String upgradeScriptName, + String sql) throws Exception { + String preUpgradeScript = "pre-" + index + "-" + upgradeScriptName; + String dummyPreScriptPath = System.getProperty("test.tmp.dir", "target/tmp") + + File.separatorChar + "scripts" + File.separatorChar + "metastore" + + File.separatorChar + "upgrade" + File.separatorChar + "derby" + + File.separatorChar + preUpgradeScript; + FileWriter fstream = new FileWriter(dummyPreScriptPath); + BufferedWriter out = new BufferedWriter(fstream); + out.write(sql + System.getProperty("line.separator") + ";"); + out.close(); + return preUpgradeScript; + } +} \ No newline at end of file diff --git metastore/scripts/upgrade/postgres/pre-0-upgrade-0.12.0-to-0.13.0.postgres.sql metastore/scripts/upgrade/postgres/pre-0-upgrade-0.12.0-to-0.13.0.postgres.sql new file mode 100644 index 0000000000000000000000000000000000000000..bc028fbf2c7c5c14aa2ace43033da1919fb2fbb4 --- /dev/null +++ metastore/scripts/upgrade/postgres/pre-0-upgrade-0.12.0-to-0.13.0.postgres.sql @@ -0,0 +1 @@ +CREATE LANGUAGE plpgsql; diff --git metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreSchemaInfo.java metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreSchemaInfo.java index af56ef6a7c6e27ead312a68d30d94802095f2c60..50d03a83d3f88219fa7e3471396a2737d79158d5 100644 --- metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreSchemaInfo.java +++ metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreSchemaInfo.java @@ -37,6 +37,7 @@ private static String UPGRADE_FILE_PREFIX="upgrade-"; private static String INIT_FILE_PREFIX="hive-schema-"; private static String VERSION_UPGRADE_LIST = "upgrade.order"; + private static String PRE_UPGRADE_PREFIX = "pre-"; private final String dbType; private final String hiveSchemaVersions[]; private final HiveConf hiveConf; @@ -138,6 +139,10 @@ private String generateUpgradeFileName(String fileVersion) { return UPGRADE_FILE_PREFIX + fileVersion + "." + dbType + SQL_FILE_EXTENSION; } + public static String getPreUpgradeScriptName(int index, String upgradeScriptName) { + return PRE_UPGRADE_PREFIX + index + "-" + upgradeScriptName; + } + public static String getHiveSchemaVersion() { String hiveVersion = HiveVersionInfo.getShortVersion(); // if there is an equivalent version, return that, else return this version @@ -149,4 +154,4 @@ public static String getHiveSchemaVersion() { } } -} +} \ No newline at end of file