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

Marcus Truscello commented on CASSANDRA-15504:
----------------------------------------------

That's unfortunate to hear.  However, I was thinking something a bit more 
simple: making SMALLINT considered "compatible" with INTs.

Currently, it appears that Int32s are only compatible with themselves (they 
lack an {{isValueCompatibleWith}} method) but Shorts do [offer a toInt 
method|[https://github.com/apache/cassandra/blob/06209037ea56b5a2a49615a99f1542d6ea1b2947/src/java/org/apache/cassandra/db/marshal/ShortType.java#L102-L105]],
 so it should be possible to upgrade Shorts to Int32s.

But if I'm understanding you correctly, that solution wouldn't work, would it?  
It sounds like the binary representations are being blindly deserialized to the 
current type, and that ShortType and Int32Type serialize to different formats.  
That means a fix would require A) modifying 
[Int32Serializer|https://github.com/apache/cassandra/blob/06209037ea56b5a2a49615a99f1542d6ea1b2947/src/java/org/apache/cassandra/serializers/Int32Serializer.java#L39-L43]
 to handle deserializing 2-byte shorts and B) modifying Int32Type to list 
itself as compatible with ShortType.

Handling _all_ type conversions in that manner would be terrible, but doing it 
for fixed-size integer types doesn't sound unreasonable.

> INT is incompatible with previous type SMALLINT
> -----------------------------------------------
>
>                 Key: CASSANDRA-15504
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-15504
>             Project: Cassandra
>          Issue Type: Bug
>            Reporter: Marcus Truscello
>            Priority: Normal
>
> With the release of Cassandra 3.11.5 and the fixing of CASSANDRA-14948, it 
> now appears that you can no longer re-add a SMALLINT column as an INT type.  
> This is rather surprising as any SMALLINT value should be representable by an 
> INT type.
> The following example was run on Cassandra 3.11.5 on CentOS 7 installed from 
> official RedHat repo:
>  
>  
> {noformat}
> cqlsh> CREATE KEYSPACE demo WITH replication = {'class':'SimpleStrategy', 
> 'replication_factor' : 1};
> cqlsh> CREATE TABLE demo.demo_table (
>    ...   user_id BIGINT,
>    ...   created TIMESTAMP,
>    ...   points  SMALLINT,
>    ...   PRIMARY KEY (user_id, created)
>    ... ) WITH CLUSTERING ORDER BY (created DESC);
> cqlsh> ALTER TABLE demo.demo_table DROP points;
> cqlsh> ALTER TABLE demo.demo_table ADD  points INT;
> InvalidRequest: Error from server: code=2200 [Invalid query] message="Cannot 
> re-add previously dropped column 'points' of type int, incompatible with 
> previous type smallint"{noformat}
>  
>  



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

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

Reply via email to