phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tdsi...@apache.org
Subject phoenix git commit: PHOENIX-2497 Disallow usage of ROW_TIMESTAMP with transactional tables
Date Fri, 11 Dec 2015 19:00:25 GMT
Repository: phoenix
Updated Branches:
  refs/heads/master f79005a76 -> e99d2ed74


PHOENIX-2497 Disallow usage of ROW_TIMESTAMP with transactional tables


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

Branch: refs/heads/master
Commit: e99d2ed74905c4445aca25298551daaa86aca7d9
Parents: f79005a
Author: Thomas D'Silva <tdsilva@salesforce.com>
Authored: Thu Dec 10 15:52:58 2015 -0800
Committer: Thomas D'Silva <tdsilva@salesforce.com>
Committed: Fri Dec 11 11:00:07 2015 -0800

----------------------------------------------------------------------
 .../apache/phoenix/end2end/AlterTableIT.java    |  2 ++
 .../org/apache/phoenix/tx/TransactionIT.java    | 24 ++++++++++++++++++++
 .../phoenix/exception/SQLExceptionCode.java     |  2 ++
 .../apache/phoenix/schema/MetaDataClient.java   | 14 ++++++++++++
 .../org/apache/phoenix/util/SchemaUtil.java     |  4 ++++
 5 files changed, 46 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/e99d2ed7/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java
