Repository: phoenix Updated Branches: refs/heads/4.x-HBase-1.2 faf4fb264 -> 67731c4db refs/heads/4.x-HBase-1.3 1f7e3206b -> b37b7d750 refs/heads/4.x-HBase-1.4 6b363b3a2 -> a1d036676 refs/heads/5.x-HBase-2.0 8a874cc95 -> accde3c7c refs/heads/master 8a874cc95 -> 6641f42d1
PHOENIX-3991 ROW_TIMESTAMP on TIMESTAMP column type throws ArrayOutOfBound when upserting without providing a value. Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/6641f42d Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/6641f42d Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/6641f42d Branch: refs/heads/master Commit: 6641f42d1f71864ed8bb1d00a1c082bcbff25ad7 Parents: 8a874cc Author: Sergey Soldatov <s...@apache.org> Authored: Wed Jul 25 12:48:03 2018 -0700 Committer: Sergey Soldatov <s...@apache.org> Committed: Thu Jul 26 13:37:23 2018 -0700 ---------------------------------------------------------------------- .../apache/phoenix/end2end/RowTimestampIT.java | 26 +++++++++++++++++--- .../apache/phoenix/execute/MutationState.java | 6 ++++- 2 files changed, 27 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/6641f42d/phoenix-core/src/it/java/org/apache/phoenix/end2end/RowTimestampIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/RowTimestampIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/RowTimestampIT.java index 509e305..e873fdf 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/RowTimestampIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/RowTimestampIT.java @@ -75,13 +75,22 @@ public class RowTimestampIT extends ParallelStatsDisabledIT { } @Test - public void testWithUpsertingRowTimestampColSpecified() throws Exception { + public void testUpsertingRowTimestampColSpecifiedWithTimestamp() throws Exception { + upsertingRowTimestampColSpecified("TIMESTAMP"); + } + + @Test + public void testUpsertingRowTimestampColSpecifiedWithDate() throws Exception { + upsertingRowTimestampColSpecified("DATE"); + } + + private void upsertingRowTimestampColSpecified(String type) throws Exception { String tableName = generateUniqueName(); String indexName = generateUniqueName(); try (Connection conn = DriverManager.getConnection(getUrl())) { conn.createStatement() .execute("CREATE TABLE IF NOT EXISTS " + tableName - + " (PK1 VARCHAR NOT NULL, PK2 DATE NOT NULL, KV1 VARCHAR, KV2 VARCHAR CONSTRAINT PK PRIMARY KEY(PK1, PK2 " + + " (PK1 VARCHAR NOT NULL, PK2 " + type + " NOT NULL, KV1 VARCHAR, KV2 VARCHAR CONSTRAINT PK PRIMARY KEY(PK1, PK2 " + sortOrder + " ROW_TIMESTAMP)) " + tableDDLOptions); } try (Connection conn = DriverManager.getConnection(getUrl())) { @@ -195,14 +204,23 @@ public class RowTimestampIT extends ParallelStatsDisabledIT { } @Test - public void testAutomaticallySettingRowTimestampForImmutableTableAndIndexes() throws Exception { + public void testAutomaticallySettingRowTimestampWithTimestamp () throws Exception { + automaticallySettingRowTimestampForImmutableTableAndIndexes("TIMESTAMP"); + } + + @Test + public void testAutomaticallySettingRowTimestampWithDate () throws Exception { + automaticallySettingRowTimestampForImmutableTableAndIndexes("DATE"); + } + + private void automaticallySettingRowTimestampForImmutableTableAndIndexes(String type) throws Exception { long startTime = EnvironmentEdgeManager.currentTimeMillis(); String tableName = generateUniqueName(); String indexName = generateUniqueName(); try (Connection conn = DriverManager.getConnection(getUrl())) { conn.createStatement() .execute("CREATE TABLE IF NOT EXISTS " + tableName - + " (PK1 VARCHAR NOT NULL, PK2 DATE NOT NULL, KV1 VARCHAR, KV2 VARCHAR CONSTRAINT PK PRIMARY KEY(PK1, PK2 " + + " (PK1 VARCHAR NOT NULL, PK2 " + type + " NOT NULL, KV1 VARCHAR, KV2 VARCHAR CONSTRAINT PK PRIMARY KEY(PK1, PK2 " + sortOrder + " ROW_TIMESTAMP)) " + tableDDLOptions); } try (Connection conn = DriverManager.getConnection(getUrl())) { http://git-wip-us.apache.org/repos/asf/phoenix/blob/6641f42d/phoenix-core/src/main/java/org/apache/phoenix/execute/MutationState.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/execute/MutationState.java b/phoenix-core/src/main/java/org/apache/phoenix/execute/MutationState.java index 35a844f..cf17b90 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/execute/MutationState.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/execute/MutationState.java @@ -25,6 +25,7 @@ import static org.apache.phoenix.monitoring.GlobalClientMetrics.GLOBAL_MUTATION_ import java.io.IOException; import java.sql.SQLException; +import java.sql.Timestamp; import java.util.Arrays; import java.util.Collection; import java.util.Collections; @@ -87,6 +88,7 @@ import org.apache.phoenix.schema.TableNotFoundException; import org.apache.phoenix.schema.TableRef; import org.apache.phoenix.schema.ValueSchema.Field; import org.apache.phoenix.schema.types.PLong; +import org.apache.phoenix.schema.types.PTimestamp; import org.apache.phoenix.trace.util.Tracing; import org.apache.phoenix.transaction.PhoenixTransactionContext; import org.apache.phoenix.transaction.PhoenixTransactionContext.PhoenixVisibilityLevel; @@ -476,7 +478,9 @@ public class MutationState implements SQLCloseable { RowKeySchema schema = table.getRowKeySchema(); int rowTimestampColPos = table.getRowTimestampColPos(); Field rowTimestampField = schema.getField(rowTimestampColPos); - byte[] rowTimestampBytes = PLong.INSTANCE.toBytes(rowTimestamp, rowTimestampField.getSortOrder()); + byte[] rowTimestampBytes = rowTimestampField.getDataType() == PTimestamp.INSTANCE ? + PTimestamp.INSTANCE.toBytes(new Timestamp(rowTimestamp), rowTimestampField.getSortOrder()) : + PLong.INSTANCE.toBytes(rowTimestamp, rowTimestampField.getSortOrder()); int oldOffset = ptr.getOffset(); int oldLength = ptr.getLength(); // Move the pointer to the start byte of the row timestamp pk