delta-io / delta

An open-source storage framework that enables building a Lakehouse architecture with compute engines including Spark, PrestoDB, Flink, Trino, and Hive and APIs
https://delta.io
Apache License 2.0
7.62k stars 1.71k forks source link

[Feature Request][Delta][Spark] SQL syntax for PRIMARY KEY constraint in OSS (informational purpose only) #3341

Open tomasz-kaminski opened 4 months ago

tomasz-kaminski commented 4 months ago

Feature request

Which Delta project/connector is this regarding?

Overview

Support SQL syntax for PRIMARY KEY information in Delta Tables (of course, without enforcing primary key, similarly as in Databricks)

Further details

please see: https://docs.databricks.com/en/sql/language-manual/sql-ref-syntax-ddl-create-table-constraint.html

examples:

-- Create a table with a primary key
> CREATE TABLE persons(first_name STRING NOT NULL, last_name STRING NOT NULL, nickname STRING,
                       CONSTRAINT persons_pk PRIMARY KEY(first_name, last_name));

-- create a table with a foreign key
> CREATE TABLE pets(name STRING, owner_first_name STRING, owner_last_name STRING,
                    CONSTRAINT pets_persons_fk FOREIGN KEY (owner_first_name, owner_last_name) REFERENCES persons);

-- Create a table with a single column primary key and system generated name
> CREATE TABLE customers(customerid STRING NOT NULL PRIMARY KEY, name STRING);

-- Create a table with a names single column primary key and a named single column foreign key
> CREATE TABLE orders(orderid BIGINT NOT NULL CONSTRAINT orders_pk PRIMARY KEY,
                      customerid STRING CONSTRAINT orders_customers_fk REFERENCES customers);

Willingness to contribute

The Delta Lake Community encourages new feature contributions. Would you or another member of your organization be willing to contribute an implementation of this feature?

sairudavath commented 3 months ago

Hey , I have tried this primary key constraints in databricks but its not working it's allowing duplicate values in the primary key column of table. Could you provide any solution for this that would be greatly appreciated 🙏