{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "3146b6d0-16d0-4175-b2c8-b16a82013f3e", "metadata": {}, "outputs": [], "source": [ "Oracle AI Data Platform v1.0\n", "\n", "Copyright © 2025, Oracle and/or its affiliates.\n", "\n", "Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/" ] }, { "cell_type": "markdown", "id": "d65c4c0d-b938-4ccf-8b56-272b3791849a", "metadata": { "type": "markdown" }, "source": [ "# Delta UniForm Notebook Samples\n", "\n", "This notebook demonstrates how to create and work with **Delta UniForm tables** that synchronize Iceberg metadata, enabling interoperability with Iceberg clients.\n" ] }, { "cell_type": "markdown", "id": "68049bcc-fa85-4ac3-b4b3-ca065a2a56e1", "metadata": { "execution": { "iopub.status.busy": "2025-09-15T19:50:02.132Z" }, "type": "markdown" }, "source": [ "## Create Delta UniForm Table with Iceberg Metadata Sync\n", "\n", "The following example creates a Delta table and enables UniForm, so that Iceberg metadata is generated alongside Delta metadata.\n" ] }, { "cell_type": "code", "execution_count": null, "id": "4b384324-cf59-4a27-a16c-4c325e401a0d", "metadata": { "type": "sql" }, "outputs": [], "source": [ "%sql\n", "CREATE TABLE cat1.db1.uniform1 (\n", " id INT,\n", " name STRING,\n", " ts TIMESTAMP\n", ")\n", "USING DELTA\n", "TBLPROPERTIES('delta.universalFormat.enabledFormats' = 'iceberg');" ] }, { "cell_type": "markdown", "id": "2a0aa6ee-433d-465a-9110-0591840a196f", "metadata": { "type": "markdown" }, "source": [ "## Insert into Delta UniForm Table\n", "\n", "Inserts are automatically reflected in both Delta and Iceberg metadata.\n" ] }, { "cell_type": "code", "execution_count": null, "id": "8dd97f80-1f09-45f8-86b9-16adf2ba13f2", "metadata": { "type": "sql" }, "outputs": [], "source": [ "%sql\n", "INSERT INTO cat1.db1.uniform1 VALUES\n", "(1, 'Alice', CURRENT_TIMESTAMP),\n", "(2, 'Bob', CURRENT_TIMESTAMP);" ] }, { "cell_type": "markdown", "id": "c4208f97-2959-4e3e-8ec6-29ea358253d3", "metadata": { "type": "markdown" }, "source": [ "## MERGE into Delta UniForm Table\n", "\n", "MERGE statements also keep both metadata layers in sync.\n", "The following example updates an existing record (id = 1) and inserts a new record (id = 3)" ] }, { "cell_type": "code", "execution_count": null, "id": "13061ffc-6539-4843-b5e0-2447d47a1540", "metadata": { "type": "sql" }, "outputs": [], "source": [ "%sql\n", "\n", "-- Temporary table or inline source for upsert\n", "CREATE OR REPLACE TEMP VIEW updates AS\n", "SELECT * FROM VALUES\n", " (1, 'Alice_updated', current_timestamp()), -- Will UPDATE\n", " (3, 'Charlie', current_timestamp()) -- Will INSERT\n", "AS updates(id, name, ts);\n", "\n", "-- UPSERT via MERGE INTO\n", "MERGE INTO cat1.db1.uniform1 AS target\n", "USING updates AS source\n", "ON target.id = source.id\n", "WHEN MATCHED THEN UPDATE SET *\n", "WHEN NOT MATCHED THEN INSERT *;" ] } ], "metadata": { "Last_Active_Cell_Index": 6, "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.12" } }, "nbformat": 4, "nbformat_minor": 5 }