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

Bret McGuire commented on CASSANDRA-20003:
------------------------------------------

There is some definite subtlety here.

 

SchemaBuilder.alterTable() returns AlterTableStart which extends several 
operation-specific interfaces (AlterTableAddColumn, AlterTableDropColumn, etc). 
 Methods on each of these return a corresponding *End interface 
(AlterTableDropColumn.dropColum() and variants returns AlterTableDropColumnEnd 
for instance) and these *End interfaces extend their corresponding basic 
interface (AlterTableDropColumnEnd extends AlterTableDropColumn).  This allows 
for nice iterative creation of DDL statements via multiple method calls on the 
builder.

 

Thing is... the PR added support for "if exists" and "if not exists" at the 
table _and_ at the column level.  Examples provided in CASSANDRA-16916 make 
that clear:

 
 * {{ALTER TABLE IF EXISTS myTable ...}}
 * {{ALTER TABLE myTable ADD IF NOT EXISTS ...}}
 * {{ALTER TABLE myTable DROP IF EXISTS ...}}
 * {{ALTER TYPE IF EXISTS myType ...}}
 * {{ALTER TYPE myType ADD IF NOT EXISTS ...}}

 

In an ideal world we'd prolly just add "ifExists()" to both 
AlterTableDropColumn and AlterTableDropColumnEnd.  But since _all_ of these 
interfaces are implemented by a single object (DefaultAlterTable) we have no 
idea of knowing whether the ifExists() method in DefaultAlterTable is being 
called from the table or column builder.

 

Prolly easiest to just use ifTableExists() and ifColumnExists().  It's slightly 
more verbose but it maintains all the current abstractions.

> Add query builder support for "IF EXISTS" and "IF NOT EXISTS" in alter 
> statements
> ---------------------------------------------------------------------------------
>
>                 Key: CASSANDRA-20003
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-20003
>             Project: Cassandra
>          Issue Type: Improvement
>          Components: Client/java-driver
>            Reporter: Bret McGuire
>            Assignee: Bret McGuire
>            Priority: Normal
>
> CASSANDRA-16916 added support for IF EXISTS and IF NOT EXISTS in alter 
> statements.  The fix version indicates that this change was aimed at the 
> 4.1.x release.  The driver's query builder should support this syntax as well.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

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

Reply via email to