Creating Partitioned Datasets in Parquet and Iceberg with the Denodo Lakehouse Accelerator

You can translate the document:

Background

The Denodo Lakehouse Accelerator (formerly known as Denodo Embedded MPP) supports inserts in both Parquet as well as Iceberg format. This can have several uses including caching, data movement optimization, and even temporary tables for the parallel processing of any operation. In this case we will take a look at how we can use this to create partitioned dataset in Amazon S3.

Partitioning of data lake storage has several benefits:

  • it reduces query scan times by enabling partition pruning
  • minimizes I/O costs by filtering out unnecessary data
  • improves parallelism in distributed query engines
  • enhances performance for analytical workloads by grouping related data together for efficient retrieval

The Denodo Lakehouse Accelerator can make use of these partitions to minimize data transfer and optimize performance. Depending on the format, partitioning is done in different ways. Parquet requires Hive style partitioning in which files need to be divided across different directories named after partition value columns. Iceberg on the other hand uses automatic partitioning managed through its metadata files. Here we will take a look at how through Denodo we can easily transform standard unpartitioned Parquet files into partitioned data in each of these file formats.

Partitioned Dataset Creation

Lets take the case of a customer dataset we have in S3. Here we can see the dataset:

It is stored as 5 Parquet files with no partitioning. While it can be accessed and utilized, performance could be improved in some queries by adding some partitioning. To address this, we first import it as a view in Denodo Virtual DataPort (VDP), if it is not available there yet:

Now, let’s create a remote table on top of it and define some partitioning. We can go to “File > New > Replication (remote table)” to create our definition:

We set the target as our Denodo Lakehouse Accelerator. Since we are generating Parquet data in this case without any additional abstractions, we will use our ‘hive’ catalog. Also, since Presto’s partitioning syntax requires the partition column be last in the schema, we adjust our VQL query to put our partition column (c_nationkey in this case) last.

Now, we expand the “Manage custom DDL template” section and modify it to define a new partioned_by clause with a parameterized array:

CREATE TABLE @{internal_parameter_table_name} (@{internal_parameter_columns} @{internal_parameter_restrictions}) WITH (FORMAT = 'PARQUET', partitioned_by = array['@{partition_column_array}'], @{internal_parameter_location_parameter_name} = '@{internal_parameter_data_location}')

 In our case it contains only our c_nationkey column.

With that done, we can go ahead and create our remote table.

Now that our remote table is created, let’s take a look at S3 to see how it was stored.

Checking Amazon s3, we find a new folder with our customer data now neatly divided into partitions based on c_nationkey! This new dataset will see greatly improved performance with filtering operations as partitions incompatible with a given query can simply be pruned by the Denodo Lakehouse Accelerator Engine.

Iceberg dataset creation

Now, let's take this one step further and convert our dataset to Iceberg. Apache Iceberg is a table format that enhances how Parquet (or ORC/Avro) files are managed in a data lake. It adds ACID transactions, schema evolution, time travel, and automatic partitioning, eliminating the need for manual partition management. Through Denodo`s Lakehouse Accelerator, we can easily convert our existing Parquet data to Iceberg format. Once again, let’s create a remote table on top of our customer view.

In this case, the important point is that we create the remote table under the ‘iceberg’ catalog, as this will ensure inserts are processed in Iceberg format. Lets then go ahead and adjust our custom DDL template with:

CREATE TABLE @{internal_parameter_table_name} (@{internal_parameter_columns} @{internal_parameter_restrictions}) WITH (FORMAT = 'PARQUET', partitioning = array['@{partition_column_array}'], @{internal_parameter_location_parameter_name} = '@{internal_parameter_data_location}')

Since Iceberg uses automatic partitioning rather than partitioning based on folder structures, the syntax to define it differs slightly from the prior template, in this case using the property ‘partitioning’ rather than ‘partitioned_by’. We will once again specify c_nationkey as our column for partitioning, and we can go ahead and create the remote table.

If we check S3 now, we will find we have a fully fledged Iceberg dataset for our customer information containing both Parquet data files as well as the required Iceberg metadata!

