djanand commented on a change in pull request #1422:
URL: https://github.com/apache/cassandra/pull/1422#discussion_r828812886



##########
File path: 
test/unit/org/apache/cassandra/cql3/validation/operations/AlterTest.java
##########
@@ -780,4 +781,110 @@ public void 
testAlterByAddingColumnToCompactTableShouldFail() throws Throwable
         assertInvalidMessage("Cannot add new column to a COMPACT STORAGE 
table",
                              "ALTER TABLE %s ADD column1 text");
     }
+
+    @Test
+    public void testAlterTableWithoutCreateTableOrIfExistsClause()
+    {
+        String tbl1 = KEYSPACE + "." + createTableName();
+        assertAlterTableThrowsException(InvalidRequestException.class, 
String.format("Table '%s' doesn't exist", tbl1),
+                                        "ALTER TABLE %s ADD myCollection 
list<text>;");
+    }
+
+    @Test
+    public void testAlterTableWithoutCreateTableWithIfExists() throws Throwable
+    {
+        String tbl1 = KEYSPACE + "." + createTableName();
+        assertNull(execute(String.format("ALTER TABLE IF EXISTS %s ADD 
myCollection list<text>;", tbl1)));
+    }
+
+    @Test
+    public void testAlterTableWithIfExists() throws Throwable
+    {
+        createTable("CREATE TABLE %s (a int, b int, PRIMARY KEY (a, b)); ");
+        alterTable("ALTER TABLE IF EXISTS %s ADD myCollection list<text>;");
+        execute("INSERT INTO %s (a, b, myCollection) VALUES (1, 2, ['first 
element']);");
+
+        assertRows(execute("SELECT * FROM %s;"), row(1, 2, list("first 
element")));
+    }
+
+    @Test
+    public void testAlterTableAddColWithIfNotExists() throws Throwable
+    {
+        createTable("CREATE TABLE %s (a int, b int, PRIMARY KEY (a, b)); ");
+        alterTable("ALTER TABLE %s ADD IF NOT EXISTS a int;");
+        execute("INSERT INTO %s (a, b) VALUES (1, 2);");
+
+        assertRows(execute("SELECT * FROM %s;"), row(1, 2));
+    }
+
+    @Test
+    public void testAlterTableAddExistingColumnWithoutIfExists()
+    {
+        createTable("CREATE TABLE %s (a int, b int, PRIMARY KEY (a, b)); ");
+        assertAlterTableThrowsException(InvalidRequestException.class,
+                                        String.format("Column with name '%s' 
already exists", "a"), "ALTER TABLE IF EXISTS %s ADD a int");

Review comment:
       Addressed the formatting in latest commit




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



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to