Hive hplsql存储过程无法插入时间戳值

时间:2016-12-12 06:17:14

标签: hive hive-hplsql

我尝试使用Hive HPL / SQL存储过程将数据插入到hive表中。但它无法插入时间戳值。我的表定义如下:

     col_name    |   data_type   | comment  |
+----------------+---------------+----------+
| id             | bigint        |          |
| clean_batchid  | bigint        |          |
| job_name       | varchar(50)   |          |
| table_name     | varchar(30)   |          |
| begin_time     | timestamp     |          |
| end_time       | timestamp     |          |
| clean_type     | varchar(20)   |          |
| total_count    | bigint        |          |
| clean_count    | bigint        |          |
| description    | varchar(500)  |    

我使用hive cli插入值没有任何问题。

insert into nbl_clean_batch 
values(12345, 1, 'tryme','B', '2016-12-12 12:52:43', '2016-12-12 12:56:19', 0, 10, 5, 'bbb');

但是当我使用hplsql执行以下脚本时:

START_DATE := SYSDATE;
END_DATE := SYSDATE;

INSERT INTO TABLE NBL_CLEAN_BATCH
(
    ID, CLEAN_BATCHID, JOB_NAME, TABLE_NAME, BEGIN_TIME, END_TIME,  CLEAN_TYPE, TOTAL_COUNT, CLEAN_COUNT, DESCRIPTION
)
VALUES (
    23456, 1, 'bbb', 'B', START_DATE, END_DATE, 0, 9, 2, 'line'
);

它抛出以下异常:

  