Iceberg Partition Transforms

Let's go one step further and make use of Icebergs transform functions. As mentioned, rather than relying on Hive style partitioning like Parquet, Iceberg utilizes hidden partitioning via its metadata. Due to this, Iceberg supports partition transforms that would not be possible in traditional Hive style partitioning. Let’s see an example of how we can utilize this using our Lineitem table. Our Lineitem is a fact table with time-series data. Partitioning based on time would be a great choice, but as our l_shipdate  field is date type, partitioning by the field alone would mean a different partition for each date, leading to thousands of partitions. Instead, let’s try to see if we can partition the data by year.

Let’s create a remote table on top of Lineitem. We can input the same custom template that we used for the Customer table. The only difference is that this time for the value for the partition_column_array we will use l_shipdate transformed by the year() function:

year(l_shipdate)

After submitting this, our new remote table is generated. To confirm the partition is working properly, let's try it out. Since the data should be partitioned into years for l_shipdate, we can go ahead and enter a condition that selects data from just a single year:

Ensure “Retrieve All Rows” is selected so that the query is not stopped early. After executing we can check the “Execution Trace” to see how the query has been processed. Under “MPP Data Access” we can see the “Input rows” correspond only to the data in our 1996 partition as all other partitions have been excluded from the table scan:

Ingesting Data from External Sources

In this article, we walked through examples of converting object storage data available to our Denodo Lakehouse Accelerator. Let’s say instead the data is located in Oracle, Salesforce, or any other  data source. In this case, we can very easily ingest data into the data lake and perform similar transformations even if the data is not in object storage. By caching or creating remote tables using the same steps outlined above we can perform the following:

  • External source -> Parquet
  • External source -> Iceberg
  • External source -> Partitioned Iceberg

However, creating partitioned Parquet files requires an extra step. This is because the bulk load process used to generate and upload the Parquet files from external sources does not create hive style partitions. So for the specific case of wanting to turn data located in an external database into partitioned Parquet, you  would need to do in two steps: first ingest the data into the data lake, and then convert it to a partitioned dataset:

  • External Database -> Parquet -> Partitioned Parquet

Best Practices

Avoid over partitioning: Having too many partitions can lead to degraded performance due to increased complexity and overhead in metadata management. In general, aim for partitions at least 1 GB in size to ensure optimal performance.

Base partition columns on query patterns: Ideally partitions should align with how the data is most frequently queried in order to ensure partitions can be properly utilized.

Use date based partitioning for time-series data - For datasets with time-series characteristics, partitioning by date (e.g., year, month, day) aligns well with common query patterns and maximizes opportunities for partition pruning.

Leverage partition transforms in Iceberg: As highlighted in this article, Iceberg supports a number of partition transforms. These allow for more flexible partition strategies. When partitioning Iceberg data, consider utilizing these partition transforms when possible in order to develop the optimal strategy.

Set appropriate timeouts: As datasets requiring partition are typically quite large, you may need to increase the query timeouts when creating your remote tables. If creating your remote table graphically, you may need to increase the stored procedure timeout via “Administration > Server Configuration > Others > Stored Procedures > Query Timeout (milliseconds).” Or, if creating your stored procedure with a VQL command, consider adding CONTEXT('querytimeout'='0') to the command.

Disclaimer

The information provided in the Denodo Knowledge Base is intended to assist our users in advanced uses of Denodo. Please note that the results from the application of processes and configurations detailed in these documents may vary depending on your specific environment. Use them at your own discretion.

For an official guide of supported features, please refer to the User Manuals. For questions on critical systems or complex environments we recommend you to contact your Denodo Customer Success Manager.
Recommendation

Recommended resources Recommendations generated by AI

Building an Augmented Data Lakehouse with the Denodo Embedded MPP

Denodo Lakehouse Accelerator AWS Checklist

How to deploy the Denodo Lakehouse Accelerator with OpenShift

Startup of the Denodo Embedded MPP

Exploring the Denodo Lakehouse Accelerator

Questions

Ask a question

You must sign in to ask a question. If you do not have an account, you can register here