简体   繁体   English

尝试将数据写入HCatalog时出现InvalidProtocolBufferException(MapReduce外部)

[英]InvalidProtocolBufferException on attempt to write data to HCatalog (outside MapReduce)

My test code: 我的测试代码:

public static void main(String [] args) throws HCatException {
    String metastoreUrl = "thrift://<censored>:9083";
    String databaseName = "default";
    String tableName = "test";


    WriteEntity.Builder builder = new WriteEntity.Builder();
    WriteEntity entity = builder.withDatabase(databaseName).withTable(tableName).build();
    HCatWriter writer = DataTransferFactory.getHCatWriter(entity, HCatalogUtils.createConfigurationMap(metastoreUrl));

    HCatRecord record1 = new DefaultHCatRecord(2);
    record1.set(0, 1);
    record1.set(1, "first line");

    List<HCatRecord> records = new ArrayList<HCatRecord>();
    records.add(record1);

    WriterContext context = writer.prepareWrite();

    writer.write(records.iterator());

    writer.commit(context);
}

When I run this, I get an exception: 当我运行它时,我得到一个例外:

Exception in thread "main" org.apache.hive.hcatalog.common.HCatException : 2004 : HCatOutputFormat not initialized, setOutput has to be called. Cause : org.apache.hive.hcatalog.common.HCatException : 2001 : Error setting output information. Cause : java.io.IOException: Failed on local exception: com.google.protobuf.InvalidProtocolBufferException: Protocol message contained an invalid tag (zero).; Host Details : local host is: "<censored>"; destination host is: "<censored>":8020; 
at org.apache.hive.hcatalog.data.transfer.impl.HCatOutputFormatWriter.prepareWrite(HCatOutputFormatWriter.java:73)
at org.apache.hcatalog.data.MyDataTest.main(MyDataTest.java:42)
Caused by: org.apache.hive.hcatalog.common.HCatException : 2001 : Error setting output information. Cause : java.io.IOException: Failed on local exception: com.google.protobuf.InvalidProtocolBufferException: Protocol message contained an invalid tag (zero).; Host Details : local host is: "<censored>"; destination host is: "<censored>":8020; 
at org.apache.hive.hcatalog.mapreduce.HCatOutputFormat.setOutput(HCatOutputFormat.java:205)
at org.apache.hive.hcatalog.mapreduce.HCatOutputFormat.setOutput(HCatOutputFormat.java:65)
at org.apache.hive.hcatalog.data.transfer.impl.HCatOutputFormatWriter.prepareWrite(HCatOutputFormatWriter.java:66)
... 1 more
Caused by: java.io.IOException: Failed on local exception: com.google.protobuf.InvalidProtocolBufferException: Protocol message contained an invalid tag (zero).; Host Details : local host is: "<censored>"; destination host is: "<censored>":8020; 
at org.apache.hadoop.net.NetUtils.wrapException(NetUtils.java:764)
at org.apache.hadoop.ipc.Client.call(Client.java:1351)
at org.apache.hadoop.ipc.Client.call(Client.java:1300)
at org.apache.hadoop.ipc.ProtobufRpcEngine$Invoker.invoke(ProtobufRpcEngine.java:206)
at com.sun.proxy.$Proxy9.getFileInfo(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.hadoop.io.retry.RetryInvocationHandler.invokeMethod(RetryInvocationHandler.java:186)
at org.apache.hadoop.io.retry.RetryInvocationHandler.invoke(RetryInvocationHandler.java:102)
at com.sun.proxy.$Proxy9.getFileInfo(Unknown Source)
at org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolTranslatorPB.getFileInfo(ClientNamenodeProtocolTranslatorPB.java:651)
at org.apache.hadoop.hdfs.DFSClient.getFileInfo(DFSClient.java:1724)
at org.apache.hadoop.hdfs.DistributedFileSystem$17.doCall(DistributedFileSystem.java:1106)
at org.apache.hadoop.hdfs.DistributedFileSystem$17.doCall(DistributedFileSystem.java:1102)
at org.apache.hadoop.fs.FileSystemLinkResolver.resolve(FileSystemLinkResolver.java:82)
at org.apache.hadoop.hdfs.DistributedFileSystem.getFileStatus(DistributedFileSystem.java:1102)
at org.apache.hive.hcatalog.mapreduce.HCatOutputFormat.setOutput(HCatOutputFormat.java:195)
... 3 more
Caused by: com.google.protobuf.InvalidProtocolBufferException: Protocol message contained an invalid tag (zero).
at com.google.protobuf.InvalidProtocolBufferException.invalidTag(InvalidProtocolBufferException.java:89)
at com.google.protobuf.CodedInputStream.readTag(CodedInputStream.java:108)
at org.apache.hadoop.ipc.protobuf.RpcHeaderProtos$RpcResponseHeaderProto.<init>(RpcHeaderProtos.java:1398)
at org.apache.hadoop.ipc.protobuf.RpcHeaderProtos$RpcResponseHeaderProto.<init>(RpcHeaderProtos.java:1362)
at org.apache.hadoop.ipc.protobuf.RpcHeaderProtos$RpcResponseHeaderProto$1.parsePartialFrom(RpcHeaderProtos.java:1492)
at org.apache.hadoop.ipc.protobuf.RpcHeaderProtos$RpcResponseHeaderProto$1.parsePartialFrom(RpcHeaderProtos.java:1487)
at com.google.protobuf.AbstractParser.parsePartialFrom(AbstractParser.java:200)
at com.google.protobuf.AbstractParser.parsePartialDelimitedFrom(AbstractParser.java:241)
at com.google.protobuf.AbstractParser.parseDelimitedFrom(AbstractParser.java:253)
at com.google.protobuf.AbstractParser.parseDelimitedFrom(AbstractParser.java:259)
at com.google.protobuf.AbstractParser.parseDelimitedFrom(AbstractParser.java:49)
at org.apache.hadoop.ipc.protobuf.RpcHeaderProtos$RpcResponseHeaderProto.parseDelimitedFrom(RpcHeaderProtos.java:2364)
at org.apache.hadoop.ipc.Client$Connection.receiveRpcResponse(Client.java:996)
at org.apache.hadoop.ipc.Client$Connection.run(Client.java:891)

Any suggestion what can be wrong or at least what should I try to investigate this further will be very much appreciated, I don't know how to move from this spot. 任何可能出错的建议或者至少我应该尝试进一步调查的内容都将非常感激,我不知道如何从这个位置转移。

This is probably caused by incompatible protobuf message versions. 这可能是由不兼容的protobuf消息版本引起的。 I usually see this when using a client built on a different (even if slightly) set of Hadoop jars than the cluster. 我通常在使用基于不同(即使是稍微)一组Hadoop jar而不是群集的客户端时看到这一点。 Different Hadoop versions can expect different fields in protobuf messages. 不同的Hadoop版本可以预期protobuf消息中的不同字段。

hadoop的版本不兼容。我也遇到了这个问题。

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

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