This is an automated email from the ASF dual-hosted git repository.
haridsv pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/phoenix.git
The following commit(s) were added to refs/heads/master by this push:
new 545b7e7a46 PHOENIX-7630: Return ResultSet for UPSERT with ON DUPLICATE
KEY (#2176)
545b7e7a46 is described below
commit 545b7e7a4650965a605d7521a5c9833f7d35162d
Author: Hari Krishna Dara <[email protected]>
AuthorDate: Mon Jun 16 10:32:50 2025 +0530
PHOENIX-7630: Return ResultSet for UPSERT with ON DUPLICATE KEY (#2176)
---
.../phoenix/jdbc/PhoenixPrefetchedResultSet.java | 3 +-
.../phoenix/jdbc/PhoenixPreparedStatement.java | 1 +
.../org/apache/phoenix/jdbc/PhoenixStatement.java | 30 +++---
.../java/org/apache/phoenix/util/TupleUtil.java | 21 +++++
.../java/org/apache/phoenix/end2end/Bson4IT.java | 9 +-
.../apache/phoenix/end2end/DynamicUpsertIT.java | 5 +
.../apache/phoenix/end2end/OnDuplicateKey2IT.java | 102 +++++++++------------
...T.java => UpsertBindNullParamToCaseExprIT.java} | 4 +-
.../phoenix/end2end/UpsertSelectAutoCommitIT.java | 20 +++-
.../org/apache/phoenix/end2end/UpsertSelectIT.java | 4 +
.../org/apache/phoenix/end2end/UpsertValuesIT.java | 5 +
11 files changed, 119 insertions(+), 85 deletions(-)
diff --git
a/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixPrefetchedResultSet.java
b/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixPrefetchedResultSet.java
index 5d5f0b35a5..609dbf10ac 100644
---
a/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixPrefetchedResultSet.java
+++
b/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixPrefetchedResultSet.java
@@ -42,7 +42,8 @@ public class PhoenixPrefetchedResultSet extends
PhoenixResultSet {
@Override
protected Tuple getCurrentRowImpl() {
- return prefetchedRows.get(prefetchedRowsIndex++);
+ return prefetchedRows.size() > prefetchedRowsIndex ?
prefetchedRows.get(prefetchedRowsIndex++)
+ : null;
}
}
diff --git
a/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixPreparedStatement.java
b/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixPreparedStatement.java
index 89c704fe77..ecc961f0d2 100644
---
a/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixPreparedStatement.java
+++
b/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixPreparedStatement.java
@@ -36,6 +36,7 @@ import java.sql.RowId;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.sql.SQLXML;
+import java.sql.Statement;
import java.sql.Time;
import java.sql.Timestamp;
import java.time.ZoneOffset;
diff --git
a/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixStatement.java
b/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixStatement.java
index 3f634ddece..0dea1cef21 100644
---
a/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixStatement.java
+++
b/phoenix-core-client/src/main/java/org/apache/phoenix/jdbc/PhoenixStatement.java
@@ -290,7 +290,7 @@ public class PhoenixStatement implements
PhoenixMonitoredStatement, SQLCloseable
private static final int NO_UPDATE = -1;
private static final String TABLE_UNKNOWN = "";
private QueryPlan lastQueryPlan;
- private PhoenixResultSet lastResultSet;
+ private ResultSet lastResultSet;
private int lastUpdateCount = NO_UPDATE;
private String lastUpdateTable = TABLE_UNKNOWN;
@@ -320,14 +320,6 @@ public class PhoenixStatement implements
PhoenixMonitoredStatement, SQLCloseable
QueryServicesOptions.DEFAULT_THREAD_TIMEOUT_MS);
}
- protected List<PhoenixResultSet> getResultSets() {
- if (lastResultSet != null) {
- return Collections.singletonList(lastResultSet);
- } else {
- return Collections.emptyList();
- }
- }
-
public PhoenixResultSet newResultSet(ResultIterator iterator, RowProjector
projector, StatementContext context) throws SQLException {
return new PhoenixResultSet(iterator, projector, context);
}
@@ -583,10 +575,15 @@ public class PhoenixStatement implements
PhoenixMonitoredStatement, SQLCloseable
return target;
}
+ private boolean isResultSetExpected(final CompilableStatement stmt) {
+ return stmt instanceof ExecutableUpsertStatement &&
+ ((ExecutableUpsertStatement) stmt).getOnDupKeyPairs() != null;
+ }
protected int executeMutation(final CompilableStatement stmt,
final AuditQueryLogger queryLogger) throws
SQLException {
- return executeMutation(stmt, true, queryLogger, null).getFirst();
+ return executeMutation(stmt, true, queryLogger,
+ isResultSetExpected(stmt) ? ReturnResult.ROW :
null).getFirst();
}
Pair<Integer, ResultSet> executeMutation(final CompilableStatement stmt,
@@ -691,10 +688,11 @@ public class PhoenixStatement implements
PhoenixMonitoredStatement, SQLCloseable
((ExecutableUpsertStatement)
stmt).getTable().getName() :
(isDelete ?
((ExecutableDeleteStatement) stmt)
.getTable().getName() : null);
- return new Pair<>(lastUpdateCount,
- result == null || result.isEmpty() ?
+ ResultSet rs = result == null ||
result.isEmpty() ?
null : TupleUtil.getResultSet(new
ResultTuple(result),
- tableNameVal, connection));
+ tableNameVal, connection);
+ setLastResultSet(rs);
+ return new Pair<>(lastUpdateCount, rs);
}
//Force update cache and retry if meta not found
error occurs
catch (MetaDataEntityNotFoundException e) {
@@ -2531,7 +2529,7 @@ public class PhoenixStatement implements
PhoenixMonitoredStatement, SQLCloseable
}
executeMutation(stmt, createAuditQueryLogger(stmt, sql));
flushIfNecessary();
- return false;
+ return isResultSetExpected(stmt);
}
executeQuery(stmt, createQueryLogger(stmt, sql));
@@ -2777,11 +2775,11 @@ public class PhoenixStatement implements
PhoenixMonitoredStatement, SQLCloseable
return closeOnCompletion;
}
- private PhoenixResultSet getLastResultSet() {
+ private ResultSet getLastResultSet() {
return lastResultSet;
}
- void setLastResultSet(PhoenixResultSet lastResultSet) {
+ void setLastResultSet(ResultSet lastResultSet) {
this.lastResultSet = lastResultSet;
}
diff --git
a/phoenix-core-client/src/main/java/org/apache/phoenix/util/TupleUtil.java
b/phoenix-core-client/src/main/java/org/apache/phoenix/util/TupleUtil.java
index 5b8cf86878..00ed160b24 100644
--- a/phoenix-core-client/src/main/java/org/apache/phoenix/util/TupleUtil.java
+++ b/phoenix-core-client/src/main/java/org/apache/phoenix/util/TupleUtil.java
@@ -29,10 +29,12 @@ import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.apache.hadoop.hbase.Cell;
+import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.DoNotRetryIOException;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.client.Result;
@@ -242,6 +244,25 @@ public class TupleUtil {
resultSet.getStatement().getQueryPlan().getContext().getResolver().getTables()
.get(0).getTable();
TupleProjector tupleProjector = new TupleProjector(pTable);
+ // NOTE - Tuple result projection does not work well with local
index and causes
+ // this assertion to get get triggered:
CellUtil.matchingRows(kvs[0], kvs[kvs.length-1])
+ // as the Tuple contains cells of the local index too, so filter
out those cells.
+ Cell firstCell = null;
+ List<Cell> cells = new ArrayList<>(toProject.size());
+ for (int i = 0; i < toProject.size(); ++i) {
+ Cell cell = toProject.getValue(i);
+ if (firstCell == null) {
+ firstCell = cell;
+ }
+ else {
+ if (! CellUtil.matchingRows(firstCell,
firstCell.getRowLength(), cell,
+ cell.getRowLength())) {
+ continue;
+ }
+ }
+ cells.add(cell);
+ }
+ toProject = new ResultTuple(Result.create(cells));
// Project results for ResultSet.
Tuple tuple = tupleProjector.projectResults(toProject, true);
// Use new CF:CQ that can be correctly used by ResultSet.
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/Bson4IT.java
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/Bson4IT.java
index 1d75ad6bb9..94f4fd1007 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/Bson4IT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/Bson4IT.java
@@ -855,10 +855,9 @@ public class Bson4IT extends ParallelStatsDisabledIT {
String jsonPath,
boolean success)
throws SQLException, IOException {
- Pair<Integer, ResultSet> resultPair =
-
stmt.unwrap(PhoenixPreparedStatement.class).executeAtomicUpdateReturnRow();
- assertEquals(success ? 1 : 0, resultPair.getFirst().intValue());
- ResultSet resultSet = resultPair.getSecond();
+ stmt.execute();
+ assertEquals(success ? 1 : 0, stmt.getUpdateCount());
+ ResultSet resultSet = stmt.getResultSet();
assertEquals(RawBsonDocument.parse(getJsonString(jsonPath)),
resultSet.getObject(3));
}
@@ -882,4 +881,4 @@ public class Bson4IT extends ParallelStatsDisabledIT {
assertEquals(scanType, explainPlanAttributes.getExplainScanType());
}
-}
\ No newline at end of file
+}
diff --git
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DynamicUpsertIT.java
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DynamicUpsertIT.java
index 16ccb6a7c2..a31ae5d165 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DynamicUpsertIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DynamicUpsertIT.java
@@ -20,6 +20,7 @@ package org.apache.phoenix.end2end;
import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -80,6 +81,10 @@ public class DynamicUpsertIT extends ParallelStatsDisabledIT
{
PreparedStatement statement = conn.prepareStatement(upsertquery);
int rowsInserted = statement.executeUpdate();
assertEquals(1, rowsInserted);
+ assertEquals(1, statement.getUpdateCount());
+ // When not using an UPSERT variant (e.g., ON DUPLICATE KEY) that
is not capable of
+ // returning a row, we don't expect to get a result set.
+ assertNull(statement.getResultSet());
// since the upsert does not alter the schema check with a
dynamicolumn
PreparedStatement selectStatement =
conn.prepareStatement(selectquery);
diff --git
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/OnDuplicateKey2IT.java
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/OnDuplicateKey2IT.java
index 235b235129..d29fe6b4b9 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/OnDuplicateKey2IT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/OnDuplicateKey2IT.java
@@ -50,10 +50,8 @@ import org.apache.hadoop.hbase.util.Pair;
import org.apache.hadoop.hbase.util.VersionInfo;
import org.apache.phoenix.compile.ExplainPlan;
import org.apache.phoenix.compile.ExplainPlanAttributes;
-import org.apache.phoenix.exception.SQLExceptionCode;
import org.apache.phoenix.jdbc.PhoenixConnection;
import org.apache.phoenix.jdbc.PhoenixPreparedStatement;
-import org.apache.phoenix.jdbc.PhoenixStatement;
import org.apache.phoenix.query.QueryConstants;
import org.apache.phoenix.schema.PColumn;
import org.apache.phoenix.schema.PTable;
@@ -63,7 +61,6 @@ import org.apache.phoenix.util.PhoenixRuntime;
import org.apache.phoenix.util.PropertiesUtil;
import org.bson.BsonDocument;
import org.bson.RawBsonDocument;
-import org.junit.Assert;
import org.junit.Assume;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@@ -161,10 +158,8 @@ public class OnDuplicateKey2IT extends
ParallelStatsDisabledIT {
validateAtomicUpsertReturnRow(tableName, conn, bsonDocument1,
bsonDocument2);
- PhoenixPreparedStatement ps =
- conn.prepareStatement(
- "DELETE FROM " + tableName + " WHERE PK1 = ? AND
PK2 " +
- "= ? AND PK3 =
?").unwrap(PhoenixPreparedStatement.class);
+ PreparedStatement ps = conn.prepareStatement("DELETE FROM " +
tableName
+ + " WHERE PK1 = ? AND PK2 = ? AND PK3 = ?");
ps.setString(1, "pk000");
ps.setDouble(2, -123.98);
ps.setString(3, "pk003");
@@ -204,11 +199,8 @@ public class OnDuplicateKey2IT extends
ParallelStatsDisabledIT {
verifyIndexRow(conn, tableName, false);
- PhoenixPreparedStatement ps =
- conn.prepareStatement(
- "DELETE FROM " + tableName + " WHERE PK1 =
? AND PK2 " +
- "= ? AND PK3 = ? AND COL4 = ?")
- .unwrap(PhoenixPreparedStatement.class);
+ PreparedStatement ps = conn.prepareStatement("DELETE FROM " +
tableName
+ + " WHERE PK1 = ? AND PK2 = ? AND PK3 = ? AND COL4 = ?");
ps.setString(1, "pk000");
ps.setDouble(2, -123.98);
ps.setString(3, "pk003");
@@ -216,8 +208,7 @@ public class OnDuplicateKey2IT extends
ParallelStatsDisabledIT {
validateReturnedRowAfterDelete(ps, "col2_001", true, false,
bsonDocument2, 234);
ps = conn.prepareStatement("DELETE FROM " + tableName
- + " WHERE PK1 = ? AND PK2 = ? AND PK3 = ? AND COL4
= ?")
- .unwrap(PhoenixPreparedStatement.class);
+ + " WHERE PK1 = ? AND PK2 = ? AND PK3 = ? AND COL4 = ?");
ps.setString(1, "pk000");
ps.setDouble(2, -123.98);
ps.setString(3, "pk003");
@@ -262,11 +253,8 @@ public class OnDuplicateKey2IT extends
ParallelStatsDisabledIT {
validateAtomicUpsertReturnRow(tableName, conn, bsonDocument1,
bsonDocument2);
- PhoenixPreparedStatement ps =
- conn.prepareStatement(
- "DELETE FROM " + tableName + " WHERE PK1 =
? AND PK2 " +
- "= ? AND PK3 = ? AND COL4 = ?")
- .unwrap(PhoenixPreparedStatement.class);
+ PreparedStatement ps = conn.prepareStatement("DELETE FROM " +
tableName
+ + " WHERE PK1 = ? AND PK2 = ? AND PK3 = ? AND COL4 = ?");
ps.setString(1, "pk000");
ps.setDouble(2, -123.98);
ps.setString(3, "pk003");
@@ -274,8 +262,7 @@ public class OnDuplicateKey2IT extends
ParallelStatsDisabledIT {
validateReturnedRowAfterDelete(ps, "col2_001", true, false,
bsonDocument2, 234);
ps = conn.prepareStatement("DELETE FROM " + tableName
- + " WHERE PK1 = ? AND PK2 = ? AND PK3 = ? AND COL4
= ?")
- .unwrap(PhoenixPreparedStatement.class);
+ + " WHERE PK1 = ? AND PK2 = ? AND PK3 = ? AND COL4 = ?");
ps.setString(1, "pk000");
ps.setDouble(2, -123.98);
ps.setString(3, "pk003");
@@ -319,10 +306,8 @@ public class OnDuplicateKey2IT extends
ParallelStatsDisabledIT {
validateAtomicUpsertReturnRow(tableName, conn, bsonDocument1,
bsonDocument2);
- PhoenixPreparedStatement ps =
- conn.prepareStatement(
- "DELETE FROM " + tableName + " WHERE PK1 = ? AND
PK2 " +
- "= ? AND PK3 =
?").unwrap(PhoenixPreparedStatement.class);
+ PreparedStatement ps = conn.prepareStatement("DELETE FROM " +
tableName
+ + " WHERE PK1 = ? AND PK2 = ? AND PK3 = ?");
ps.setString(1, "pk000");
ps.setDouble(2, -123.98);
ps.setString(3, "pk003");
@@ -360,15 +345,13 @@ public class OnDuplicateKey2IT extends
ParallelStatsDisabledIT {
throws SQLException {
addRows(tableName, conn);
- PhoenixPreparedStatement ps = conn.prepareStatement(
- "DELETE FROM " + tableName + " WHERE PK1 = ? AND PK2 =
?")
- .unwrap(PhoenixPreparedStatement.class);
+ PreparedStatement ps = conn.prepareStatement(
+ "DELETE FROM " + tableName + " WHERE PK1 = ? AND PK2 = ?");
ps.setString(1, "pk001");
ps.setDouble(2, 122.34);
validateReturnedRowAfterDelete(ps, "col2_001", false, false,
bsonDocument2, 234);
- ps = conn.prepareStatement(
- "DELETE FROM " +
tableName).unwrap(PhoenixPreparedStatement.class);
+ ps = conn.prepareStatement("DELETE FROM " + tableName);
validateReturnedRowAfterDelete(ps, "col2_001", false, false,
bsonDocument2, 234);
ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM " +
tableName);
@@ -376,10 +359,8 @@ public class OnDuplicateKey2IT extends
ParallelStatsDisabledIT {
addRows(tableName, conn);
- ps = conn.prepareStatement(
- "DELETE FROM " + tableName + " WHERE PK1 IN (?) AND
PK2 IN (?) AND " +
- "PK3 IN (?, ?)")
- .unwrap(PhoenixPreparedStatement.class);
+ ps = conn.prepareStatement("DELETE FROM " + tableName
+ + " WHERE PK1 IN (?) AND PK2 IN (?) AND PK3 IN (?, ?)");
ps.setString(1, "pk001");
ps.setDouble(2, 122.34);
ps.setString(3, "pk004");
@@ -397,8 +378,7 @@ public class OnDuplicateKey2IT extends
ParallelStatsDisabledIT {
upsertSql =
"UPSERT INTO " + tableName + " (PK1, PK2, PK3, COUNTER1) "
- + "VALUES('pk000', -123.98, 'pk003', 0) ON DUPLICATE"
- + " KEY IGNORE";
+ + "VALUES('pk000', -123.98, 'pk003', 0) ON DUPLICATE
KEY IGNORE";
validateReturnedRowAfterUpsert(conn, upsertSql, tableName, 1011.202,
null, false,
null, bsonDocument1, 123);
@@ -449,14 +429,15 @@ public class OnDuplicateKey2IT extends
ParallelStatsDisabledIT {
conn.createStatement().execute(upsertSql);
}
- private static void
validateReturnedRowAfterDelete(PhoenixPreparedStatement ps,
+ private static void validateReturnedRowAfterDelete(PreparedStatement ps,
String col2,
boolean
isSinglePointLookup,
boolean
atomicDeleteSuccessful,
BsonDocument
expectedDoc,
Integer col4)
throws SQLException {
- final Pair<Integer, ResultSet> resultPair =
ps.executeAtomicUpdateReturnRow();
+ final Pair<Integer, ResultSet> resultPair =
+
ps.unwrap(PhoenixPreparedStatement.class).executeAtomicUpdateReturnRow();
ResultSet resultSet = resultPair.getSecond();
if (!isSinglePointLookup) {
assertNull(resultSet);
@@ -498,24 +479,32 @@ public class OnDuplicateKey2IT extends
ParallelStatsDisabledIT {
BsonDocument
expectedDoc,
Integer col4)
throws SQLException {
- final Pair<Integer, ResultSet> resultPair;
+ int updateCount;
+ ResultSet resultSet;
if (inputDoc != null) {
- PhoenixPreparedStatement ps =
-
conn.prepareStatement(upsertSql).unwrap(PhoenixPreparedStatement.class);
+ PreparedStatement ps = conn.prepareStatement(upsertSql);
ps.setObject(1, inputDoc);
- resultPair = ps.executeAtomicUpdateReturnRow();
+ updateCount = ps.executeUpdate();
+ resultSet = ps.getResultSet();
} else {
- resultPair = conn.createStatement().unwrap(PhoenixStatement.class)
- .executeAtomicUpdateReturnRow(upsertSql);
+ Statement stmt = conn.createStatement();
+ resultSet = stmt.execute(upsertSql) ? stmt.getResultSet() : null;
+ updateCount = stmt.getUpdateCount();
+ }
+ boolean isOnDuplicateKey = upsertSql.toUpperCase().contains("ON
DUPLICATE KEY");
+ if (conn.getAutoCommit() && isOnDuplicateKey) {
+ assertEquals(success ? 1 : 0, updateCount);
+ assertEquals("pk000", resultSet.getString(1));
+ assertEquals(-123.98, resultSet.getDouble(2), 0.0);
+ assertEquals("pk003", resultSet.getString(3));
+ assertEquals(col1, resultSet.getDouble(4), 0.0);
+ validateReturnedRowResult(col2, expectedDoc, col4, resultSet);
+ assertFalse(resultSet.next());
+ }
+ else {
+ assertNull(resultSet);
+ assertEquals(1, updateCount);
}
- assertEquals(success ? 1 : 0, resultPair.getFirst().intValue());
- ResultSet resultSet = resultPair.getSecond();
-
- assertEquals("pk000", resultSet.getString(1));
- assertEquals(-123.98, resultSet.getDouble(2), 0.0);
- assertEquals("pk003", resultSet.getString(3));
- assertEquals(col1, resultSet.getDouble(4), 0.0);
- validateReturnedRowResult(col2, expectedDoc, col4, resultSet);
}
@Test
@@ -535,9 +524,8 @@ public class OnDuplicateKey2IT extends
ParallelStatsDisabledIT {
addRows2(tableName, conn);
- PhoenixPreparedStatement ps = conn.prepareStatement(
- "DELETE FROM " + tableName + " WHERE PK IN (?, ?,
?)")
- .unwrap(PhoenixPreparedStatement.class);
+ PreparedStatement ps = conn.prepareStatement(
+ "DELETE FROM " + tableName + " WHERE PK IN (?, ?, ?)");
ps.setString(1, "pk001");
ps.setString(2, "pk002");
ps.setString(3, "pk003");
@@ -589,10 +577,6 @@ public class OnDuplicateKey2IT extends
ParallelStatsDisabledIT {
"IGNORE";
validateReturnedRowAfterUpsert(conn, upsertSql, tableName,
1011.202, null, true,
bsonDocument1, bsonDocument1, 123);
- throw new RuntimeException("Should not reach here");
- } catch (SQLException e) {
-
Assert.assertEquals(SQLExceptionCode.AUTO_COMMIT_NOT_ENABLED.getErrorCode(),
- e.getErrorCode());
}
}
diff --git
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/TestUpsertBindNullParamToCaseExprIT.java
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertBindNullParamToCaseExprIT.java
similarity index 98%
rename from
phoenix-core/src/it/java/org/apache/phoenix/end2end/TestUpsertBindNullParamToCaseExprIT.java
rename to
phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertBindNullParamToCaseExprIT.java
index 6d149e1f13..b56a235a5f 100644
---
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/TestUpsertBindNullParamToCaseExprIT.java
+++
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertBindNullParamToCaseExprIT.java
@@ -24,6 +24,7 @@ import org.apache.phoenix.util.ReadOnlyProps;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
+import org.junit.experimental.categories.Category;
import java.sql.Connection;
import java.sql.DriverManager;
@@ -39,7 +40,8 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
-public class TestUpsertBindNullParamToCaseExprIT extends BaseTest {
+@Category(ParallelStatsDisabledTest.class)
+public class UpsertBindNullParamToCaseExprIT extends BaseTest {
@BeforeClass
public static synchronized void doSetup() throws Exception {
diff --git
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertSelectAutoCommitIT.java
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertSelectAutoCommitIT.java
index d3f8fbd00d..9dd3059173 100644
---
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertSelectAutoCommitIT.java
+++
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertSelectAutoCommitIT.java
@@ -79,6 +79,10 @@ public class UpsertSelectAutoCommitIT extends
ParallelStatsDisabledIT {
stmt.setString(2, ROW1);
stmt.setString(3, A_VALUE);
stmt.execute();
+ assertEquals(1, stmt.getUpdateCount());
+ // When not using an UPSERT variant (e.g., ON DUPLICATE KEY) that is
not capable of
+ // returning a row, we don't expect to get a result set.
+ assertNull(stmt.getResultSet());
String query = "SELECT entity_id, a_string FROM " + atable;
PreparedStatement statement = conn.prepareStatement(query);
@@ -94,8 +98,13 @@ public class UpsertSelectAutoCommitIT extends
ParallelStatsDisabledIT {
+ " (ORGANIZATION_ID CHAR(15) NOT NULL, ENTITY_ID CHAR(15) NOT
NULL, A_STRING VARCHAR\n"
+
"CONSTRAINT pk PRIMARY KEY (organization_id, entity_id DESC))");
-
- conn.createStatement().execute("UPSERT INTO " + atable2 + " SELECT *
FROM " + atable);
+
+ Statement upsertStmt = conn.createStatement();
+ upsertStmt.execute("UPSERT INTO " + atable2 + " SELECT * FROM " +
atable);
+ assertEquals(1, upsertStmt.getUpdateCount());
+ // When not using an UPSERT variant (e.g., ON DUPLICATE KEY) that is
not capable of
+ // returning a row, we don't expect to get a result set.
+ assertNull(upsertStmt.getResultSet());
query = "SELECT entity_id, a_string FROM " + atable2;
statement = conn.prepareStatement(query);
rs = statement.executeQuery();
@@ -178,8 +187,13 @@ public class UpsertSelectAutoCommitIT extends
ParallelStatsDisabledIT {
conn.createStatement().execute("CREATE TABLE " + tableName
+ " (pk INTEGER PRIMARY KEY, val INTEGER)
UPDATE_CACHE_FREQUENCY=3600000");
- conn.createStatement().execute(
+ Statement upsertStmt = conn.createStatement();
+ upsertStmt.execute(
"UPSERT INTO " + tableName + " VALUES (NEXT VALUE FOR "+ tableName
+ "_seq, 1)");
+ assertEquals(1, upsertStmt.getUpdateCount());
+ // When not using an UPSERT variant (e.g., ON DUPLICATE KEY) that is
not capable of
+ // returning a row, we don't expect to get a result set.
+ assertNull(upsertStmt.getResultSet());
PreparedStatement stmt =
conn.prepareStatement("UPSERT INTO " + tableName
+ " SELECT NEXT VALUE FOR "+ tableName + "_seq, val
FROM " + tableName);
diff --git
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertSelectIT.java
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertSelectIT.java
index 958af7151c..347f4db077 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertSelectIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertSelectIT.java
@@ -216,6 +216,10 @@ public class UpsertSelectIT extends
ParallelStatsDisabledIT {
upsertStmt.setString(1, A_VALUE);
int rowsInserted = upsertStmt.executeUpdate();
assertEquals(4, rowsInserted);
+ assertEquals(4, upsertStmt.getUpdateCount());
+ // When not using an UPSERT variant (e.g., ON DUPLICATE KEY)
that is not capable of
+ // returning a row, we don't expect to get a result set.
+ assertNull(upsertStmt.getResultSet());
}
conn.commit();
}
diff --git
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertValuesIT.java
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertValuesIT.java
index 52a7553895..2c3b4f9f1e 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertValuesIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertValuesIT.java
@@ -23,6 +23,7 @@ import static org.apache.phoenix.util.TestUtil.closeStatement;
import static org.apache.phoenix.util.TestUtil.closeStmtAndConn;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -76,6 +77,10 @@ public class UpsertValuesIT extends ParallelStatsDisabledIT {
PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " +
tableName + " (inst,host,\"DATE\") VALUES(?,'b',CURRENT_DATE())");
stmt.setString(1, "a");
stmt.execute();
+ // When not using an UPSERT variant (e.g., ON DUPLICATE KEY) that is
not capable of
+ // returning a row, we don't expect to get a result set.
+ assertNull(stmt.getResultSet());
+ assertEquals(1, stmt.getUpdateCount());
stmt.execute();
stmt.execute();
stmt.setString(1, "b");