You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ja...@apache.org on 2018/09/24 15:28:20 UTC

[15/50] [abbrv] phoenix git commit: PHOENIX-3991 ROW_TIMESTAMP on TIMESTAMP column type throws ArrayOutOfBound when upserting without providing a value.

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/b37b7d75
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/b37b7d75
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/b37b7d75

Branch: refs/heads/omid2
Commit: b37b7d7505570d8b198ecd4b6e5a626c73bf7ebe
Parents: 1f7e320
Author: Sergey Soldatov <ss...@apache.org>
Authored: Wed Jul 25 12:48:03 2018 -0700
Committer: Sergey Soldatov <ss...@apache.org>
Committed: Thu Jul 26 13:39:00 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/b37b7d75/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 458cc38..0457bf3 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
@@ -73,13 +73,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())) {
@@ -192,14 +201,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/b37b7d75/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 c29d6b5..d2d1eea 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;
@@ -85,6 +86,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;
@@ -474,7 +476,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