繁体   English   中英

在cassandra-cli中如何获取表中的所有列名以及如何在java中使用hector获取它?

[英]in cassandra-cli how to get all column names in a table and how to get it using hector in java?

我正在尝试获取列名但无法获得仅列名称。

在cli我执行命令describe table nodes ,它返回结果:

CREATE TABLE nodes (
  key text PRIMARY KEY,
  id text,
  scores text,
  topic1 text,
  topic2 text,
  topic3 text,
  topic4 text,
  topics text
) WITH COMPACT STORAGE AND
  bloom_filter_fp_chance=0.010000 AND
  caching='KEYS_ONLY' AND
  comment='' AND
  dclocal_read_repair_chance=0.000000 AND
  gc_grace_seconds=864000 AND
  read_repair_chance=0.100000 AND
  replicate_on_write='true' AND
  populate_io_cache_on_flush='false' AND
  compaction={'class': 'SizeTieredCompactionStrategy'} AND
  compression={'sstable_compression': 'SnappyCompressor'};

CREATE INDEX idx_nodes_id ON nodes (id);

正如在这个问题中给出的,我尝试在cli中使用以下命令:

SELECT column_name FROM system.schema_columnfamilies WHERE keyspace_name = 'ianew' AND columnfamily_name = 'nodes';

但它给出了错误:

Bad Request: Undefined name column_name in selection clause
Perhaps you meant to use CQL 2? Try using the -2 option when starting cqlsh.

然后我试着用:

SELECT * FROM system.schema_columnfamilies WHERE keyspace_name = 'ianew' AND columnfamily_name = 'nodes';

它返回了以下所有内容:

    keyspace_name | columnfamily_name | bloom_filter_fp_chance | caching   | column_aliases | comment | compaction_strategy_class                                       | compaction_strategy_options | comparator                               | compression_parameters                                                      | default_read_consistency | default_validator                        | default_write_consistency | gc_grace_seconds | id   | key_alias | key_aliases | key_validator                            | local_read_repair_chance | max_compaction_threshold | min_compaction_threshold | populate_io_cache_on_flush | read_repair_chance | replicate_on_write | subcomparator | type     | value_alias
---------------+-------------------+------------------------+-----------+----------------+---------+-----------------------------------------------------------------+-----------------------------+------------------------------------------+-----------------------------------------------------------------------------+--------------------------+------------------------------------------+---------------------------+------------------+------+-----------+-------------+------------------------------------------+--------------------------+--------------------------+--------------------------+----------------------------+--------------------+--------------------+---------------+----------+-------------
         ianew |             nodes |                   null | KEYS_ONLY |             [] |         | org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy |                          {} | org.apache.cassandra.db.marshal.UTF8Type | {"sstable_compression":"org.apache.cassandra.io.compress.SnappyCompressor"} |                     null | org.apache.cassandra.db.marshal.UTF8Type |                      null |           864000 | null |      null |          [] | org.apache.cassandra.db.marshal.UTF8Type |                        0 |                       32 |                        4 |                      False |                0.1 |               True |          null | Standard |        null

正如在这篇文章中给出 ,我尝试在java中使用hector:

SliceQuery<String, String, String> query = HFactory.createSliceQuery(keyspace, StringSerializer.get(), StringSerializer.get(),  StringSerializer.get());
query.setColumnFamily(columnFamilyName);
query.setKey("key");
query.setRange(null, null, false, Integer.MAX_VALUE);

ColumnSliceIterator<String, String, String> iterator = new ColumnSliceIterator<String, String, String>(query, null, "\uFFFF", false);

while (iterator.hasNext()) {
    HColumnImpl<String, String> column = (HColumnImpl<String, String>) iterator.next();
    System.out.println("Column name = " + column.getName() + "; Column value = " + column.getValue());
    colNames.add(column.getName());
}

但它返回没有结果。

我希望输出类似于:

TABLE nodes:
Columns: key text PRIMARY KEY, id text, scores text, topic1 text, topic2 text, topic3 text, topic4 text, topics text

和赫克托尔的类似结果。

我正在使用的版本:

[cqlsh 2.3.0 | Cassandra 1.2.4 | CQL spec 3.0.0 | Thrift protocol 19.35.0]

在cassandra 1.1中确实可以工作,但是schema_columnfamilies列族从那时起就被修改了。

错误请求:选择子句中未定义的名称column_name

在Cassandra 1.2.x中,有关列的信息位于名为schema_columns的单独键空间中,具有以下模式:

CREATE TABLE schema_columns (
  keyspace_name text,
  columnfamily_name text,
  column_name text,
  component_index int,
  index_name text,
  index_options text,
  index_type text,
  validator text,
  PRIMARY KEY (keyspace_name, columnfamily_name, column_name)
);

尝试这些方面的东西:

 SELECT * FROM system.schema_columns 
 WHERE keyspace_name = 'ianew' AND columnfamily_name = 'nodes';

有关系统键空间内容的文档

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM