You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ch...@apache.org on 2019/10/17 01:38:55 UTC

[phoenix] branch master updated: PHOENIX-5524: Connections with SCN should fail mutations on tables with any index

This is an automated email from the ASF dual-hosted git repository.

chinmayskulkarni pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/phoenix.git


The following commit(s) were added to refs/heads/master by this push:
     new efbed5a  PHOENIX-5524: Connections with SCN should fail mutations on tables with any index
efbed5a is described below

commit efbed5a33861bc87f541bddfd8808fe0a6e9b125
Author: Chinmay Kulkarni <ch...@gmail.com>
AuthorDate: Tue Oct 15 00:08:41 2019 -0700

    PHOENIX-5524: Connections with SCN should fail mutations on tables with any index
---
 .../apache/phoenix/end2end/UpsertWithSCNIT.java    | 55 +++++++++++++++-------
 .../org/apache/phoenix/compile/UpsertCompiler.java | 11 ++---
 .../apache/phoenix/exception/SQLExceptionCode.java |  7 ++-
 3 files changed, 46 insertions(+), 27 deletions(-)

diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertWithSCNIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertWithSCNIT.java
index 40bb883..c21f84e 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertWithSCNIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertWithSCNIT.java
@@ -18,14 +18,11 @@
 package org.apache.phoenix.end2end;
 
 import org.apache.phoenix.exception.SQLExceptionCode;
-import org.apache.phoenix.exception.SQLExceptionInfo;
-import org.junit.Assert;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 
 import java.sql.Connection;
-import java.sql.Date;
 import java.sql.DriverManager;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
@@ -33,7 +30,6 @@ import java.sql.SQLException;
 import java.util.Properties;
 
 import static org.hamcrest.CoreMatchers.containsString;
