2016-12-27 137 views
0

在Cassandra中将int移植到bigint最简单的方法是什么?我想创建一个类型为bigint的新列,然后运行脚本以基本设置该列的值=所有行的int列的值,然后删除原始列并重命名新列。不过,我想知道是否有人有更好的选择,因为这种方法并不适合我。Cassandra将int移植到bigint

回答

1

您可以ALTER您的表格,并将您的int列更改为varint类型。检查the documentationALTER TABLEdata types compatibility矩阵。

唯一的另一种选择是你说的:添加一个新的列并逐行填充它。删除第一列可以是完全可选的:如果在执行插入时不分配值,则所有内容都将保持原样,新记录不会消耗空间。

+0

我一直在寻找在varint类型,但我无法找出差异的确切内容和BIGINT之间。我想,因为varint映射到一个java BigInteger,这应该足够了,因为我真正关心的是它足够大,我认为BigInteger在技术上没有上限。就Cassandra而言,在空间等方面还有其他差异吗? – cloudwalker

0

你可以ALTER你的表格存储在卡桑德拉bigint与varint。查看示例 -

[email protected]:demo> CREATE TABLE int_test (id int, name text, primary key(id)); 
[email protected]:demo> SELECT * FROM int_test; 

id | name 
----+------ 

(0 rows) 
[email protected]:demo> INSERT INTO int_test (id, name) VALUES (215478936541111, 'abc'); 
[email protected]:demo> SELECT * FROM int_test ; 

id     | name 
---------------------+--------- 
    215478936541111 | abc 

(1 rows) 
[email protected]:demo> ALTER TABLE demo.int_test ALTER id TYPE varint; 
[email protected]:demo> INSERT INTO int_test (id, name) VALUES (9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999, 'abcd'); 
[email protected]:demo> SELECT * FROM int_test ; 

id                               | name 
------------------------------------------------------------------------------------------------------------------------------+--------- 
                               215478936541111 | abc                          
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 | abcd 

(2 rows) 
[email protected]:demo>