-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-41290][SQL] Support GENERATED ALWAYS AS expressions for columns in create/replace table statements #38823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
db13658
29d11ec
3c19862
ebc5ed9
02f5783
08a5f09
f9cfd6b
4eab27d
8c80d23
57e5c1a
f9999ef
cbb512a
7155d48
ca838fd
6cf13af
a0eb80e
ed41d31
7d9f8e8
2905db1
564da54
bb684cd
61b801e
e9b28df
53c9dbd
301db0d
c8dce5f
c016690
5b0eaad
f01a0b4
9ff8fa8
09d437d
3fb71ed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,8 @@ | |
| * {@link TableCatalog#createTable(Identifier, Column[], Transform[], Map)}, and report it in | ||
| * {@link Table#columns()} by calling the static {@code create} functions of this interface to | ||
| * create it. | ||
| * <p> | ||
| * A column cannot have both a default value and a generation expression. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| */ | ||
| @Evolving | ||
| public interface Column { | ||
|
|
@@ -42,7 +44,16 @@ static Column create(String name, DataType dataType) { | |
| } | ||
|
|
||
| static Column create(String name, DataType dataType, boolean nullable) { | ||
| return create(name, dataType, nullable, null, null, null); | ||
| return create(name, dataType, nullable, null, null); | ||
| } | ||
|
|
||
| static Column create( | ||
| String name, | ||
| DataType dataType, | ||
| boolean nullable, | ||
| String comment, | ||
| String metadataInJSON) { | ||
| return new ColumnImpl(name, dataType, nullable, comment, null, null, metadataInJSON); | ||
| } | ||
|
|
||
| static Column create( | ||
|
|
@@ -52,7 +63,18 @@ static Column create( | |
| String comment, | ||
| ColumnDefaultValue defaultValue, | ||
| String metadataInJSON) { | ||
| return new ColumnImpl(name, dataType, nullable, comment, defaultValue, metadataInJSON); | ||
| return new ColumnImpl(name, dataType, nullable, comment, defaultValue, null, metadataInJSON); | ||
| } | ||
|
|
||
| static Column create( | ||
| String name, | ||
| DataType dataType, | ||
| boolean nullable, | ||
| String comment, | ||
| String generationExpression, | ||
| String metadataInJSON) { | ||
| return new ColumnImpl(name, dataType, nullable, comment, null, | ||
| generationExpression, metadataInJSON); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -82,6 +104,15 @@ static Column create( | |
| @Nullable | ||
| ColumnDefaultValue defaultValue(); | ||
|
|
||
| /** | ||
| * Returns the generation expression of this table column. Null means no generation expression. | ||
| * <p> | ||
| * The generation expression is stored as spark SQL dialect. It is up to the data source to verify | ||
| * expression compatibility and reject writes as necessary. | ||
| */ | ||
| @Nullable | ||
| String generationExpression(); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added it as just a string here as it seems we don't need any additional information |
||
|
|
||
| /** | ||
| * Returns the column metadata in JSON format. | ||
| */ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.spark.sql.connector.catalog; | ||
|
|
||
| import org.apache.spark.annotation.Evolving; | ||
|
|
||
| /** | ||
| * Capabilities that can be provided by a {@link TableCatalog} implementation. | ||
| * <p> | ||
| * TableCatalogs use {@link TableCatalog#capabilities()} to return a set of capabilities. Each | ||
| * capability signals to Spark that the catalog supports a feature identified by the capability. | ||
| * For example, returning {@link #SUPPORTS_CREATE_TABLE_WITH_GENERATED_COLUMNS} allows Spark to | ||
| * accept {@code GENERATED ALWAYS AS} expressions in {@code CREATE TABLE} statements. | ||
| * | ||
| * @since 3.4.0 | ||
| */ | ||
| @Evolving | ||
| public enum TableCatalogCapability { | ||
|
|
||
| /** | ||
| * Signals that the TableCatalog supports defining generated columns upon table creation in SQL. | ||
| * <p> | ||
| * Without this capability, any create/replace table statements with a generated column defined | ||
| * in the table schema will throw an exception during analysis. | ||
| * <p> | ||
| * A generated column is defined with syntax: {@code colName colType GENERATED ALWAYS AS (expr)} | ||
| * <p> | ||
| * Generation expression are included in the column definition for APIs like | ||
| * {@link TableCatalog#createTable}. | ||
| * See {@link Column#generationExpression()}. | ||
| */ | ||
| SUPPORTS_CREATE_TABLE_WITH_GENERATED_COLUMNS | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.