jpisaac commented on a change in pull request #955:
URL: https://github.com/apache/phoenix/pull/955#discussion_r520960164
##########
File path:
phoenix-core/src/test/java/org/apache/phoenix/query/PhoenixTestBuilder.java
##########
@@ -294,27 +423,104 @@ public void upsertRow(int rowIndex) throws SQLException {
buf.append("?,");
}
buf.setCharAt(buf.length() - 1, ')');
-
- LOGGER.info(buf.toString());
+ LOGGER.debug(buf.toString());
Connection connection = getConnection();
try (PreparedStatement stmt =
connection.prepareStatement(buf.toString())) {
for (int i = 0; i < upsertValues.size(); i++) {
+ //TODO : handle null values
stmt.setObject(i + 1, upsertValues.get(i));
}
stmt.execute();
connection.commit();
}
+ return upsertValues;
+ }
+
+ // Upsert batch of rows.
+ public void upsertRows(int startRowIndex, int numRows) throws
SQLException {
+ dataTable.clear();
+ List<String> upsertColumns = Lists.newArrayList();
+ List<Integer> rowKeyPositions = Lists.newArrayList();
+
+ // Figure out the upsert columns based on whether this is a full
or partial row update.
+ boolean isFullRowUpdate = getColumnPositionsToUpdate().isEmpty();
+ if (isFullRowUpdate) {
+ upsertColumns.addAll(getUpsertColumns());
+ } else {
+ List<String> tmpColumns = getUpsertColumns();
+ for (int i : getColumnPositionsToUpdate()) {
+ upsertColumns.add(tmpColumns.get(i));
+ }
+ }
+
+ Set<String> rowKeys = getRowKeyColumns() == null ||
getRowKeyColumns().isEmpty() ?
+ Sets.<String>newHashSet(getUpsertColumns()) :
+ Sets.newHashSet(getRowKeyColumns());
+
+ StringBuilder buf = new StringBuilder("UPSERT INTO ");
+ buf.append(getTargetEntity());
+ buf.append("
(").append(Joiner.on(",").join(upsertColumns)).append(") VALUES(");
+ for (int i = 0; i < upsertColumns.size(); i++) {
+ buf.append("?,");
+ if (rowKeys.contains(upsertColumns.get(i))) {
+ rowKeyPositions.add(i);
+ }
+ }
+ buf.setCharAt(buf.length() - 1, ')');
+ LOGGER.debug (buf.toString());
+
+ Connection connection = getConnection();
+ try (PreparedStatement stmt =
connection.prepareStatement(buf.toString())) {
+
+ for (int r = startRowIndex; r < startRowIndex + numRows; r++) {
+ List<Object> upsertValues = Lists.newArrayList();
+ List<Object> rowValues = null;
+ try {
+ rowValues = getTestDataSupplier().getValues(r);
+ } catch (Exception e) {
+ throw new SQLException(e);
Review comment:
I think I was trying to keep the interface simple with only one
exception (SQLException)
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]