Easy methods to Use Apache Iceberg in CDP’s Open Lakehouse


In June 2022, Cloudera introduced the overall availability of Apache Iceberg within the Cloudera Knowledge Platform (CDP). Iceberg is a 100% open-table format, developed by the Apache Software program Basis, which helps customers keep away from vendor lock-in and implement an open lakehouse

The final availability covers Iceberg operating inside a number of the key information companies in CDP, together with Cloudera Knowledge Warehouse (CDW), Cloudera Knowledge Engineering (CDE), and Cloudera Machine Studying (CML). These connections empower analysts and information scientists to simply collaborate on the identical information, with their selection of instruments and engines. No extra lock-in, pointless information transformations, or information motion throughout instruments and clouds simply to extract insights out of the info.

With Iceberg in CDP, you possibly can profit from the next key options:

  • CDE and CDW help Apache Iceberg: Run queries in CDE and CDW following Spark ETL and Impala enterprise intelligence  patterns, respectively.
  • Exploratory information science and visualization: Entry Iceberg tables by auto-discovered CDW connection in CML initiatives.
  • Wealthy set of SQL (question, DDL, DML) instructions: Create or manipulate database objects, run queries, load and modify information, carry out time journey operation, and convert Hive exterior tables to Iceberg tables utilizing SQL instructions developed for CDW and CDE.
  • Time Journey: Reproduce a question as of a given time or snapshot ID, which can be utilized for historic audits and rollback of misguided operations, for example.
  • In-place desk (schema, partition) evolution: Evolve Iceberg desk schema and partition layouts with out expensive distractions, corresponding to rewriting desk information or migrating to a brand new desk.
  • SDX Integration (Ranger): Handle entry to Iceberg tables by Apache Ranger.

On this two-part weblog submit, we’re going to point out you the right way to use Iceberg in CDP to construct an open lakehouse and leverage the CDP compute companies from information engineering, to information warehousing, to machine studying.

On this first half we’ll deal with the right way to construct the open lakehouse with Apache Iceberg in CDP; ingest and rework information utilizing CDE; and leverage time journey, partition evolution, and entry management to SQL and BI workloads on Cloudera Knowledge Warehouse.

Answer overview:


The next CDP public cloud (AWS) information companies needs to be provisioned:

  • Cloudera Knowledge Warehouse Impala Digital Warehouse
  • Cloudera Knowledge Engineering (Spark 3) with Airflow enabled
  • Cloudera Machine Studying 

Loading information into Iceberg tables with CDE

We begin by making a Spark 3 digital cluster (VC) in CDE. To manage prices we will modify the quotas for the digital cluster and use spot situations. Additionally, choosing the choice to allow Iceberg analytic tables ensures the VC has the required libraries to work together with Iceberg tables.

After a couple of minutes the VC might be up and operating, able to deploy new Spark jobs.

Since we might be utilizing Spark to carry out a collection of desk operations, we’ll use Airflow to orchestrate a pipeline of those operations. 

Step one is to load our Iceberg desk. Apart from creating and loading an Iceberg desk straight with new information, CDP gives a number of different choices. You’ll be able to import or migrate current exterior Hive tables.

  • Importing retains the supply and vacation spot intact and impartial. 
  • Migrating converts the desk into an Iceberg desk.

Right here we now have merely imported an current flights desk into our airline’s Iceberg database desk. 

from pyspark.sql import SparkSession

import sys

spark = SparkSession 


    .appName("Iceberg put together tables") 

    .config("spark.sql.catalog.spark_catalog", "org.apache.iceberg.spark.SparkSessionCatalog")

    .config("spark.sql.catalog.spark_catalog.kind", "hive")

    .config("spark.sql.extensions", "org.apache.iceberg.spark.extensions.IcebergSparkSessionExtensions")


