我用ORC创建了一个蜂巢表。如果我从 Hive 控制台插入数据,它可以完美运行。但是如果我从 Jdbc 代码插入数据。它引发配置单元语义异常。
错误
rg.apache.hive.service.cli.HiveSQLException:编译语句时出错:失败:语义异常 [错误 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.Generated MethodAccessor24.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(Native Method( 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.$Proxy 25.executeStatementAsync(Unknown Source( 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$Processor$ExecuteStatement.getResult(TCLIService.java:1313( org.apache.hive.service.cli.thrift.TCLIService$Processor$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 + ")";
任何帮助将不胜感激。
字符串。假设年龄是一个整数,这将起作用,但这是一个糟糕的解决方案:
result = "'" + name + "'," + age + ",'" + job + "'"
这是一个 bas 解决方案,因为如果名称和作业计入引号,则会破坏您的代码。更好的解决方案是使用预准备语句。使用准备好的语句,您不必担心查询:
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(sno,名称(值(1,jj(;
上面一行抛出错误,如果我们编辑与下面相同,它可以工作
在表中插入测试1(sno,名称(值(1,"JJ"(;
这里名称数据类型是字符串
是的,您需要将字符串括起来,否则它将抛出相同的错误。