2016-12-27 121 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>