【问题标题】:Hive hplsql stored procedure cannot insert timestamp valuesHive hplsql 存储过程无法插入时间戳值
【发布时间】:2016-12-18 05:44:46
【问题描述】:

我尝试使用 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 行 2:27 不匹配输入 '-' 期望)在值行构造函数中的 '2016' 附近
在 org.apache.hive.jdbc.Utils.verifySuccess(Utils.java:267) 在 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) 在 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) 在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 在 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在 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 mismatched input '-'expecting)在值行构造函数中的'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) 在 sun.reflect.GeneratedMethodAccessor43.invoke(未知来源) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在 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) 在 java.security.AccessController.doPrivileged(本机方法) 在 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) 在 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) 在 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:line 2:27 mismatched input '-'expecting) 在值行构造函数中靠近 '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)

知道为什么吗?

谢谢,

【问题讨论】:

  • hplsql 版本为 0.3.31

标签: hive hive-hplsql


【解决方案1】:

我以前用过这种格式……

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>

【讨论】:

  • 嗨,CURRENT_DATE 功能正在运行。但不是时间戳功能,如 CURRENT_TIMESTAMP、SYSDATE。
  • 更新了我执行的脚本
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-03
  • 2017-05-31
  • 1970-01-01
  • 1970-01-01
  • 2012-05-02
  • 1970-01-01
相关资源
最近更新 更多