spark.sql("""CALL spark_catalog.system.snapshot('airlines_csv.flights_external', 

Our imported flights desk now accommodates the identical information as the present exterior hive desk and we will shortly verify the row counts by 12 months to verify:

  12 months _c1

1 2008 7009728

2 2007 7453215

3 2006 7141922

4 2005 7140596

5 2004 7129270

6 2003 6488540

7 2002 5271359

8 2001 5967780

9 2000 5683047

In-place partition evolution 

Subsequent, some of the widespread information administration duties is to switch the schema of the desk.  Often that is easy to carry out if it’s a non-partitioned column. But when the partition scheme wants altering, you’ll sometimes need to recreate the desk from scratch. In Iceberg these desk administration operations will be utilized with minimal rework, decreasing the burden on the info practitioner as they evolve their tables to higher match enterprise necessities.

In our second stage of the pipeline, we alter the partition scheme to incorporate the 12 months column utilizing one line of code!

print(f"Alter partition scheme utilizing 12 months n")

spark.sql("""ALTER TABLE airlines_iceberg.flights_v3 


When describing the desk we will see “12 months” is now a partition column:

# Partition Remodel Info

# col_name transform_type

12 months IDENTITY

Within the ultimate stage of our ETL pipeline, we load new information into this partition. Let’s check out how we will benefit from this Iceberg desk utilizing Impala to run interactive BI queries.

Utilizing CDW with Iceberg

Time journey

Now that we now have information loaded into Iceberg tables, let’s use Impala to question the desk. First we’ll open Hue in CDW and entry the desk that we simply created utilizing Spark in CDE. Go to CDW and open Hue within the Impala Digital Warehouse.

First we verify the historical past of the desk and see:


Instance Outcomes:

creation_time snapshot_id parent_id is_current_ancestor
2022-07-20 09:38:27.421000000 7445571238522489274 NULL TRUE
2022-07-20 09:41:24.610000000 1177059607967180436 7445571238522489274 TRUE
2022-07-20 09:50:16.592000000 2140091152014174701 1177059607967180436 TRUE

Now we will question the desk at completely different time limits to see the outcomes utilizing the timestamps and the snapshot_id’s, as proven under.

choose 12 months, depend(*) from flights_v3

FOR SYSTEM_VERSION AS OF 7445571238522489274

group by 12 months

order by 12 months desc;
12 months depend(*)
2005 7140596
2004 7129270
2003 6488540
2002 5271359
2001 5967780
2000 5683047
1999 5527884
1998 5384721
1997 5411843
1996 5351983
1995 5327435

We see that as of the primary snapshot (7445571238522489274) we had information from the years 1995 to 2005 within the desk. Let’s see the info as of the second snapshot:

choose 12 months, depend(*) from flights_v3

FOR SYSTEM_VERSION AS OF 1177059607967180436

group by 12 months

order by 12 months desc;
12 months depend(*)
2006 7141922
2005 7140596
2004 7129270
2003 6488540
2002 5271359
2001 5967780
2000 5683047
1999 5527884
1998 5384721
1997 5411843
1996 5351983
1995 5327435

Now we now have information as of the 12 months 2006 additionally within the desk. Utilizing the “FOR SYSTEM_VERSION AS OF <snapshot id>” you possibly can question older information. You may also use timestamps utilizing “FOR SYSTEM_TIME AS OF <timestamp>.”

In-place partition evolution

Along with the CDE’s (Spark) functionality for in-place partition evolution, you may also use CDW (Impala) to carry out in-place partition evolution. First, we’ll verify the present partitioning of the desk utilizing the present create desk command, as proven under:


We see that the desk is partitioned by the 12 months column. We will change the partitioning scheme of the desk from partitioned by 12 months to be partitioned by the 12 months in addition to the month column. After new information is loaded into the desk all subsequent queries will profit from partition pruning on the month column in addition to the 12 months column.

ALTER TABLE flights_v3 SET PARTITION spec (12 months, month);


CREATE EXTERNAL TABLE flights_v3 (   month INT NULL,   dayofmonth INT NULL,   dayofweek INT NULL,   deptime INT NULL,   crsdeptime INT NULL,   arrtime INT NULL,   crsarrtime INT NULL,   uniquecarrier STRING NULL,   flightnum INT NULL,   tailnum STRING NULL,   actualelapsedtime INT NULL,   crselapsedtime INT NULL,   airtime INT NULL,   arrdelay INT NULL,   depdelay INT NULL,   origin STRING NULL,   dest STRING NULL,   distance INT NULL,   taxiin INT NULL,   taxiout INT NULL,   cancelled INT NULL,   cancellationcode STRING NULL,   diverted STRING NULL,   carrierdelay INT NULL,   weatherdelay INT NULL,   nasdelay INT NULL,   securitydelay INT NULL,   lateaircraftdelay INT NULL,   12 months INT NULL ) PARTITIONED BY SPEC (   12 months,   month ) STORED AS ICEBERG LOCATION 's3a://xxxxxx/warehouse/tablespace/exterior/hive/airways.db/flights_v3' TBLPROPERTIES ('OBJCAPABILITIES'='EXTREAD,EXTWRITE', 'engine.hive.enabled'='true', 'exterior.desk.purge'='TRUE', 'iceberg.catalog'='hadoop.tables', 'numFiles'='2', 'numFilesErasureCoded'='0', 'totalSize'='6958', 'write.format.default'='parquet')

High-quality-grained entry management by SDX integration (Ranger) 

To safe Iceberg tables, we help Ranger-based guidelines for each row and column safety, as proven under. 

Column masking for the taxiout column:

Row masking for 12 months sooner than 2000:

SELECT taxiout FROM flights_v3 restrict 10;

SELECT distinct (12 months) FROM flights_v3;

BI queries

Question to search out all worldwide flights, outlined as flights the place the vacation spot airport nation is just not the identical because the origin airport nation:


   flightnum,    uniquecarrier,    origin,    dest,    month,    dayofmonth,    `dayofweek`

FROM flights_v3, airports_iceberg oa, airports_iceberg da  


   f.origin = oa.iata     and f.dest = da.iata and oa.nation <> da.nation 

ORDER BY    month ASC,    dayofmonth ASC 

LIMIT 4  ;
flightnum uniquecarrier origin dest month dayofmonth dayofweek
2280 XE BTR IAH 1 1 4
1673 DL ATL BTR 1 1 7
916 DL BTR ATL 1 1 2
3470 MQ BTR DFW 1 1 1

Question to discover passenger manifest information. For instance, do we now have worldwide connecting flights?

SELECT * FROM unique_tickets a,    flights_v3 o,    flights_v3 d,   airports oa,    airports da   WHERE    a.leg1flightnum = o.flightnum    AND a.leg1uniquecarrier = o.uniquecarrier     AND a.leg1origin = o.origin     AND a.leg1dest = o.dest     AND a.leg1month = o.month     AND a.leg1dayofmonth = o.dayofmonth    AND a.leg1dayofweek = o.`dayofweek`     AND a.leg2flightnum = d.flightnum    AND a.leg2uniquecarrier = d.uniquecarrier     AND a.leg2origin = d.origin     AND a.leg2dest = d.dest     AND a.leg2month = d.month     AND a.leg2dayofmonth = d.dayofmonth    AND a.leg2dayofweek = d.`dayofweek`     AND d.origin = oa.iata     AND d.dest = da.iata     AND oa.nation <> da.nation  ; 


On this first weblog, we shared with you the right way to use Apache Iceberg in Cloudera Knowledge Platform to construct an open lakehouse. Within the instance workflow, we confirmed you the right way to ingest information units into an Iceberg desk with Cloudera Knowledge Engineering (CDE), carry out time journey and in-place partition evolution, and apply fine-grained entry management (FGAC) with Cloudera Knowledge Warehouse (CDW). Keep tuned for half two!

To construct an open lakehouse by yourself strive Cloudera Knowledge Warehouse (CDW), Cloudera Knowledge Engineering (CDE), and Cloudera Machine Studying (CML) by signing up for a 60-day trial, or check drive CDP. If you have an interest in chatting about Apache Iceberg in CDP, let your account staff know. Present your suggestions within the feedback part under. 


Please enter your comment!
Please enter your name here