配置单元hplsql存储过程无法插入时间戳值

p1tboqfb  于 2021-06-28  发布在  Hive
关注(0)|答案(1)|浏览(326)

我尝试使用hivehpl/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)  |

我使用hivecli插入值,没有任何问题。

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:编译语句时出错:失败: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\u stmt(exec。java:1116)在org.apache.hive.hplsql.exec.visitinsert\u stmt(exec。java:52)在org.apache.hive.hplsql.hplsqlparser$insert\u 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(本机方法)sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl。java:62)在sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl。java:43)在java.lang.reflect.method.invoke(方法。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:编译语句时出错:失败:在org.apache.hive.service.cli.operation.operation.tosqlexception(operation)的值行构造函数中,parseexception行2:27不匹配的输入“-”应为“2016”附近。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.executeStatementSync(hivesessionimpl。java:492)位于sun.reflect.generatedmethodaccessor43.invoke(未知源)sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl。java:43)在java.lang.reflect.method.invoke(方法。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)位于javax.security.auth.subject.doas(subject)的java.security.accesscontroller.doprivileged(本机方法)。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.executeStatementSync(未知源),org.apache.hive.service.cli.cliservice.executeStatementSync(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(线程。java:745)原因:java.lang.runtimeexception:org.apache.hadoop.hive.ql.parse.parseexception:line 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(驱动程序。java:1301)在org.apache.hadoop.hive.ql.driver.compileandrespond(驱动程序。java:1279) 在org.apache.hive.service.cli.operation.sqloperation.prepare(sqloperation。java:197)
知道为什么吗?
谢谢,

sg2wtvxw

sg2wtvxw1#

我以前用过这种格式。。。

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>

相关问题