CqlInputFormat 中的 Hadoop Cassandra 宽行
Hadoop Cassandra wide rows in CqlInputFormat
我正在编写一个使用 Cassandra (v2.0.11) 作为其输入和输出的 hadoop 作业。
在我的 hadoop 作业中,我定义了输入列族:
ConfigHelper.setInputColumnFamily(job.getConfiguration(), KEYSPACE, INPUT_COLUMN_FAMILY, WIDE_ROWS);
其中 WIDE_ROWS=true
。我还设置 CqlInputFormat
为读数 class:
job.setInputFormatClass(CqlInputFormat.class);
CqlInputFormat
在写 (link) 的地方使用 CqlRecordReader
:
// Because the old Hadoop API wants us to write to the key and value
// and the new asks for them, we need to copy the output of the new API
// to the old. Thus, expect a small performance hit.
// And obviously this wouldn't work for wide rows. But since ColumnFamilyInputFormat
// and ColumnFamilyRecordReader don't support them, it should be fine for now.
public boolean next(Long key, Row value) throws IOException
{
if (nextKeyValue())
{
((WrappedRow)value).setRow(getCurrentValue());
return true;
}
return false;
}
我很不明白...当我检查ColumnFamilyRecordReader
代码(link)时,似乎使用了宽行...
CqlInputFormat
真的支持宽行吗?你能解释一下吗?
我调查了一下,发现 CQL "transposes" 宽行,因此每一列都分别馈送到映射函数(CqlInputFormat
运行 CQL 查询以从 cassandra 节点获取数据)。
这种方法在处理非常宽的行时不会导致 OOM 异常,因为 CqlInputFormat
使用了 CQL 中可用的分页机制。每页只需要 CqlConfigHelper.getInputCQLPageRowSize
列。
不幸的是,在我的例子中它效率不高,因为我想对每个行键执行 "group by" 操作来计算列数。并且在数千列的循环中递增计数器比仅采用 columns.size()
(如果有这种可能性的话)要慢。
更多阅读:
http://www.datastax.com/dev/blog/cql3-for-cassandra-experts
https://issues.apache.org/jira/browse/CASSANDRA-3264
我正在编写一个使用 Cassandra (v2.0.11) 作为其输入和输出的 hadoop 作业。
在我的 hadoop 作业中,我定义了输入列族:
ConfigHelper.setInputColumnFamily(job.getConfiguration(), KEYSPACE, INPUT_COLUMN_FAMILY, WIDE_ROWS);
其中 WIDE_ROWS=true
。我还设置 CqlInputFormat
为读数 class:
job.setInputFormatClass(CqlInputFormat.class);
CqlInputFormat
在写 (link) 的地方使用 CqlRecordReader
:
// Because the old Hadoop API wants us to write to the key and value
// and the new asks for them, we need to copy the output of the new API
// to the old. Thus, expect a small performance hit.
// And obviously this wouldn't work for wide rows. But since ColumnFamilyInputFormat
// and ColumnFamilyRecordReader don't support them, it should be fine for now.
public boolean next(Long key, Row value) throws IOException
{
if (nextKeyValue())
{
((WrappedRow)value).setRow(getCurrentValue());
return true;
}
return false;
}
我很不明白...当我检查ColumnFamilyRecordReader
代码(link)时,似乎使用了宽行...
CqlInputFormat
真的支持宽行吗?你能解释一下吗?
我调查了一下,发现 CQL "transposes" 宽行,因此每一列都分别馈送到映射函数(CqlInputFormat
运行 CQL 查询以从 cassandra 节点获取数据)。
这种方法在处理非常宽的行时不会导致 OOM 异常,因为 CqlInputFormat
使用了 CQL 中可用的分页机制。每页只需要 CqlConfigHelper.getInputCQLPageRowSize
列。
不幸的是,在我的例子中它效率不高,因为我想对每个行键执行 "group by" 操作来计算列数。并且在数千列的循环中递增计数器比仅采用 columns.size()
(如果有这种可能性的话)要慢。
更多阅读:
http://www.datastax.com/dev/blog/cql3-for-cassandra-experts
https://issues.apache.org/jira/browse/CASSANDRA-3264