2017-03-16 82 views
2

我想從bash命令執行cql查詢。從命令行運行cassandra查詢

[cqlsh 3.1.8 | Cassandra 1.2.19 | CQL spec 3.0.5 | Thrift protocol 19.36.2]

[[email protected] ~]# /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 

有什麼建議?

+0

如何:'cqlsh -e「SELECT column FROM some_keyspace.Users where key = value;」'? – markc

+1

運行'cqlsh -h'獲得支持選項 –

回答

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 
0

啓動CQLSH後,您可以使用-f從文件或源文件執行。我不認爲-e是該版本的有效選項。

1

首先,你應該認真考慮升級。您錯過了很多新功能和錯誤修復。

其次,在卡桑德拉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) 
+0

好的,我怎樣才能輸出列值?沒有列名和下劃線 – 4EACH

+0

哪個版本開始支持-e標誌? – 4EACH

+0

@ 4EACH在Cassandra 2.0中引入了'-e'標誌。 – Aaron