diff --git a/src/com/oltpbenchmark/benchmarks/wikipedia/WikipediaLoader.java b/src/com/oltpbenchmark/benchmarks/wikipedia/WikipediaLoader.java index b0398113e..7b1920832 100644 --- a/src/com/oltpbenchmark/benchmarks/wikipedia/WikipediaLoader.java +++ b/src/com/oltpbenchmark/benchmarks/wikipedia/WikipediaLoader.java @@ -179,7 +179,7 @@ private void loadUsers(Connection conn, int lo, int hi) throws SQLException { String sql = SQLUtil.getInsertSQL(catalog_tbl, this.getDatabaseType()); if(this.getDatabaseType() == DatabaseType.ORACLE) { // Oracle handles quoted object identifiers differently, do not escape names - sql = SQLUtil.getInsertSQL(catalog_tbl, false); + sql = SQLUtil.getInsertSQL(catalog_tbl, false, DatabaseType.ORACLE.getInsertKeyword()); } PreparedStatement userInsert = conn.prepareStatement(sql); @@ -268,7 +268,7 @@ private void loadPages(Connection conn, int lo, int hi) throws SQLException { String sql = SQLUtil.getInsertSQL(catalog_tbl, this.getDatabaseType()); if (this.getDatabaseType() == DatabaseType.ORACLE) { // Oracle handles quoted object identifiers differently, do not escape names - sql = SQLUtil.getInsertSQL(catalog_tbl, false); + sql = SQLUtil.getInsertSQL(catalog_tbl, false, DatabaseType.ORACLE.getInsertKeyword()); } PreparedStatement pageInsert = conn.prepareStatement(sql); @@ -427,7 +427,7 @@ private void loadRevision(Connection conn) throws SQLException { String textSQL = SQLUtil.getInsertSQL(textTable, this.getDatabaseType()); if (this.getDatabaseType() == DatabaseType.ORACLE) { // Oracle handles quoted object identifiers differently, do not escape names - textSQL = SQLUtil.getInsertSQL(textTable, false); + textSQL = SQLUtil.getInsertSQL(textTable, false, DatabaseType.ORACLE.getInsertKeyword()); } PreparedStatement textInsert = conn.prepareStatement(textSQL); @@ -436,7 +436,7 @@ private void loadRevision(Connection conn) throws SQLException { String revSQL = SQLUtil.getInsertSQL(revTable, this.getDatabaseType()); if (this.getDatabaseType() == DatabaseType.ORACLE) { // Oracle handles quoted object identifiers differently, do not escape names - revSQL = SQLUtil.getInsertSQL(revTable, false); + revSQL = SQLUtil.getInsertSQL(revTable, false, DatabaseType.ORACLE.getInsertKeyword()); } PreparedStatement revisionInsert = conn.prepareStatement(revSQL); diff --git a/src/com/oltpbenchmark/types/DatabaseType.java b/src/com/oltpbenchmark/types/DatabaseType.java index 499b2e3c5..28adc8e13 100644 --- a/src/com/oltpbenchmark/types/DatabaseType.java +++ b/src/com/oltpbenchmark/types/DatabaseType.java @@ -34,34 +34,37 @@ public enum DatabaseType { * (3) Should SQLUtil.getInsertSQL include col names * (4) Does this DBMS support "real" transactions? */ - DB2("com.ibm.db2.jcc.DB2Driver", true, false, true), - MYSQL("com.mysql.jdbc.Driver", true, false, true), - MYROCKS("com.mysql.jdbc.Driver", true, false, true), - POSTGRES("org.postgresql.Driver", false, false, true), - ORACLE("oracle.jdbc.driver.OracleDriver", true, false, true), - SQLSERVER("com.microsoft.sqlserver.jdbc.SQLServerDriver", true, false, true), - SQLITE("org.sqlite.JDBC", true, false, true), - AMAZONRDS(null, true, false, true), - SQLAZURE(null, true, false, true), - ASSCLOWN(null, true, false, true), - HSQLDB("org.hsqldb.jdbcDriver", false, false, true), - H2("org.h2.Driver", true, false, true), - MONETDB("nl.cwi.monetdb.jdbc.MonetDriver", false, false, true), - NUODB("com.nuodb.jdbc.Driver", true, false, true), - TIMESTEN("com.timesten.jdbc.TimesTenDriver", true, false, true), - CASSANDRA("com.github.adejanovski.cassandra.jdbc.CassandraDriver", true, true, false), - MEMSQL("com.mysql.jdbc.Driver", true, false, false), - NOISEPAGE("org.postgresql.Driver", false, false, true), + DB2("com.ibm.db2.jcc.DB2Driver", true, false, true, "INSERT"), + MYSQL("com.mysql.jdbc.Driver", true, false, true, "INSERT"), + MYROCKS("com.mysql.jdbc.Driver", true, false, true, "INSERT"), + POSTGRES("org.postgresql.Driver", false, false, true, "INSERT"), + ORACLE("oracle.jdbc.driver.OracleDriver", true, false, true, "INSERT"), + SQLSERVER("com.microsoft.sqlserver.jdbc.SQLServerDriver", true, false, true, "INSERT"), + SQLITE("org.sqlite.JDBC", true, false, true, "INSERT"), + AMAZONRDS(null, true, false, true, "INSERT" ), + SQLAZURE(null, true, false, true, "INSERT"), + ASSCLOWN(null, true, false, true, "INSERT"), + HSQLDB("org.hsqldb.jdbcDriver", false, false, true, "INSERT"), + H2("org.h2.Driver", true, false, true, "INSERT"), + MONETDB("nl.cwi.monetdb.jdbc.MonetDriver", false, false, true, "INSERT"), + NUODB("com.nuodb.jdbc.Driver", true, false, true, "INSERT"), + TIMESTEN("com.timesten.jdbc.TimesTenDriver", true, false, true, "INSERT"), + CASSANDRA("com.github.adejanovski.cassandra.jdbc.CassandraDriver", true, true, false, "INSERT"), + MEMSQL("com.mysql.jdbc.Driver", true, false, false, "INSERT"), + NOISEPAGE("org.postgresql.Driver", false, false, true, "INSERT") ; private DatabaseType(String driver, boolean escapeNames, boolean includeColNames, - boolean supportTxns) { + boolean supportTxns, + String insertKeyword) { this.driver = driver; this.escapeNames = escapeNames; this.includeColNames = includeColNames; this.supportTxns = supportTxns; + this.insertKeyword = insertKeyword; + } /** @@ -90,6 +93,13 @@ private DatabaseType(String driver, * when the framework tries to set the isolation level. */ private boolean supportTxns; + + /** + * Most of the databases use "INSERT" key word in insert statements to write data to database + * but some databases like Apache Phoenix uses "UPSERT" to combine the semantics of insert + * and update together in same query. This helps to define the insert key word used in DB. + */ + private String insertKeyword; // --------------------------------------------------------------- // ACCESSORS @@ -129,6 +139,8 @@ public boolean shouldIncludeColumnNames() { public boolean shouldUseTransactions() { return (this.supportTxns); } + + public String getInsertKeyword() { return (this.insertKeyword); } // ---------------------------------------------------------------- // STATIC METHODS + MEMBERS diff --git a/src/com/oltpbenchmark/util/SQLUtil.java b/src/com/oltpbenchmark/util/SQLUtil.java index cf9028a52..e3a2af6e4 100644 --- a/src/com/oltpbenchmark/util/SQLUtil.java +++ b/src/com/oltpbenchmark/util/SQLUtil.java @@ -338,7 +338,7 @@ public static String getCountSQL(DatabaseType dbType, Table catalog_tbl, String * @return */ public static String getInsertSQL(DatabaseType dbType, Table catalog_tbl, int...exclude_columns) { - return getInsertSQL(catalog_tbl, false, dbType.shouldEscapeNames(), 1, exclude_columns); + return getInsertSQL(catalog_tbl, false, dbType.shouldEscapeNames(), 1, dbType.getInsertKeyword(), exclude_columns); } /** @@ -347,10 +347,11 @@ public static String getInsertSQL(DatabaseType dbType, Table catalog_tbl, int... * * @param catalog_tbl Table affected * @param escape_names Flag to escape object names + * @param insertKeyword * @return */ - public static String getInsertSQL(Table catalog_tbl, boolean escape_names, int...exclude_columns) { - return getInsertSQL(catalog_tbl, false, escape_names, 1, exclude_columns); + public static String getInsertSQL(Table catalog_tbl, boolean escape_names, String insertKeyword, int...exclude_columns) { + return getInsertSQL(catalog_tbl, false, escape_names, 1, insertKeyword, exclude_columns); } /** @@ -363,7 +364,7 @@ public static String getInsertSQL(Table catalog_tbl, boolean escape_names, int.. * @return */ public static String getInsertSQL(Table catalog_tbl, DatabaseType db_type, int... exclude_columns) { - return SQLUtil.getInsertSQL(catalog_tbl, false, false, 1, exclude_columns); + return SQLUtil.getInsertSQL(catalog_tbl, false, false, 1, db_type.getInsertKeyword(), exclude_columns); } /** @@ -376,7 +377,7 @@ public static String getInsertSQL(Table catalog_tbl, DatabaseType db_type, int.. */ @Deprecated public static String getInsertSQL(Table catalog_tbl, boolean show_cols, int batchSize, int...exclude_columns) { - return getInsertSQL(catalog_tbl, false, true, batchSize, exclude_columns); + return getInsertSQL(catalog_tbl, false, true, batchSize, "INSERT", exclude_columns); } /** @@ -388,11 +389,13 @@ public static String getInsertSQL(Table catalog_tbl, boolean show_cols, int batc * the number of sets of parameters * that should be included in the insert * @param exclude_columns + * @param insertKeyword * @return */ - public static String getInsertSQL(Table catalog_tbl, boolean show_cols, boolean escape_names, int batchSize, int... exclude_columns) { + public static String getInsertSQL(Table catalog_tbl, boolean show_cols, boolean escape_names, int batchSize, String insertKeyword, int... exclude_columns) { StringBuilder sb = new StringBuilder(); - sb.append("INSERT INTO ") + sb.append(insertKeyword); + sb.append(" INTO ") .append(escape_names ? catalog_tbl.getEscapedName() : catalog_tbl.getName()); StringBuilder values = new StringBuilder();