HPL / SQL中未处理的异常
  org.apache.hive.service.cli.HiveSQLException:编译语句时出错:FAILED:ParseException line 2:27输入不匹配' - '期待)2016年附近'在值行构造函数中   在org.apache.hive.jdbc.Utils.verifySuccess(Utils.java:267)       at org.apache.hive.jdbc.Utils.verifySuccessWithInfo(Utils.java:253)       在org.apache.hive.jdbc.HiveStatement.runAsyncOnServer(HiveStatement.java:310)       在org.apache.hive.jdbc.HiveStatement.execute(HiveStatement.java:250)       在org.apache.hive.hplsql.Conn.executeSql(Conn.java:110)       在org.apache.hive.hplsql.Exec.executeSql(Exec.java:592)       在org.apache.hive.hplsql.Stmt.insertValues(Stmt.java:800)       在org.apache.hive.hplsql.Stmt.insert(Stmt.java:713)       在org.apache.hive.hplsql.Exec.visitInsert_stmt(Exec.java:1116)       在org.apache.hive.hplsql.Exec.visitInsert_stmt(Exec.java:52)       在org.apache.hive.hplsql.HplsqlParser $ Insert_stmtContext.accept(HplsqlParser.java:10330)       在org.antlr.v4.runtime.tree.AbstractParseTreeVisitor.visitChildren(AbstractParseTreeVisitor.java:70)       在org.apache.hive.hplsql.Exec.visitStmt(Exec.java:1009)       在org.apache.hive.hplsql.Exec.visitStmt(Exec.java:52)       在org.apache.hive.hplsql.HplsqlParser $ StmtContext.accept(HplsqlParser.java:1015)       在org.antlr.v4.runtime.tree.AbstractParseTreeVisitor.visitChildren(AbstractParseTreeVisitor.java:70)       在org.apache.hive.hplsql.HplsqlBaseVisitor.visitBlock(HplsqlBaseVisitor.java:28)       在org.apache.hive.hplsql.HplsqlParser $ BlockContext.accept(HplsqlParser.java:449)       在org.antlr.v4.runtime.tree.AbstractParseTreeVisitor.visitChildren(AbstractParseTreeVisitor.java:70)       在org.apache.hive.hplsql.Exec.visitProgram(Exec.java:916)       在org.apache.hive.hplsql.Exec.visitProgram(Exec.java:52)       在org.apache.hive.hplsql.HplsqlParser $ ProgramContext.accept(HplsqlParser.java:392)       at org.antlr.v4.runtime.tree.AbstractParseTreeVisitor.visit(AbstractParseTreeVisitor.java:42)       在org.apache.hive.hplsql.Exec.run(Exec.java:771)       在org.apache.hive.hplsql.Exec.run(Exec.java:747)       在org.apache.hive.hplsql.Hplsql.main(Hplsql.java:23)       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)       at java.lang.reflect.Method.invoke(Method.java:498)       在org.apache.hadoop.util.RunJar.run(RunJar.java:221)       在org.apache.hadoop.util.RunJar.main(RunJar.java:136)   引起:org.apache.hive.service.cli.HiveSQLException:编译语句时出错:FAILED:ParseException line 2:27输入不匹配' - '期待)2016年附近'在值行构造函数中       在org.apache.hive.service.cli.operation.Operation.toSQLException(Operation.java:394)       在org.apache.hive.service.cli.operation.SQLOperation.prepare(SQLOperation.java:199)       在org.apache.hive.service.cli.operation.SQLOperation.runInternal(SQLOperation.java:282)       在org.apache.hive.service.cli.operation.Operation.run(Operation.java:334)       在org.apache.hive.service.cli.session.HiveSessionImpl.executeStatementInternal(HiveSessionImpl.java:505)       在org.apache.hive.service.cli.session.HiveSessionImpl.executeStatementAsync(HiveSessionImpl.java:492)       at sun.reflect.GeneratedMethodAccessor43.invoke(Unknown Source)       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)       at java.lang.reflect.Method.invoke(Method.java:498)       在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)       at java.security.AccessController.doPrivileged(Native Method)       在javax.security.auth.Subject.doAs(Subject.java:422)       在org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1657)       在org.apache.hive.service.cli.session.HiveSessionProxy.invoke(HiveSessionProxy.java:59)       在com.sun.proxy。$ Proxy38.executeStatementAsync(未知来源)       在org.apache.hive.service.cli.CLIService.executeStatementAsync(CLIService.java:297)       在org.apache.hive.service.cli.thrift.ThriftCLIService.ExecuteStatement(ThriftCLIService.java:506)       在org.apache.hive.service.rpc.thrift.TCLIService $ Processor $ ExecuteStatement.getResult(TCLIService.java:1437)       at org.apache.hive.service.rpc.thrift.TCLIService $ Processor $ ExecuteStatement.getResult(TCLIService.java:1422)       在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:286)       在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)       at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:617)       在java.lang.Thread.run(Thread.java:745)   引起:java.lang.RuntimeException:org.apache.hadoop.hive.ql.parse.ParseException:第2:27行不匹配的输入' - '期待)2016年附近'在值行构造函数中       在org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:207)       在org.apache.hadoop.hive.ql.parse.ParseDriver.parse(ParseDriver.java:166)       在org.apache.hadoop.hive.ql.Driver.compile(Driver.java:465)       在org.apache.hadoop.hive.ql.Driver.compileInternal(Driver.java:1301)       在org.apache.hadoop.hive.ql.Driver.compileAndRespond(Driver.java:1279)       在org.apache.hive.service.cli.operation.SQLOperation.prepare(SQLOperation.java:197)

知道为什么吗?

谢谢,

1 个答案:

答案 0 :(得分:0)

我之前使用过这种格式......

hive> set CURRENT_DATE=FROM_UNIXTIME(UNIX_TIMESTAMP());    
hive> select ${hiveconf:CURRENT_DATE}, * from tab1;
OK
2016-12-14 13:43:13     1       100
2016-12-14 13:43:13     2       235325
2016-12-14 13:43:13     3       3242
2016-12-14 13:43:13     4       32543
Time taken: 1.377 seconds, Fetched: 4 row(s)
hive> set CURRENT_TIMESTAMP = CURRENT_TIMESTAMP;
hive> select ${hiveconf:CURRENT_TIMESTAMP}, * from tab1;
OK
2016-12-14 13:43:35.425 1       100
2016-12-14 13:43:35.425 2       235325
2016-12-14 13:43:35.425 3       3242
2016-12-14 13:43:35.425 4       32543
Time taken: 1.32 seconds, Fetched: 4 row(s)
hive>