我正在写一个使用Cassandra(v2.0.11)作为输入和输出的hadoop作业。
在我的hadoop工作中,我定义了输入列族:
ConfigHelper.setInputColumnFamily(job.getConfiguration(), KEYSPACE, INPUT_COLUMN_FAMILY, WIDE_ROWS);
其中
WIDE_ROWS=true
。我还将CqlInputFormat
设置为阅读类: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“转置”宽行,以便将每一列分别馈给map函数(CqlInputFormat
运行CQL查询以从cassandra节点获取数据)。
当处理非常宽的行时,此方法不会导致OOM异常,因为CqlInputFormat
使用CQL中可用的分页机制。每页只需要CqlConfigHelper.getInputCQLPageRowSize
列。
不幸的是,在我的情况下效率不高,因为我想对每个行键执行“分组依据”操作以对列进行计数。而且,在成千上万个列的循环中增加计数器比仅使用columns.size()
(如果有这种可能)要慢。
了解更多信息:
http://www.datastax.com/dev/blog/cql3-for-cassandra-experts
https://issues.apache.org/jira/browse/CASSANDRA-3264
关于hadoop - CqlInputFormat中的Hadoop Cassandra宽行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28933048/