从命令行运行Cassandra查询

4
我希望能够从bash命令执行CQL查询。

[cqlsh 3.1.8 | Cassandra 1.2.19 | CQL规范3.0.5 | Thrift协议19.36.2]

[root@hostname ~]# /opt/apache-cassandra-1.2.19/bin/cqlsh -k "some_keyspace" -e "SELECT column FROM Users where key=value"

我得到了:

cqlsh: 错误:没有这个选项:-e

选项:

  --version             show program's version number and exit
  -h, --help            show this help message and exit
  -C, --color           Always use color output
  --no-color            Never use color output
  -u USERNAME, --username=USERNAME
                        Authenticate as user.
  -p PASSWORD, --password=PASSWORD
                        Authenticate using password.
  -k KEYSPACE, --keyspace=KEYSPACE
                        Authenticate to the given keyspace.
  -f FILE, --file=FILE  Execute commands from FILE, then exit
  -t TRANSPORT_FACTORY, --transport-factory=TRANSPORT_FACTORY
                        Use the provided Thrift transport factory function.
  --debug               Show additional debugging information
  --cqlversion=CQLVERSION
                        Specify a particular CQL version (default: 3.0.5).
                        Examples: "2", "3.0.0-beta1"
  -2, --cql2            Shortcut notation for --cqlversion=2
  -3, --cql3            Shortcut notation for --cqlversion=3

有什么建议吗?

如何使用以下命令:cqlsh -e "SELECT column FROM some_keyspace.Users where key=value;" - markc
1
运行 cqlsh -h 以获取支持的选项。 - undefined_variable
3个回答

2

首先,您应该认真考虑升级。这样您就可以享受到许多新功能和错误修复。

其次,在Cassandra 1.2中使用cqlsh时,您可以使用-f标志来指定包含cql语句的文件:

$ echo "use system_auth; SELECT role,is_superuser FROM roles WHERE role='cassandra';" > userQuery.cql
$ bin/cqlsh -u aploetz -p reindeerFlotilla -f userQuery.cql 

 role      | is_superuser
-----------+--------------
 cassandra |         True


(1 rows)

好的,我该如何输出仅包含列值的内容?不包括列名和下划线。 - 4EACH
哪个版本开始支持 -e 标志? - 4EACH
@4EACH -e 标志是在 Cassandra 2.0 中引入的。 - Aaron

0

在启动CQLSH后,您可以使用-f从文件或SOURCE执行。我认为-e不是该版本的有效选项。


0

它有点混乱而且不稳定,但这就是答案:

/opt/apache-cassandra-1.2.19/bin/cqlsh -k "keyspace" -f  /path/to/file.cql  > /path/to/output.txt
tail -2 /path/to/output.txt | head -1 > /path/to/output-value.txt

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接