Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在cassandra表中动态添加列_Cassandra_Hector_Cql_Cql3 - Fatal编程技术网

在cassandra表中动态添加列

在cassandra表中动态添加列,cassandra,hector,cql,cql3,Cassandra,Hector,Cql,Cql3,我在CQl3中有下表 create table userInfo ( userid text, email text, firstName text, lastName text, city text, Primary key (userid,email) ); 现在我想根据用户的选择动态地将两列COL1和COL2添加到这个表中。我该怎么做 我做了以下事情 ALTER TABLE ADD COL1 text; ALTER TABLE ADD COL2 text; 它将COL1和C

我在CQl3中有下表

create table userInfo
(
 userid text,
 email text,
 firstName text,
 lastName text,
 city text,
 Primary key (userid,email)
);
现在我想根据用户的选择动态地将两列COL1和COL2添加到这个表中。我该怎么做

我做了以下事情

ALTER TABLE ADD COL1 text;
ALTER TABLE ADD COL2 text;
它将COL1和COL2添加到表中。 然后,当我插入userInfo(…,…,COL1,…)值(…,…,'some value',…)时,它只在COL1中输入NULL


建议一些动态添加列的好方法。如果我想添加大量的列,我不认为更改表是一个好方法。我正在使用java程序中的Hector库动态添加列。

也许CQL不是您的最佳选择。CQL要求您预先定义模式,以支持类似SQL的语法功能,但它带走了Cassandra的一些有用的动态特性。使用几乎所有Cassandra客户机基于节俭的变异功能,您可以简单地命名要编写的列,如果不存在,将为您创建该列

例如:

ks.insert(key, createColumnPath(colName), bytes(value));

也许CQL不是你最好的选择。CQL要求您预先定义模式,以支持类似SQL的语法功能,但它带走了Cassandra的一些有用的动态特性。使用几乎所有Cassandra客户机基于节俭的变异功能,您可以简单地命名要编写的列,如果不存在,将为您创建该列

例如:

ks.insert(key, createColumnPath(colName), bytes(value));

我发现CQL中的一个解决方案是使用Map。我将添加特定于功能的地图。这比节俭的解决方案更好吗?你能给我一个使用hector向CQL添加地图的简单完整示例吗?我发现CQL中的一个解决方案是使用地图。我将添加特定于功能的地图。这比节俭的解决方案更好吗?你能给我一个简单完整的例子,使用hector向CQL添加地图吗。