0

我必须在我的键空间中创建多个列族。一种方法是一个一个地创建列族。但就我而言,我有大约 100 个列族,所以我不能一个一个地做……所以有什么办法,我可以通过某种方式创建多个列族可以在短时间内为我创建多个列族的脚本?

create column family USER_DATA_SECOND_1
with comparator = 'UTF8Type'
and key_validation_class = 'CompositeType(DateType,UTF8Type)'
and default_validation_class = 'BytesType'
and gc_grace = 86400

create column family USER_DATA_SECOND_2
with comparator = 'UTF8Type'
and key_validation_class = 'CompositeType(DateType,UTF8Type)'
and default_validation_class = 'BytesType'
and gc_grace = 86400

create column family USER_DATA_SECOND_3
with comparator = 'UTF8Type'
and key_validation_class = 'CompositeType(DateType,UTF8Type)'
and default_validation_class = 'BytesType'
and gc_grace = 86400

....
....
....

create column family USER_DATA_SECOND_100
with comparator = 'UTF8Type'
and key_validation_class = 'CompositeType(DateType,UTF8Type)'
and default_validation_class = 'BytesType'
and gc_grace = 86400

并且在创建这些多个列族之后..假设如果我需要再次删除所有这些列族,那么如何再次使用一些脚本来做到这一点?

下面是方法,我现在正在从我的本地机器到我的登台 cassandra 服务器一个一个地创建列族,这不是我想要的..

C:\Apache Cassandra\apache-cassandra-1.2.3\bin>cassandra-cli -h sc-cdbhost01.vip.slc.qa.host.com
Starting Cassandra Client
Connected to: "Staging Cluster cass01" on sc-cdbhost01.vip.slc.qa.host.com/9160
Welcome to Cassandra CLI version 1.2.3

Type 'help;' or '?' for help.
Type 'quit;' or 'exit;' to quit.

[default@unknown] use profileks;
Authenticated to keyspace: profileks
[default@profileks] create column family USER_DATA_SECOND_1
...     with comparator = 'UTF8Type'
...     and key_validation_class = 'CompositeType(DateType,UTF8Type)'
...     and default_validation_class = 'BytesType'
...     and gc_grace = 86400;
27fe1848-c7de-3994-9289-486a9bbbf344
[default@profileks]

谁能帮助我是否可以通过某种脚本创建多个列族,然后通过某种脚本也删除这些列族?

4

3 回答 3

1

以下是示例脚本

键空间创建脚本

drop keyspace my_keyspace;
create keyspace my_keyspace with placement_strategy = 'org.apache.cassandra.locator.SimpleStrategy' and strategy_options = {replication_factor:1};

要执行它:

cassandra-cli -h <hostname> -p <port> -u <user> -pw <password> -f <keyspace_script>


架构创建脚本

create column family USER_DATA_SECOND_1 with comparator = 'UTF8Type' and key_validation_class = 'CompositeType(DateType,UTF8Type)' and default_validation_class = 'BytesType' and gc_grace = 86400;
create column family USER_DATA_SECOND_2 with comparator = 'UTF8Type' and key_validation_class = 'CompositeType(DateType,UTF8Type)' and default_validation_class = 'BytesType' and gc_grace = 86400;
...

要执行它:

cassandra-cli -h <hostname> -p <port> -u <user> -pw <password> -k my_keyspace -f <schema_script>
于 2013-09-27T07:00:57.113 回答
0

@TechGeeky

cassandra-cli -f -k 将在声明的键空间中执行脚本文件中的所有命令

为了从头开始删除和创建 CF,我们曾经有一个 2 脚本可以执行以下操作:

键空间脚本

1 删除键空间 xxx

2 创建密钥空间 xxx ...

结构脚本

1 创建列族...

...

n. 创建列族

一件重要的事情,创建列族应该保持在 1 行。删除所有换行符。

于 2013-09-26T20:23:19.420 回答
0

您可以使用SOURCE 'file'命令来执行写入文件中的整个语句集。请参考链接

例如:在 .txt 文件中,您编写了一些模式、创建键空间、创建列族和许多其他相关内容。然后使用 SOURCE 命令执行文件中的所有语句。

于 2013-09-27T08:59:37.690 回答