apachephoenix upsert到表select*from视图

vkc1a9a2  于 2021-06-07  发布在  Hbase
关注(0)|答案(1)|浏览(433)

我从hbase表创建了一个phoenix视图,然后从中创建了一个phoenix视图,最后尝试向上插入一个新的:

create view "personal" (k VARCHAR primary key, "personal_data"."name" VARCHAR);

select * from "personal";

+--------+-------------------------------+
|   K    |             name              |
+--------+-------------------------------+
| 0      | Darrell Clark                 |
| 1      | Elizabeth Baker               |
| 10     | Brad Alexander                |
| 100    | Douglas Morris                |
| 1000   | Joel Boyd                     |
| 10000  | Christine Wood                |
| 10001  | Thomas Wilson                 |
| 10002  | Laura Salinas                 |
| 10003  | Audrey Norris                 |
| 10004  | Kristen Klein                 |
| 10005  | Vanessa Brooks                |
| 10006  | Mary Flynn                    |
| 10007  | Margaret Mullen               |

然后创建一个phoenix表:

create table if not exists personal_table (name VARCHAR, k VARCHAR CONSTRAINT my_pk PRIMARY KEY (name, k));

然后我试着向上插入:

UPSERT INTO personal_table SELECT * FROM personal;

Error: ERROR 1012 (42M03): Table undefined. tableName=PERSONAL (state=42M03,code=1012)
org.apache.phoenix.schema.TableNotFoundException: ERROR 1012 (42M03): Table undefined. tableName=PERSONAL
    at org.apache.phoenix.compile.FromCompiler$BaseColumnResolver.createTableRef(FromCompiler.java:582)
    at org.apache.phoenix.compile.FromCompiler$SingleTableColumnResolver.<init>(FromCompiler.java:396)
    at org.apache.phoenix.compile.FromCompiler.getResolverForQuery(FromCompiler.java:228)
    at org.apache.phoenix.compile.UpsertCompiler.compile(UpsertCompiler.java:504)
    at org.apache.phoenix.jdbc.PhoenixStatement$ExecutableUpsertStatement.compilePlan(PhoenixStatement.java:784)
    at org.apache.phoenix.jdbc.PhoenixStatement$ExecutableUpsertStatement.compilePlan(PhoenixStatement.java:770)
    at org.apache.phoenix.jdbc.PhoenixStatement$2.call(PhoenixStatement.java:401)
    at org.apache.phoenix.jdbc.PhoenixStatement$2.call(PhoenixStatement.java:391)
    at org.apache.phoenix.call.CallRunner.run(CallRunner.java:53)
    at org.apache.phoenix.jdbc.PhoenixStatement.executeMutation(PhoenixStatement.java:390)
    at org.apache.phoenix.jdbc.PhoenixStatement.executeMutation(PhoenixStatement.java:378)
    at org.apache.phoenix.jdbc.PhoenixStatement.execute(PhoenixStatement.java:1825)
    at sqlline.Commands.execute(Commands.java:822)
    at sqlline.Commands.sql(Commands.java:732)
    at sqlline.SqlLine.dispatch(SqlLine.java:813)
    at sqlline.SqlLine.begin(SqlLine.java:686)
    at sqlline.SqlLine.start(SqlLine.java:398)
    at sqlline.SqlLine.main(SqlLine.java:291)

有什么问题吗?是否可以向上插入表格select*from view?谢谢!

azpvetkf

azpvetkf1#

是否可以向上插入表格select*from view?
不,不是这样的。upsert语句中缺少引号导致此错误。“与create table一样,表、列族和列名都是大写的,除非它们是双引号 UPSERT INTO personal_table SELECT * FROM personal; 应该是-> UPSERT INTO personal_table SELECT * FROM "personal"; 我在本地法院审理了你的案子。以下是我在hbase shell上执行的操作:

// create personel table on hbase
create 'personel', {NAME => 'personal_data', VERSIONS => 5}

put 'personel','1','personal_data:name','quaresma'
put 'personel','2','personal_data:name','cenk'
put 'personel','3','personal_data:name','fabri'
put 'personel','4','personal_data:name','pepe'
put 'personel','5','personal_data:name','talisca'

scan 'personel'


然后我切换到phoenix sqlline并执行以下命令:

CREATE VIEW "personel" (k VARCHAR PRIMARY KEY, "personal_data"."name" VARCHAR);

SELECT * FROM "personel";

create table if not exists personal_table (name VARCHAR, k VARCHAR CONSTRAINT my_pk PRIMARY KEY (name, k));

UPSERT INTO personal_table SELECT * FROM "personel";

select * from personal_table;



相关问题