/** * Provides a mechanism to run SQL scripts against, where the arguments are: 1) connection URL * string 2) one or more paths to either SQL scripts or CSV files If a CurrentSCN property is set * on the connection URL, then it is incremented between processing, with each file being * processed by a new connection at the increment timestamp value. */ public static void main(String[] args) { ExecutionCommand execCmd = ExecutionCommand.parseArgs(args); String jdbcUrl = JDBC_PROTOCOL + JDBC_PROTOCOL_SEPARATOR + execCmd.getConnectionString(); PhoenixConnection conn = null; try { Properties props = new Properties(); conn = DriverManager.getConnection(jdbcUrl, props).unwrap(PhoenixConnection.class); for (String inputFile : execCmd.getInputFiles()) { if (inputFile.endsWith(SQL_FILE_EXT)) { PhoenixRuntime.executeStatements( conn, new FileReader(inputFile), Collections.emptyList()); } else if (inputFile.endsWith(CSV_FILE_EXT)) { String tableName = execCmd.getTableName(); if (tableName == null) { tableName = SchemaUtil.normalizeIdentifier( inputFile.substring( inputFile.lastIndexOf(File.separatorChar) + 1, inputFile.length() - CSV_FILE_EXT.length())); } CSVCommonsLoader csvLoader = new CSVCommonsLoader( conn, tableName, execCmd.getColumns(), execCmd.isStrict(), execCmd.getFieldDelimiter(), execCmd.getQuoteCharacter(), execCmd.getEscapeCharacter(), execCmd.getArrayElementSeparator()); csvLoader.upsert(inputFile); } } } catch (Throwable t) { t.printStackTrace(); } finally { if (conn != null) { try { conn.close(); } catch (SQLException e) { // going to shut jvm down anyway. So might as well feast on it. } } System.exit(0); } }