我正在尝试在hive创建语句中使用substr,但我无法创建表,任何人都可以帮忙吗?
CREATE TABLE Contact(
RegionId varchar(6),
(substring(RegionID,1,2)) AS Channel
)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '|'
STORED AS TEXTFILE
LOCATION'hdfs_location';
答案 0 :(得分:0)
不幸的是,您无法将UDF与CREATE TABLE语句一起使用。这是因为您只是为表定义模式,而不是对数据执行操作。有关详细信息,请参阅此链接:https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-CreateTable
我的建议是定义专栏"频道"像往常一样,例如:
CREATE TABLE Contact(
RegionId varchar(6),
Channel string
)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '|'
STORED AS TEXTFILE
LOCATION'hdfs_location';
然后在将数据插入表时,使用子字符串方法:
INSERT INTO TABLE Contact
SELECT RegionId, substring(RegionID,1,2) as Channel
FROM table;