您可以强制 HbaseInput 组件获取 Hbase 表的行键。执行以下操作,转到存在 tHbaseInput 类的位置。
C:\Program Files (x86)\Talend-Studio\studio\plugins\org.talend.designer.components.mrprovider_6.2.1.20160704_1411\components\tHBaseInput
并且在 tHBaseInput_mrcode_main_only java jet 类中,会有一个方法 validateResult(),如下
public boolean validateResult(org.apache.hadoop.hbase.client.Result result,
<%=recordStruct%> value) throws IOException {
org.apache.hadoop.hbase.io.ImmutableBytesWritable rowKey = new org.apache.hadoop.hbase.io.ImmutableBytesWritable();
rowKey.set(result.getRow());
lastSuccessfulRow = rowKey.get();
byte[] rowResult = null;
String temp = null;
<%
for (int i = 0; i < mapping.size(); i++) {
Map<String, String> map = mapping.get(i);
String family_column= map.get("FAMILY_COLUMN");
IMetadataColumn column = mainColumns.get(i);
String columnName = column.getLabel();
String defaultValue = column.getDefault();
String typeToGenerate = JavaTypesManager.getTypeToGenerate(column.getTalendType(), column.isNullable());
JavaType javaType = JavaTypesManager.getJavaTypeFromId(column.getTalendType());
String patternValue = column.getPattern() == null || column.getPattern().trim().length() == 0 ? null : column.getPattern();
boolean isPrimitiveType = JavaTypesManager.isJavaPrimitiveType(javaType, column.isNullable());
String toAssign = "value." + columnName;
%>
rowResult = result.getValue(
org.apache.hadoop.hbase.util.Bytes.toBytes(<%=family_column%>),
org.apache.hadoop.hbase.util.Bytes.toBytes("<%=column.getOriginalDbColumnName()%>"));
temp = org.apache.hadoop.hbase.util.Bytes.toString(rowResult);
Modify the above method to below
public boolean validateResult(org.apache.hadoop.hbase.client.Result result,
<%=recordStruct%> value) throws IOException {
org.apache.hadoop.hbase.io.ImmutableBytesWritable rowKey = new org.apache.hadoop.hbase.io.ImmutableBytesWritable();
rowKey.set(result.getRow());
lastSuccessfulRow = rowKey.get();
byte[] rowResult = null;
String temp = null;
value.key = org.apache.hadoop.hbase.util.Bytes.toString(lastSuccessfulRow);
<%
for (int i = 0; i < mapping.size(); i++) {
Map<String, String> map = mapping.get(i);
String family_column= map.get("FAMILY_COLUMN");
IMetadataColumn column = mainColumns.get(i);
String columnName = column.getLabel();
String defaultValue = column.getDefault();
String typeToGenerate = JavaTypesManager.getTypeToGenerate(column.getTalendType(), column.isNullable());
JavaType javaType = JavaTypesManager.getJavaTypeFromId(column.getTalendType());
String patternValue = column.getPattern() == null || column.getPattern().trim().length() == 0 ? null : column.getPattern();
boolean isPrimitiveType = JavaTypesManager.isJavaPrimitiveType(javaType, column.isNullable());
String toAssign = "value." + columnName;
%>
if(!"key".equalsIgnoreCase("<%=column.getOriginalDbColumnName()%>"))
完成后,删除 C:\Program Files (x86)\Talend-Studio\studio\configuration 中的文件“ComponentsCache.javacache”。并重启talend open studio。现在您的 tHbaseInput 组件将从 Hbase 表中获取行键。这可能不适用于每种情况,但如果您使用 talend open studio 生成作业并将 jar 部署到其他地方,这可能会有所帮助。
感谢我的项目经理。