[ 
https://issues.apache.org/jira/browse/PHOENIX-6506?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17382233#comment-17382233
 ] 

ASF GitHub Bot commented on PHOENIX-6506:
-----------------------------------------

virajjasani commented on a change in pull request #1261:
URL: https://github.com/apache/phoenix/pull/1261#discussion_r671413220



##########
File path: 
phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertValuesIT.java
##########
@@ -670,5 +669,144 @@ public void testColumnQualifierForUpsertedValues() throws 
Exception {
             assertTrue(next.containsColumn(Bytes.toBytes("CF2"), 
PInteger.INSTANCE.toBytes(3)));
         }
     }
-    
+
+    @Test
+    public void testUpsertValueWithDiffSequenceAndConnections() throws 
Exception {
+        String tableName = generateUniqueName();
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            conn.setAutoCommit(true);
+            PreparedStatement createTableStatement = 
conn.prepareStatement(String.format("CREATE TABLE IF NOT EXISTS " +
+                    "%s (SERVICE VARCHAR NOT NULL, SEQUENCE_NUMBER BIGINT NOT 
NULL , " +
+                    "CONSTRAINT PK PRIMARY KEY (SERVICE, SEQUENCE_NUMBER)) 
MULTI_TENANT = TRUE", tableName));
+            createTableStatement.execute();
+        }
+
+        testGlobalSequenceUpsertWithTenantConnection(tableName);
+        testGlobalSequenceUpsertWithGlobalConnection(tableName);
+        testTenantSequenceUpsertWithSameTenantConnection(tableName);
+        testTenantSequenceUpsertWithDifferentTenantConnection(tableName);
+        testTenantSequenceUpsertWithGlobalConnection(tableName);
+
+    }
+
+    private void testTenantSequenceUpsertWithGlobalConnection(String 
tableName) throws Exception {
+        String sequenceName = generateUniqueSequenceName();
+
+        try (Connection conn = getTenantConnection("PHOENIX")) {
+            conn.setAutoCommit(true);
+            PreparedStatement createSequenceStatement = 
conn.prepareStatement(String.format("CREATE SEQUENCE " +
+                    "IF NOT EXISTS %s", sequenceName));
+            createSequenceStatement.execute();
+        }
+
+        try (Connection tenantConn = DriverManager.getConnection(getUrl())) {
+            tenantConn.setAutoCommit(true);
+            Statement executeUpdateStatement = tenantConn.createStatement();
+            try {
+                executeUpdateStatement.execute(String.format("UPSERT INTO %s ( 
SERVICE, SEQUENCE_NUMBER) VALUES " +
+                        "( 'PHOENIX', NEXT VALUE FOR %s)", tableName, 
sequenceName));
+            } catch (SequenceNotFoundException e) {
+                assertTrue(true);
+            } catch (Exception e) {
+                assertTrue(false);

Review comment:
       I think we can just fail here with `Assert.fail()`

##########
File path: 
phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertValuesIT.java
##########
@@ -670,5 +669,144 @@ public void testColumnQualifierForUpsertedValues() throws 
Exception {
             assertTrue(next.containsColumn(Bytes.toBytes("CF2"), 
PInteger.INSTANCE.toBytes(3)));
         }
     }
-    
+
+    @Test
+    public void testUpsertValueWithDiffSequenceAndConnections() throws 
Exception {
+        String tableName = generateUniqueName();
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            conn.setAutoCommit(true);
+            PreparedStatement createTableStatement = 
conn.prepareStatement(String.format("CREATE TABLE IF NOT EXISTS " +
+                    "%s (SERVICE VARCHAR NOT NULL, SEQUENCE_NUMBER BIGINT NOT 
NULL , " +
+                    "CONSTRAINT PK PRIMARY KEY (SERVICE, SEQUENCE_NUMBER)) 
MULTI_TENANT = TRUE", tableName));
+            createTableStatement.execute();
+        }
+
+        testGlobalSequenceUpsertWithTenantConnection(tableName);
+        testGlobalSequenceUpsertWithGlobalConnection(tableName);
+        testTenantSequenceUpsertWithSameTenantConnection(tableName);
+        testTenantSequenceUpsertWithDifferentTenantConnection(tableName);
+        testTenantSequenceUpsertWithGlobalConnection(tableName);
+
+    }
+
+    private void testTenantSequenceUpsertWithGlobalConnection(String 
tableName) throws Exception {
+        String sequenceName = generateUniqueSequenceName();
+
+        try (Connection conn = getTenantConnection("PHOENIX")) {
+            conn.setAutoCommit(true);
+            PreparedStatement createSequenceStatement = 
conn.prepareStatement(String.format("CREATE SEQUENCE " +
+                    "IF NOT EXISTS %s", sequenceName));
+            createSequenceStatement.execute();
+        }
+
+        try (Connection tenantConn = DriverManager.getConnection(getUrl())) {
+            tenantConn.setAutoCommit(true);
+            Statement executeUpdateStatement = tenantConn.createStatement();
+            try {
+                executeUpdateStatement.execute(String.format("UPSERT INTO %s ( 
SERVICE, SEQUENCE_NUMBER) VALUES " +
+                        "( 'PHOENIX', NEXT VALUE FOR %s)", tableName, 
sequenceName));
+            } catch (SequenceNotFoundException e) {
+                assertTrue(true);
+            } catch (Exception e) {
+                assertTrue(false);
+            }
+        }
+    }
+
+    private void testTenantSequenceUpsertWithDifferentTenantConnection(String 
tableName) throws Exception {
+        String sequenceName = generateUniqueSequenceName();
+
+        try (Connection conn = getTenantConnection("PHOENIX")) {
+            conn.setAutoCommit(true);
+            PreparedStatement createSequenceStatement = 
conn.prepareStatement(String.format("CREATE SEQUENCE " +
+                    "IF NOT EXISTS %s", sequenceName));
+            createSequenceStatement.execute();
+        }
+
+        try (Connection tenantConn = getTenantConnection("HBASE")) {
+            tenantConn.setAutoCommit(true);
+
+            Statement executeUpdateStatement = tenantConn.createStatement();
+            try {
+                executeUpdateStatement.execute(String.format("UPSERT INTO %s ( 
SEQUENCE_NUMBER) VALUES " +
+                        "( NEXT VALUE FOR %s)", tableName, sequenceName));
+            } catch (SequenceNotFoundException e) {
+                assertTrue(true);
+            } catch (Exception e) {
+                assertTrue(false);

Review comment:
       same as above, just use `fail()`

##########
File path: 
phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertValuesIT.java
##########
@@ -44,11 +45,9 @@
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.phoenix.exception.SQLExceptionCode;
 import org.apache.phoenix.jdbc.PhoenixConnection;
+import org.apache.phoenix.schema.SequenceNotFoundException;
 import org.apache.phoenix.schema.types.PInteger;
-import org.apache.phoenix.util.DateUtil;
-import org.apache.phoenix.util.EnvironmentEdgeManager;
-import org.apache.phoenix.util.SchemaUtil;
-import org.apache.phoenix.util.TestUtil;
+import org.apache.phoenix.util.*;

Review comment:
       Please revert this to individual imports, I think you just need one 
additional import.

##########
File path: 
phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertValuesIT.java
##########
@@ -670,5 +669,144 @@ public void testColumnQualifierForUpsertedValues() throws 
Exception {
             assertTrue(next.containsColumn(Bytes.toBytes("CF2"), 
PInteger.INSTANCE.toBytes(3)));
         }
     }
-    
+
+    @Test
+    public void testUpsertValueWithDiffSequenceAndConnections() throws 
Exception {
+        String tableName = generateUniqueName();
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            conn.setAutoCommit(true);
+            PreparedStatement createTableStatement = 
conn.prepareStatement(String.format("CREATE TABLE IF NOT EXISTS " +
+                    "%s (SERVICE VARCHAR NOT NULL, SEQUENCE_NUMBER BIGINT NOT 
NULL , " +
+                    "CONSTRAINT PK PRIMARY KEY (SERVICE, SEQUENCE_NUMBER)) 
MULTI_TENANT = TRUE", tableName));
+            createTableStatement.execute();
+        }
+
+        testGlobalSequenceUpsertWithTenantConnection(tableName);
+        testGlobalSequenceUpsertWithGlobalConnection(tableName);
+        testTenantSequenceUpsertWithSameTenantConnection(tableName);
+        testTenantSequenceUpsertWithDifferentTenantConnection(tableName);
+        testTenantSequenceUpsertWithGlobalConnection(tableName);

Review comment:
       Nice coverage




-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


> Tenant Connection is not able to access/validate Global Sequences
> -----------------------------------------------------------------
>
>                 Key: PHOENIX-6506
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-6506
>             Project: Phoenix
>          Issue Type: Bug
>            Reporter: Lokesh Khurana
>            Assignee: Lokesh Khurana
>            Priority: Major
>         Attachments: PHOENIX-6506-test.patch, PHOENIX-6506.patch
>
>
> In our test environment we were using sequence(created using global 
> connection) in our Table, recently we updated that table to be MULTI_TENANT 
> and both types of connections (tenant and global) are needs to upsert data 
> into Table.
> Tenant connections are not able to upsert data into table as it is not able 
> to validate sequence and getting SequenceNotFoundException. 
> Adding patch with Test failing due to same scenario.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to