index c86f8c5..122ec16 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java
@@ -2190,6 +2190,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
 			// creating a transactional table should fail if transactions are disabled
 			try {
 				conn.createStatement().execute("CREATE TABLE DEMO1(k INTEGER PRIMARY KEY, v VARCHAR)
TRANSACTIONAL=true");
+				fail();
 			} catch (SQLException e) {
 				assertEquals(SQLExceptionCode.CANNOT_CREATE_TXN_TABLE_IF_TXNS_DISABLED.getErrorCode(),
e.getErrorCode());
 			}
@@ -2197,6 +2198,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
 			conn.createStatement().execute("CREATE TABLE DEMO2(k INTEGER PRIMARY KEY, v VARCHAR)");
 			try {
 				conn.createStatement().execute("ALTER TABLE DEMO2 SET TRANSACTIONAL=true");
+				fail();
 			} catch (SQLException e) {
 				assertEquals(SQLExceptionCode.CANNOT_ALTER_TO_BE_TXN_IF_TXNS_DISABLED.getErrorCode(),
e.getErrorCode());
 			}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/e99d2ed7/phoenix-core/src/it/java/org/apache/phoenix/tx/TransactionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/tx/TransactionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/tx/TransactionIT.java
index 2061f45..56a9bdd 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/tx/TransactionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/tx/TransactionIT.java
@@ -548,4 +548,28 @@ public class TransactionIT extends BaseHBaseManagedTimeIT {
         assertTrue(conn.unwrap(PhoenixConnection.class).getTable(new PTableKey(null, "DEMO")).isTransactional());
         assertTrue(conn.unwrap(PhoenixConnection.class).getTable(new PTableKey(null, "DEMO_IDX")).isTransactional());
     }
+    
+    @Test
+    public void testRowTimestampDisabled() throws SQLException {
+    	Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+	        conn.setAutoCommit(false);
+	        Statement stmt = conn.createStatement();
+	        try {
+	        	stmt.execute("CREATE TABLE DEMO(k VARCHAR, v VARCHAR, d DATE NOT NULL, CONSTRAINT
PK PRIMARY KEY(k,d ROW_TIMESTAMP)) TRANSACTIONAL=true");
+	        	fail();
+	        }
+        	catch(SQLException e) {
+        		assertEquals(SQLExceptionCode.CANNOT_CREATE_TXN_TABLE_WITH_ROW_TIMESTAMP.getErrorCode(),
e.getErrorCode());
+        	}
+	        stmt.execute("CREATE TABLE DEMO(k VARCHAR, v VARCHAR, d DATE NOT NULL, CONSTRAINT
PK PRIMARY KEY(k,d ROW_TIMESTAMP))");
+	        try {
+	        	stmt.execute("ALTER TABLE DEMO SET TRANSACTIONAL=true");
+	        	fail();
+	        }
+        	catch(SQLException e) {
+        		assertEquals(SQLExceptionCode.CANNOT_ALTER_TO_BE_TXN_WITH_ROW_TIMESTAMP.getErrorCode(),
e.getErrorCode());
+        	}
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/e99d2ed7/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java
----------------------------------------------------------------------
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 fb8ebfd..39f2c14 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
@@ -278,6 +278,8 @@ public enum SQLExceptionCode {
     TRANSACTION_FAILED(1077, "44A08", "Transaction Failure "),
     CANNOT_CREATE_TXN_TABLE_IF_TXNS_DISABLED(1078, "44A09", "Cannot create a transactional
table if transactions are disabled"),
     CANNOT_ALTER_TO_BE_TXN_IF_TXNS_DISABLED(1079, "44A10", "Cannot alter table to be transactional
table if transactions are disabled"),
+    CANNOT_CREATE_TXN_TABLE_WITH_ROW_TIMESTAMP(1080, "44A11", "Cannot create a transactional
table if transactions are disabled"),
+    CANNOT_ALTER_TO_BE_TXN_WITH_ROW_TIMESTAMP(1081, "44A12", "Cannot alter table to be transactional
table if transactions are disabled"),
 
     /** Sequence related */
     SEQUENCE_ALREADY_EXIST(1200, "42Z00", "Sequence already exists.", new Factory() {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/e99d2ed7/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
index ccfb1cb..9c365ab 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
@@ -1718,6 +1718,14 @@ public class MetaDataClient {
                 .setSchemaName(schemaName).setTableName(tableName)
                 .build().buildException();
             }
+            // can't create a transactional table if it has a row timestamp column
+            if (pkConstraint.getNumColumnsWithRowTimestamp()>0 && transactional)
{
+            	throw new SQLExceptionInfo.Builder(SQLExceptionCode.CANNOT_CREATE_TXN_TABLE_WITH_ROW_TIMESTAMP)
+                .setSchemaName(schemaName).setTableName(tableName)
+                .build().buildException();
+            }
+            
+            
             tableProps.put(PhoenixDatabaseMetaData.TRANSACTIONAL, transactional);
             if (transactional) {
                 // If TTL set, use Tephra TTL property name instead
@@ -2667,6 +2675,12 @@ public class MetaDataClient {
                         	throw new SQLExceptionInfo.Builder(SQLExceptionCode.CANNOT_ALTER_TO_BE_TXN_IF_TXNS_DISABLED)
                             .setSchemaName(schemaName).setTableName(tableName).build().buildException();
                         }
+                        // cannot make a table transactional if it has a row timestamp column
+                        if (SchemaUtil.hasRowTimestampColumn(table)) {
+                        	throw new SQLExceptionInfo.Builder(SQLExceptionCode.CANNOT_ALTER_TO_BE_TXN_WITH_ROW_TIMESTAMP)
+                            .setSchemaName(schemaName).setTableName(tableName)
+                            .build().buildException();
+                        }
                         timeStamp = TransactionUtil.getTableTimestamp(connection, isTransactional);
                         changingPhoenixTableProperty = true;
                         nonTxToTx = true;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/e99d2ed7/phoenix-core/src/main/java/org/apache/phoenix/util/SchemaUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/SchemaUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/SchemaUtil.java
index cb8aced..c6a20b3 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/SchemaUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/SchemaUtil.java
@@ -886,4 +886,8 @@ public class SchemaUtil {
         }
         return columnInfoList;
     }
+    
+    public static boolean hasRowTimestampColumn(PTable table) {
+    	return table.getRowTimestampColPos()>0;
+    }
 }


Mime
View raw message