在 hive 中创建一个表,时间戳作为注释

问题描述

我想在 hive 中创建一个表,在注释中包含创建日期(current_timestamp 函数)。像这样:

CREATE TABLE IF NOT EXISTS ex.tb_test ( field1 int,field2 String) COMMENT current_timestamp STORED AS TEXTFILE;

但它返回错误:ILED: ParseException line 2: 8 mismatched input 'current_timestamp' expecting StringLiteral near 'COMMENT'

你知道有什么方法可以在评论添加表格的创建日期吗?

解决方法

表 DDL 不支持函数。您可以将预先计算的时间戳作为 --hiveconf 参数传递并使用例如: comment '${hiveconf:ts}'(它应该被引用),该参数将在命令执行之前解析为字符串文字。

顺便说一句,Hive 存储 CreateTime。

describe formatted table_name 命令输出 CreateTime 以及其他表信息。