Flink如何创建同Hive兼容的表

文章讨论了使用FlinkAPI创建Hive表后,在Hive中查询时遇到的SemanticException,对比了FlinkSQL创建表的正常情况。问题在于FlinkAPI创建的表缺少connector参数,导致字段信息存储在表参数中而非常规字段列表。解决方案包括设置connector为hive或使用Flink的HiveSQL方言。
摘要由CSDN通过智能技术生成

曾使用Flink API创建Hive表,然后查询时碰到过这个问题:

hive>select * from  test_db.test_flink_hive_table;
FAILED: SemanticException Line 0:-1 Invalid column reference 'TOK_ALLCOLREF'

但是如果使用Flink SQL去查询却是正常的。切换其他引擎,比如使用Trino按照相同的方式创建表,也是正常查询,那问题自然就是Flink的处理方式不同了。

用Hive SQL打印表的详情来研究下:

hive>desc formatted test_db.test_flink_hive_table;
OK
# col_name            	data_type           	comment             
		 
# Detailed Table Information		 
Database:           	test_db             	 
OwnerType:          	USER                	 
Owner:              	null                	 
LastAccessTime:     	UNKNOWN             	 
Retention:          	0                   	 
Location:           	file:/tmp/test_db/test_flink_hive_table	 
Table Type:         	MANAGED_TABLE       	 
Table Parameters:		 
	flink.comment       	test crreate flink hive table
	flink.schema.0.data-type	INT                 
	flink.schema.0.name 	id                  
	flink.schema.1.data-type	VARCHAR(2147483647) 
	flink.schema.1.name 	data                
	is_generic          	true                
	transient_lastDdlTime	1678861999          
		 
# Storage Information		 
SerDe Library:      	org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe	 
InputFormat:        	org.apache.hadoop.mapred.TextInputFormat	 
OutputFormat:       	org.apache.hadoop.hive.ql.io.IgnoreKeyTextOutputFormat	 
Compressed:         	No                  	 
Num Buckets:        	0                   	 
Bucket Col
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值