2017-03-16 3 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:エラー:いいえ、そのようなオプション:

--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 

任意の提案:

オプション-eを?

+0

どのように: 'cqlsh -e 'select_from 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を使用してファイルまたはSOURCEから実行できます。私は-eがそのバージョンで有効なオプションだとは思わない。

1

まず、アップグレードを真剣に検討する必要があります。あなたは、多くの新機能やバグ修正を見逃しています。

第二に、カサンドラ1.2でcqlshであなたがCQL文を含むファイルを指定する-fフラグを使用することができます。

$ 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

Ok、どうすれば列の値だけを出力できますか?列名とアンダースコアなし – 4EACH

+0

-eフラグのサポートを開始するのはどのバージョンですか? – 4EACH

+0

@ 4EACH '-e'フラグはCassandra 2.0で導入されました。 – Aaron

関連する問題