-import static org.hamcrest.core.Is.is;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
@@ -44,10 +40,10 @@ public class UpsertWithSCNIT extends ParallelStatsDisabledIT {
     @Rule
     public final ExpectedException exception = ExpectedException.none();
     Properties props = null;
-    PreparedStatement prep = null;
+    private PreparedStatement prep = null;
     String tableName =null;
 
-    private void helpTestUpserWithSCNIT(boolean rowColumn, boolean txTable,
+    private void helpTestUpsertWithSCNIT(boolean rowColumn, boolean txTable,
                                         boolean mutable, boolean local, boolean global)
             throws SQLException {
 
@@ -57,8 +53,8 @@ public class UpsertWithSCNIT extends ParallelStatsDisabledIT {
                 + (rowColumn ? "CREATED_DATE DATE NOT NULL, ":"")
                 + "METRIC_ID CHAR(15) NOT NULL,METRIC_VALUE VARCHAR(50) CONSTRAINT PK PRIMARY KEY("
                 + (rowColumn? "CREATED_DATE ROW_TIMESTAMP, ":"") + "METRIC_ID)) "
-                + (mutable? "IMMUTABLE_ROWS=false":"" )
-                + (txTable ? "TRANSACTION_PROVIDER='TEPHRA',TRANSACTIONAL=true":"");
+                + "IMMUTABLE_ROWS=" + (mutable? "false" : "true" )
+                + (txTable ? ", TRANSACTION_PROVIDER='TEPHRA',TRANSACTIONAL=true":"");
         props = new Properties();
         Connection conn = DriverManager.getConnection(getUrl(), props);
         conn.createStatement().execute(createTable);
@@ -81,7 +77,7 @@ public class UpsertWithSCNIT extends ParallelStatsDisabledIT {
     @Test // See https://issues.apache.org/jira/browse/PHOENIX-4983
     public void testUpsertOnSCNSetTxnTable() throws SQLException {
 
-        helpTestUpserWithSCNIT(false, true, false, false, false);
+        helpTestUpsertWithSCNIT(false, true, false, false, false);
         exception.expect(SQLException.class);
         exception.expectMessage(containsString(String.valueOf(
                 SQLExceptionCode
@@ -93,7 +89,7 @@ public class UpsertWithSCNIT extends ParallelStatsDisabledIT {
     @Test
     public void testUpsertOnSCNSetMutTableWithoutIdx() throws Exception {
 
-        helpTestUpserWithSCNIT(false, false, true, false, false);
+        helpTestUpsertWithSCNIT(false, false, true, false, false);
         prep.executeUpdate();
         props = new Properties();
         Connection conn = DriverManager.getConnection(getUrl(),props);
@@ -107,7 +103,7 @@ public class UpsertWithSCNIT extends ParallelStatsDisabledIT {
     @Test
     public void testUpsertOnSCNSetTable() throws Exception {
 
-        helpTestUpserWithSCNIT(false, false, false, false, false);
+        helpTestUpsertWithSCNIT(false, false, false, false, false);
         prep.executeUpdate();
         props = new Properties();
         Connection conn = DriverManager.getConnection(getUrl(),props);
@@ -121,34 +117,59 @@ public class UpsertWithSCNIT extends ParallelStatsDisabledIT {
     @Test
     public void testUpsertOnSCNSetMutTableWithLocalIdx() throws Exception {
 
-        helpTestUpserWithSCNIT(false, false, true, true, false);
+        helpTestUpsertWithSCNIT(false, false, true, true, false);
         exception.expect(SQLException.class);
         exception.expectMessage(containsString(String.valueOf(
                 SQLExceptionCode
-                .CANNOT_UPSERT_WITH_SCN_FOR_MUTABLE_TABLE_WITH_INDEXES
+                .CANNOT_UPSERT_WITH_SCN_FOR_TABLE_WITH_INDEXES
                 .getErrorCode())));
         prep.executeUpdate();
     }
+
+    @Test
+    public void testUpsertOnSCNSetImmutableTableWithLocalIdx() throws Exception {
+
+        helpTestUpsertWithSCNIT(false, false, false, true, false);
+        exception.expect(SQLException.class);
+        exception.expectMessage(containsString(String.valueOf(
+                SQLExceptionCode
+                        .CANNOT_UPSERT_WITH_SCN_FOR_TABLE_WITH_INDEXES
+                        .getErrorCode())));
+        prep.executeUpdate();
+    }
+
     @Test
     public void testUpsertOnSCNSetMutTableWithGlobalIdx() throws Exception {
 
-        helpTestUpserWithSCNIT(false, false, true, false, true);
+        helpTestUpsertWithSCNIT(false, false, true, false, true);
         exception.expect(SQLException.class);
         exception.expectMessage(containsString(String.valueOf(
                 SQLExceptionCode
-                        .CANNOT_UPSERT_WITH_SCN_FOR_MUTABLE_TABLE_WITH_INDEXES
+                        .CANNOT_UPSERT_WITH_SCN_FOR_TABLE_WITH_INDEXES
                         .getErrorCode())));
         prep.executeUpdate();
+    }
+
+    @Test
+    public void testUpsertOnSCNSetImmutableTableWithGlobalIdx() throws Exception {
 
+        helpTestUpsertWithSCNIT(false, false, false, false, true);
+        exception.expect(SQLException.class);
+        exception.expectMessage(containsString(String.valueOf(
+                SQLExceptionCode
+                        .CANNOT_UPSERT_WITH_SCN_FOR_TABLE_WITH_INDEXES
+                        .getErrorCode())));
+        prep.executeUpdate();
     }
+
     @Test
     public void testUpsertOnSCNSetWithRowTSColumn() throws Exception {
 
-        helpTestUpserWithSCNIT(true, false, false, false, false);
+        helpTestUpsertWithSCNIT(true, false, false, false, false);
         exception.expect(SQLException.class);
         exception.expectMessage(containsString(String.valueOf(
                 SQLExceptionCode
-                        .CANNOT_UPSERT_WITH_SCN_FOR_ROW_TIMSTAMP_COLUMN
+                        .CANNOT_UPSERT_WITH_SCN_FOR_ROW_TIMESTAMP_COLUMN
                         .getErrorCode())));
         prep.executeUpdate();
     }
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
index 0cba233..8e7aa05 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
@@ -368,7 +368,7 @@ public class UpsertCompiler {
         // Cannot update:
         // - read-only VIEW
         // - transactional table with a connection having an SCN
-        // - mutable table with indexes and SCN set
+        // - table with indexes and SCN set
         // - tables with ROW_TIMESTAMP columns
         if (table.getType() == PTableType.VIEW && table.getViewType().isReadOnly()) {
             throw new ReadOnlyTableException(schemaName,tableName);
@@ -382,19 +382,18 @@ public class UpsertCompiler {
                     .CANNOT_SPECIFY_SCN_FOR_TXN_TABLE)
                     .setSchemaName(schemaName)
                     .setTableName(tableName).build().buildException();
-        } else if (!table.isImmutableRows() && connection.getSCN() != null
-                && !table.getIndexes().isEmpty() && !connection.isRunningUpgrade()
-                && !connection.isBuildingIndex()) {
+        } else if (connection.getSCN() != null && !table.getIndexes().isEmpty()
+                && !connection.isRunningUpgrade() && !connection.isBuildingIndex()) {
             throw new SQLExceptionInfo
                     .Builder(SQLExceptionCode
-                    .CANNOT_UPSERT_WITH_SCN_FOR_MUTABLE_TABLE_WITH_INDEXES)
+                    .CANNOT_UPSERT_WITH_SCN_FOR_TABLE_WITH_INDEXES)
                     .setSchemaName(schemaName)
                     .setTableName(tableName).build().buildException();
         } else if(connection.getSCN() != null && !connection.isRunningUpgrade()
                 && !connection.isBuildingIndex() && table.getRowTimestampColPos() >= 0) {
             throw new SQLExceptionInfo
                     .Builder(SQLExceptionCode
-                    .CANNOT_UPSERT_WITH_SCN_FOR_ROW_TIMSTAMP_COLUMN)
+                    .CANNOT_UPSERT_WITH_SCN_FOR_ROW_TIMESTAMP_COLUMN)
                     .setSchemaName(schemaName)
                     .setTableName(tableName).build().buildException();
         }
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java b/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java
index cf6c148..9333b63 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java
@@ -490,12 +490,11 @@ public enum SQLExceptionCode {
 
     STATS_COLLECTION_DISABLED_ON_SERVER(1401, "STS01", "Stats collection attempted but is disabled on server"),
 
-    CANNOT_UPSERT_WITH_SCN_FOR_ROW_TIMSTAMP_COLUMN(901,"43M12",
+    CANNOT_UPSERT_WITH_SCN_FOR_ROW_TIMESTAMP_COLUMN(901,"43M12",
             "Cannot use a connection with SCN set to upsert data for " +
                     "table with ROW_TIMESTAMP column."),
-    CANNOT_UPSERT_WITH_SCN_FOR_MUTABLE_TABLE_WITH_INDEXES(903,"43M14",
-            "Cannot use a connection with SCN set to " +
-                    "upsert data for a mutable table with indexes.");
+    CANNOT_UPSERT_WITH_SCN_FOR_TABLE_WITH_INDEXES(903,"43M14",
+            "Cannot use a connection with SCN set to upsert data for a table with indexes.");
 
 
     private final int errorCode;