phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jamestay...@apache.org
Subject phoenix git commit: PHOENIX-4179 Use max timestamp of projected cells for cell timestamp returned to client
Date Fri, 08 Sep 2017 17:32:29 GMT
Repository: phoenix
Updated Branches:
  refs/heads/master 5a21734f1 -> 6775dc5c4


PHOENIX-4179 Use max timestamp of projected cells for cell timestamp returned to client


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/6775dc5c
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/6775dc5c
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/6775dc5c

Branch: refs/heads/master
Commit: 6775dc5c489bd002186e8b5375dd89b666836067
Parents: 5a21734
Author: James Taylor <jtaylor@salesforce.com>
Authored: Thu Sep 7 17:02:44 2017 -0700
Committer: James Taylor <jtaylor@salesforce.com>
Committed: Thu Sep 7 17:02:44 2017 -0700

----------------------------------------------------------------------
 .../apache/phoenix/end2end/index/IndexIT.java   | 58 ++++++++++++++++++++
 .../apache/phoenix/execute/TupleProjector.java  | 12 +++-
 2 files changed, 68 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/6775dc5c/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexIT.java
index 12add12..f8856e3 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexIT.java
@@ -19,6 +19,7 @@
 package org.apache.phoenix.end2end.index;
 
 import static org.apache.phoenix.query.QueryConstants.MILLIS_IN_DAY;
+import static org.apache.phoenix.util.TestUtil.ROW5;
 import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
@@ -39,6 +40,7 @@ import java.sql.Statement;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Properties;
+import java.util.Random;
 
 import org.apache.hadoop.hbase.Cell;
 import org.apache.hadoop.hbase.CellScanner;
@@ -57,6 +59,7 @@ import org.apache.phoenix.end2end.ParallelStatsDisabledIT;
 import org.apache.phoenix.exception.SQLExceptionCode;
 import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
+import org.apache.phoenix.jdbc.PhoenixResultSet;
 import org.apache.phoenix.jdbc.PhoenixStatement;
 import org.apache.phoenix.parse.NamedTableNode;
 import org.apache.phoenix.parse.TableName;
@@ -66,6 +69,7 @@ import org.apache.phoenix.schema.PTableImpl;
 import org.apache.phoenix.schema.PTableKey;
 import org.apache.phoenix.schema.PTableType;
 import org.apache.phoenix.util.DateUtil;
+import org.apache.phoenix.util.EnvironmentEdgeManager;
 import org.apache.phoenix.util.PropertiesUtil;
 import org.apache.phoenix.util.QueryUtil;
 import org.apache.phoenix.util.ReadOnlyProps;
@@ -79,6 +83,7 @@ import org.junit.runners.Parameterized.Parameters;
 
 @RunWith(Parameterized.class)
 public class IndexIT extends ParallelStatsDisabledIT {
+    private static final Random RAND = new Random();
 
     private final boolean localIndex;
     private final boolean transactional;
@@ -1146,4 +1151,57 @@ public class IndexIT extends ParallelStatsDisabledIT {
         }
     }
 
