无法使用主键创建配置单元表

xggvc2p6  于 2021-06-03  发布在  Hadoop
关注(0)|答案(7)|浏览(343)

无法使用主键在配置单元中创建外部表。下面是示例代码:

hive> create table exmp((name string),primary key(name));

这将返回以下错误消息:
noviablealException(278@[]),位于org.apache.hadoop.hive.ql.parse.hiveparser\u identifiersparser.identifier(hiveparser\u identifiersparser)。java:11216)在org.apache.hadoop.hive.ql.parse.hiveparser.identifier(hiveparser。java:35977)在org.apache.hadoop.hive.ql.parse.hiveparser.columnnametype(hiveparser。java:31169)在org.apache.hadoop.hive.ql.parse.hiveparser.columnnametypelist(hiveparser。java:29373)在org.apache.hadoop.hive.ql.parse.hiveparser.createtablestatement(hiveparser)上。java:4439)在org.apache.hadoop.hive.ql.parse.hiveparser.ddlstatement(hiveparser.com)上。java:2084)在org.apache.hadoop.hive.ql.parse.hiveparser.execstatement(hiveparser。java:1344)在org.apache.hadoop.hive.ql.parse.hiveparser.statement(hiveparser。java:983)在org.apache.hadoop.hive.ql.parse.parsedriver.parse(parsedriver。java:190)在org.apache.hadoop.hive.ql.driver.compile(driver。java:434)在org.apache.hadoop.hive.ql.driver.compile(driver。java:352)位于org.apache.hadoop.hive.ql.driver.compileinternal(驱动程序。java:995)在org.apache.hadoop.hive.ql.driver.runinternal(驱动程序。java:1038)在org.apache.hadoop.hive.ql.driver.run(driver。java:931)在org.apache.hadoop.hive.ql.driver.run(driver。java:921)在org.apache.hadoop.hive.cli.clidriver.processlocalcmd(clidriver。java:268)在org.apache.hadoop.hive.cli.clidriver.processcmd(clidriver。java:220)在org.apache.hadoop.hive.cli.clidriver.processline(clidriver。java:422)在org.apache.hadoop.hive.cli.clidriver.executedriver(clidriver。java:790)在org.apache.hadoop.hive.cli.clidriver.run(clidriver。java:684)位于org.apache.hadoop.hive.cli.clidriver.main(clidriver。java:623)位于sun.reflect.nativemethodaccessorimpl.invoke0(本机方法)sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl。java:62)在sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl。java:43)在java.lang.reflect.method.invoke(方法。java:483)在org.apache.hadoop.util.runjar.main(runjar。java:212)失败:parseexception行1:18无法识别'(''name'附近的输入列规范中的“string”
请帮帮我。

9udxz4iz

9udxz4iz1#

试试这个

create table exmp(name string,primary key(name));
zf2sa74q

zf2sa74q2#

旧版本的配置单元不支持主键,但已在2.1.0版本的配置单元中添加了此支持。下面是它的示例查询 CREATE TABLE table_name ( id int, name string, dept string, primary key(id) disable novalidate ); ps:如何获得hive版本 hive --version Hive 1.2.1000.x.x.x.x-x 或者进入直线击球 beeline Beeline version 1.2.1000.x.x.x.x-x by Apache Hive

0tdrvxhp

0tdrvxhp3#

配置单元中没有任何主键和外键。因此请删除主键并执行。
创建表exmp(名称字符串);

b09cbbtk

b09cbbtk4#

首先,配置单元中的derby没有键;其次,某些键可能与配置单元中的关键字重复,因此必须向它们添加单引号。在我的例子中,查询出错

create table NYSE (exchange String,stock_symbol String,stock_date String,stock_price_open double, stock_price_high double, stock_price_low double, stock_price_close double, stock_volume double, stock_price_adj_close double) row format delimited fields terminated by ‘,’;

应该是的

create table NYSE (`exchange` String,stock_symbol String,stock_date String,stock_price_open double, stock_price_high double, stock_price_low double, stock_price_close double, stock_volume double, stock_price_adj_close double) row format delimited fields terminated by ',';
emeijp43

emeijp435#

从官方页面:https://cwiki.apache.org/confluence/display/hive/languagemanual+ddl
它们在创建表的语法中包括:

constraint_specification:
  : [, PRIMARY KEY (col_name, ...) DISABLE NOVALIDATE ]
    [, CONSTRAINT constraint_name FOREIGN KEY (col_name, ...) REFERENCES 
table_name(col_name, ...) DISABLE NOVALIDATE .

所以这意味着我们可以在配置单元中用主键创建表
版本信息
从hive 2.1.0(hive-13290)开始。
配置单元包括对未验证的主键和外键约束的支持。当存在约束时,一些sql工具会生成更高效的查询。由于这些约束未经验证,因此上游系统需要在加载到配置单元之前确保数据完整性。例子:

CREATE TABLE pk(
    id1 integer,
    id2 integer,
    primary key(id1, id2) disable novalidate
);

CREATE TABLE fk(
    id1 integer,
    id2 integer,
    constraint c1 foreign key(id1, id2) references pk(id2, id1) disable novalidate
);
lawou6xi

lawou6xi6#

配置单元中没有主键概念,因为它不是数据库,并且配置单元中的操作基于文件而不是基于记录。
试试这个

create table table_name (
    row_number() over() as rowId     operation
    name string,
    age Int,
    address string) row format delimited fields terminated by ',' stored as textfile;

在这里考虑 rowId 并执行操作。

628mspwn

628mspwn7#

抱歉,如果您有任何其他与配置单元表相关的功能,则配置单元中没有主键

CREATE DATABASE [IF NOT EXISTS] userdb;

SHOW DATABASES;

DROP DATABASE IF EXISTS userdb;

DROP DATABASE IF EXISTS userdb CASCADE;

CREATE TABLE IF NOT EXISTS employee ( eid int, name String,
 salary String, destination String)
 COMMENT "Employee details"
 ROW FORMAT DELIMITED
 FIELDS TERMINATED BY "\t"
 LINES TERMINATED BY "\n"
 STORED AS TEXTFILE;  

LOAD DATA LOCAL INPATH '/home/user/sample.txt'
    OVERWRITE INTO TABLE employee;

ALTER TABLE employee RENAME TO emp;

desc tablename;

ALTER TABLE employee CHANGE name ename String;
hive> ALTER TABLE employee CHANGE salary salary Double;

ALTER TABLE employee ADD COLUMNS ( 
    dept STRING COMMENT 'Department name');    

ALTER TABLE employee REPLACE COLUMNS ( 
    eid INT empid Int, 
    ename STRING name String);

DROP TABLE IF EXISTS employee;

SHOW TABLES;

SELECT * FROM employee WHERE Salary>40000 && Dept=TP;  

CREATE VIEW emp_30000 AS
    SELECT * FROM employee
    WHERE salary>30000;

DROP VIEW emp_30000;

相关问题