question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature Request] SQL syntax for GENERATED columns in OSS

See original GitHub issue

Bug

Using SQL it is not possible to CREATE or INSERT into a table with GENERATED columns with spark 3.2.1 and delta 1.2.0.

Describe the problem

Steps to reproduce

  1. download latest spark-3.2.1-bin-hadoop3.2-scala2.13
  2. start with
bin/spark-sql --packages io.delta:delta-core_2.13:1.2.0 --conf spark.sql.extensions=io.delta.sql.DeltaSparkSessionExtension --conf spark.sql.catalog.spark_catalog=org.apache.spark.sql.delta.catalog.DeltaCatalog
  1. try creating a table with a generated column:
CREATE TABLE `everts` (
 event_time TIMESTAMP NOT NULL,
 event_month DATE GENERATED ALWAYS AS (CAST(event_time AS DATE))
)
USING DELTA
;
  1. try INSERT INTO
INSERT INTO TABLE default.events (event_time) 
VALUES (timestamp(now()))
;

Observed results

neither the CREATE nor the INSERT (for the case the table was created with DeltaTableBuilder) would succeed.

Expected results

Would be really great if the Delta OSS supports more of the feature announced by Databricks (otherwise it would help to communicate explicitly which features are Databricks exclusive and which are also available in the Delta OSS).

Further details

Could it be that the SQL GENERATED column syntax is supported on databricks only? Or am I missing something? I cannot find any ‘GENERATED ALWAYS …’ related grammar in DeltaSqlBase.g4 either?

Environment information

  • Delta Lake version: 1.2.0
  • Spark version: 3.2.1
  • Scala version: 2.13.5

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:4
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
allisonport-dbcommented, Nov 28, 2022

Working to get this into 3.4 tracking via SPARK-41290

4reactions
zsxwingcommented, Apr 29, 2022

@kpe This is not in Spark yet. We are talking to the Spark community and hope we can get this syntax supported in Spark 3.4. It’s a SQL standard so it should not be hard to add the parser support. And you are right. We need to add this to SqlBaseParser.g4.

Read more comments on GitHub >

github_iconTop Results From Across the Web

13.1.18.7 CREATE TABLE and Generated Columns
CREATE TABLE supports the specification of generated columns. Values of a generated column are computed from an expression included in the column definition ......
Read more >
Generated Columns | PingCAP Docs
This document introduces the concept and usage of generated columns. Basic concepts. Unlike general columns, the value of the generated column is calculated ......
Read more >
Generated (Virtual and Persistent/Stored) Columns - MariaDB
A generated column is a column in a table that cannot explicitly be set to a specific value in a DML query. Instead,...
Read more >
Generated Columns in PostgreSQL - The Developer Space
This article describes different ways of setting up generated (computed) columns in different versions of PostgreSQL.
Read more >
Use Delta Lake generated columns - Azure Databricks
Tables created with generated columns have a higher table writer protocol version than the default. See Table protocol versioning to understand ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found