插入数据时出现hive语义异常

时间:2016-02-03 11:22:11

标签: hadoop jdbc hive orc bigdata

我用ORC创建了一个hive表。如果我从蜂巢控制台插入数据它完美地工作。但是如果我从Jdbc代码中插入数据。它会抛出hive语义异常。

错误

  

rg.apache.hive.service.cli.HiveSQLException:编译语句时出错:FAILED:SemanticException [错误10293]:无法为插入值创建临时文件插入/值不支持TOK_TABLE_OR_COL类型的表达式       org.apache.hive.service.cli.operation.Operation.toSQLException(Operation.java:326)       org.apache.hive.service.cli.operation.SQLOperation.prepare(SQLOperation.java:102)       org.apache.hive.service.cli.operation.SQLOperation.runInternal(SQLOperation.java:171)       org.apache.hive.service.cli.operation.Operation.run(Operation.java:268)       org.apache.hive.service.cli.session.HiveSessionImpl.executeStatementInternal(HiveSessionImpl.java:410)       org.apache.hive.service.cli.session.HiveSessionImpl.executeStatementAsync(HiveSessionImpl.java:397)       sun.reflect.GeneratedMethodAccessor24.invoke(未知来源)       sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)       java.lang.reflect.Method.invoke(Method.java:606)       org.apache.hive.service.cli.session.HiveSessionProxy.invoke(HiveSessionProxy.java:78)       org.apache.hive.service.cli.session.HiveSessionProxy.access $ 000(HiveSessionProxy.java:36)       org.apache.hive.service.cli.session.HiveSessionProxy $ 1.run(HiveSessionProxy.java:63)       java.security.AccessController.doPrivileged(本机方法)       javax.security.auth.Subject.doAs(Subject.java:415)       org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1671)       org.apache.hive.service.cli.session.HiveSessionProxy.invoke(HiveSessionProxy.java:59)       com.sun.proxy。$ Proxy25.executeStatementAsync(未知来源)       org.apache.hive.service.cli.CLIService.executeStatementAsync(CLIService.java:258)       org.apache.hive.service.cli.thrift.ThriftCLIService.ExecuteStatement(ThriftCLIService.java:509)       org.apache.hive.service.cli.thrift.TCLIService $处理器$ ExecuteStatement.getResult(TCLIService.java:1313)       org.apache.hive.service.cli.thrift.TCLIService $处理器$ ExecuteStatement.getResult(TCLIService.java:1298)       org.apache.thrift.ProcessFunction.process(ProcessFunction.java:39)       org.apache.thrift.TBaseProcessor.process(TBaseProcessor.java:39)       org.apache.hive.service.auth.TSetIpAddressProcessor.process(TSetIpAddressProcessor.java:56)       org.apache.thrift.server.TThreadPoolServer $ WorkerProcess.run(TThreadPoolServer.java:285)       java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)       java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:615)       java.lang.Thread.run(Thread.java:745)

我的插入查询

result = name+","+age+","+job;
String stmt = "INSERT INTO table real_estate.addressinformation_orc VALUES(" + result + ")";

任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:1)

你需要引用字符串。假设年龄是一个整数,这将有效,但这是一个糟糕的解决方案:

result = "'" + name + "'," + age + ",'" + job + "'"

这是一个基本的解决方案,因为如果名称和工作计算引用,那将破坏您的代码。 更好的解决方案是使用预准备语句。准备好的陈述,您不必担心qoting:

preparedStatement = dbConnection.
  prepareStatement("INSERT INTO table " +     
    "real_estate.addressinformation_orc VALUES(?,?,?)");

preparedStatement.setString(1, name);
preparedStatement.setInt(2, age);
preparedStatement.setString(3, job);

// execute insert SQL stetement
preparedStatement.executeUpdate();

答案 1 :(得分:0)

您需要在字符串引号中添加结果变量。

例如: 插入表test1(sno,name)值(1,jj);

上面的行抛出错误,如果我们编辑相同的下面就行了

插入表test1(sno,name)值(1," jj");

这里name数据类型是字符串