將Cassandra查詢導出成CSV和JSON格式的工具:CQLKIT

jopen 9年前發布 | 42K 次閱讀 CQLKIT NoSQL數據庫

cqlkit 是一個CLI工具用于將Cassandra查詢導出成CSV和JSON格式。 

Here is a simple some examples.

Export JSON for the system columns in cassandra cluster.

cql2json -q "select * from system.schema_columns"

Export CSV for the system columns in cassandra cluster.

cql2csv -q "select * from system.schema_columns"

Requirement

  • Java8

Installation

  1. Download from release page.
  2. Unzip the package.
  3. Add$CQLKIT_PATH/binto the PATH environment variable

Usage

CQL2CSV

usage: cql2csv [-c contactpoint] [-q query] [FILE]
File       The file to use as CQL query. If both FILE and QUERY are
           omitted, query will be read from STDIN.

 -c <arg>              The contact point.
 -cqlshrc <arg>        Use an alternative cqlshrc file location, path.
 -h,--help             Show the help and exit
 -H,--no-header-row    Do not output column names.
 -k <arg>              The keyspace to use.
 -l,--linenumbers      Insert a column of line numbers at the front of the
                       output. Useful when piping to grep or as a simple
                       primary key.
 -p,--parallel <arg>   The level of parallelism to run the task. Default
                       is sequential.
 -q,--query <arg>      The CQL query to execute. If specified, it
                       overrides FILE and STDIN.
 -u <arg>              The user to authenticate.
 -v,--version          Print the version

CQL2JSON

usage: cql2json [-c contactpoint] [-q query] [FILE]
File       The file to use as CQL query. If both FILE and QUERY are
           omitted, query will be read from STDIN.

 -c <arg>                  The contact point.
 -cqlshrc <arg>            Use an alternative cqlshrc file location, path.
 -h,--help                 Show the help and exit
 -j,--json-columns <arg>   The columns that contains json string. The
                           content would be used as json object instead of
                           plain text. Columns are separated by comma.
 -k <arg>                  The keyspace to use.
 -l,--linenumbers          Insert a column of line numbers at the front of
                           the output. Useful when piping to grep or as a
                           simple primary key.
 -p,--parallel <arg>       The level of parallelism to run the task.
                           Default is sequential.
 -q,--query <arg>          The CQL query to execute. If specified, it
                           overrides FILE and STDIN.
 -u <arg>                  The user to authenticate.
 -v,--version              Print the version

Setup the cqlshrc

To connect to cassandra cluster, although we can use-cand-kto specify the contact server and keyspace respectively, to preapre a cqlshrc is recommended to simply your query. cqlshrc is used by cqlsh. cqlkit leverages this file to connect to your cluster. Here is the setup steps.

  1. Create the cqlshrc file at~/.cassandra/cqlshrc
  2. Here is the example format.

[authentication]
keyspace = system

[connection]
hostname = 192.168.59.103
port = 9042

; vim: set ft=dosini :

推薦的第三方工具

  • csvkit - A toolkit to handle CSV files. There are many useful CLI tools included.

  • q - Another CSV tool which focuses on query on CSV files.

  • json2csv - Convert JSON format to CSV format

  • jq - a lightweight and flexible command-line JSON processor.

項目主頁:http://www.baiduhome.net/lib/view/home/1438239676269

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!