在Iceberg官方下载页面(http://iceberg.apache.org/releases/)
1、用的是spark3.0最新的,下载对应的jar包,放到spark的jars目录下
2、在spark-defaults.conf添加默认参数
spark.sql.catalog.hive_prod org.apache.iceberg.spark.SparkCatalog
spark.sql.catalog.hive_prod.type hive
spark.sql.catalog.hive_prod.uri thrift://###
3、启动spark-sql
-- 切换命名空间,在这里我们才可以创建iceberg表,在这里的iceberg表可以使用。
use hive_prod.test;
-- 创建表
create table ygy_iceberg_spark(id int ,name string) using iceberg;
-- 插入数据
insert into table ygy_iceberg_spark values(1,'a'),(2,'b'),(3,'c'),(4,'d');
-- 更改表结构
ALTER TABLE ygy_iceberg_spark ADD COLUMN sex String AFTER id;
-- 插入数据
insert into table ygy_iceberg_spark values(5,'男','e'),(6,'女','f');
--查看数据
select * from ygy_iceberg_spark ;
4、在hive中查看表结构
show create table test.ygy_iceberg_spark;
CREATE EXTERNAL TABLE `test.ygy_iceberg_spark`(
`id` int,
`sex` string,
`name` string)
ROW FORMAT SERDE
'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe'
STORED AS INPUTFORMAT
'org.apache.hadoop.mapred.FileInputFormat'
OUTPUTFORMAT
'org.apache.hadoop.mapred.FileOutputFormat'
LOCATION
'hdfs://HDFS80933/usr/hive/warehouse/test.db/ygy_iceberg_spark'
TBLPROPERTIES (
'metadata_location'='hdfs://HDFS80933/usr/hive/warehouse/test.db/ygy_iceberg_spark/metadata/00003-7c439192-6c07-4ddf-a717-1782b7f482c4.metadata.json',
'previous_metadata_location'='hdfs://HDFS80933/usr/hive/warehouse/test.db/ygy_iceberg_spark/metadata/00002-1f71e8ca-3e2c-4053-86b4-14265dc90b77.metadata.json',
'table_type'='ICEBERG',
'transient_lastDdlTime'='1618305074')
可以看到我们数据存放的一些信息。
在执行删除的时候,发生了错误,有点困扰
spark-sql> delete from ygy_iceberg_spark where id<1;
Error in query: Cannot delete from table hive_prod.test.ygy_iceberg_spark where [LessThan(id,1)]
可以看看这个文章iceberg-Spark3.0SQL 测试案例