+    @Test
+    public void testReturnedTimestamp() throws Exception {
+        String tenantId = getOrganizationId();
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        Connection conn = DriverManager.getConnection(getUrl(), props);
+        try {
+            String indexName = generateUniqueName();
+            String tableName =
+                    initATableValues(generateUniqueName(), tenantId, getDefaultSplits(tenantId),
+                        new Date(System.currentTimeMillis()), null, getUrl(), tableDDLOptions);
+            String ddl = "CREATE "+ (localIndex ? "LOCAL " : "") + " INDEX " + indexName
+ " on " + tableName + "(A_STRING) INCLUDE (B_STRING)";
+            conn.createStatement().executeUpdate(ddl);
+            String query = "SELECT ENTITY_ID,A_STRING,B_STRING FROM " + tableName + " WHERE
organization_id=? and entity_id=?";
+
+            PreparedStatement statement = conn.prepareStatement(query);
+            statement.setString(1, tenantId);
+
+            long currentTime = EnvironmentEdgeManager.currentTimeMillis();
+            String entityId = mutable ? ROW5 : Integer.toString(Math.abs(RAND.nextInt() %
1000000000));
+            PreparedStatement ddlStatement = conn.prepareStatement("UPSERT INTO " + tableName
+ "(ORGANIZATION_ID, ENTITY_ID,A_STRING) VALUES('" + tenantId + "',?,?)");
+            ddlStatement.setString(1, entityId);
+            ddlStatement.setString(2, Integer.toString(Math.abs(RAND.nextInt() % 1000000000)));
+            ddlStatement.executeUpdate();
+            conn.commit();
+ 
+            statement.setString(2, entityId);
+            ResultSet rs = statement.executeQuery();
+            assertTrue (rs.next());
+            assertTrue(rs.unwrap(PhoenixResultSet.class).getCurrentRow().getValue(0).getTimestamp()
>= currentTime);
+            assertEquals(rs.getString(1).trim(), entityId);
+            assertFalse(rs.next());
+
+            currentTime = EnvironmentEdgeManager.currentTimeMillis();
+            entityId = mutable ? ROW5 : Integer.toString(Math.abs(RAND.nextInt() % 1000000000));
+            ddlStatement = conn.prepareStatement("UPSERT INTO " + tableName + "(ORGANIZATION_ID,
ENTITY_ID,B_STRING) VALUES('" + tenantId + "',?,?)");
+            ddlStatement.setString(1, entityId);
+            ddlStatement.setString(2, Integer.toString(Math.abs(RAND.nextInt() % 1000000000)));
+            ddlStatement.executeUpdate();
+            conn.commit();
+            
+            statement.setString(2, entityId);
+            rs = statement.executeQuery();
+            assertTrue (rs.next());
+            assertTrue(rs.unwrap(PhoenixResultSet.class).getCurrentRow().getValue(0).getTimestamp()
>= currentTime);
+            assertEquals(rs.getString(1).trim(), entityId);
+            assertFalse(rs.next());
+
+        } finally {
+            conn.close();
+        }
+    }
+
+
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6775dc5c/phoenix-core/src/main/java/org/apache/phoenix/execute/TupleProjector.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/execute/TupleProjector.java b/phoenix-core/src/main/java/org/apache/phoenix/execute/TupleProjector.java
index 2126026..266bb6e 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/execute/TupleProjector.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/execute/TupleProjector.java
@@ -280,12 +280,20 @@ public class TupleProjector {
     }
     
     public ProjectedValueTuple projectResults(Tuple tuple, boolean useNewValueQualifier)
{
+        long maxTS = tuple.getValue(0).getTimestamp();
+        int nCells = tuple.size();
+        for (int i = 1; i < nCells; i++) {
+            long ts = tuple.getValue(i).getTimestamp();
+            if (ts > maxTS) {
+                maxTS = ts;
+            }
+        }
         byte[] bytesValue = schema.toBytes(tuple, getExpressions(), valueSet, ptr);
         Cell base = tuple.getValue(0);
         if (useNewValueQualifier) {
-            return new ProjectedValueTuple(base.getRowArray(), base.getRowOffset(), base.getRowLength(),
base.getTimestamp(), bytesValue, 0, bytesValue.length, valueSet.getEstimatedLength());
+            return new ProjectedValueTuple(base.getRowArray(), base.getRowOffset(), base.getRowLength(),
maxTS, bytesValue, 0, bytesValue.length, valueSet.getEstimatedLength());
         } else {
-            return new OldProjectedValueTuple(base.getRowArray(), base.getRowOffset(), base.getRowLength(),
base.getTimestamp(), bytesValue, 0, bytesValue.length, valueSet.getEstimatedLength());
+            return new OldProjectedValueTuple(base.getRowArray(), base.getRowOffset(), base.getRowLength(),
maxTS, bytesValue, 0, bytesValue.length, valueSet.getEstimatedLength());
         }
     }
     


Mime
View raw message