-
Notifications
You must be signed in to change notification settings - Fork 28.3k
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
[SPARK-48824][SQL] Add Identity Column SQL syntax #47614
Changes from all commits
bde6e0b
c00bee8
dd8b835
77eae56
a5f9ddf
54e9d3b
825d682
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 |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* 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; | ||
zhipengmao-db marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import org.apache.spark.annotation.Evolving; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* Identity column specification. | ||
*/ | ||
@Evolving | ||
public class IdentityColumnSpec { | ||
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. let's add |
||
private final long start; | ||
private final long step; | ||
private final boolean allowExplicitInsert; | ||
|
||
/** | ||
* Creates an identity column specification. | ||
* @param start the start value to generate the identity values | ||
* @param step the step value to generate the identity values | ||
* @param allowExplicitInsert whether the identity column allows explicit insertion of values | ||
*/ | ||
public IdentityColumnSpec(long start, long step, boolean allowExplicitInsert) { | ||
this.start = start; | ||
this.step = step; | ||
this.allowExplicitInsert = allowExplicitInsert; | ||
} | ||
|
||
/** | ||
* @return the start value to generate the identity values | ||
*/ | ||
public long getStart() { | ||
return start; | ||
} | ||
|
||
/** | ||
* @return the step value to generate the identity values | ||
*/ | ||
public long getStep() { | ||
return step; | ||
} | ||
|
||
/** | ||
* @return whether the identity column allows explicit insertion of values | ||
*/ | ||
public boolean isAllowExplicitInsert() { | ||
return allowExplicitInsert; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
IdentityColumnSpec that = (IdentityColumnSpec) o; | ||
return start == that.start && | ||
step == that.step && | ||
allowExplicitInsert == that.allowExplicitInsert; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(start, step, allowExplicitInsert); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "IdentityColumnSpec{" + | ||
"start=" + start + | ||
", step=" + step + | ||
", allowExplicitInsert=" + allowExplicitInsert + | ||
"}"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,7 +53,7 @@ static Column create( | |
boolean nullable, | ||
String comment, | ||
String metadataInJSON) { | ||
return new ColumnImpl(name, dataType, nullable, comment, null, null, metadataInJSON); | ||
return new ColumnImpl(name, dataType, nullable, comment, null, null, null, metadataInJSON); | ||
} | ||
|
||
static Column create( | ||
|
@@ -63,7 +63,8 @@ static Column create( | |
String comment, | ||
ColumnDefaultValue defaultValue, | ||
String metadataInJSON) { | ||
return new ColumnImpl(name, dataType, nullable, comment, defaultValue, null, metadataInJSON); | ||
return new ColumnImpl(name, dataType, nullable, comment, defaultValue, | ||
null, null, metadataInJSON); | ||
} | ||
|
||
static Column create( | ||
|
@@ -74,7 +75,18 @@ static Column create( | |
String generationExpression, | ||
String metadataInJSON) { | ||
return new ColumnImpl(name, dataType, nullable, comment, null, | ||
generationExpression, metadataInJSON); | ||
generationExpression, null, metadataInJSON); | ||
} | ||
|
||
static Column create( | ||
String name, | ||
DataType dataType, | ||
boolean nullable, | ||
String comment, | ||
IdentityColumnSpec identityColumnSpec, | ||
String metadataInJSON) { | ||
return new ColumnImpl(name, dataType, nullable, comment, null, | ||
null, identityColumnSpec, metadataInJSON); | ||
} | ||
|
||
/** | ||
|
@@ -113,6 +125,12 @@ static Column create( | |
@Nullable | ||
String generationExpression(); | ||
|
||
/** | ||
* Returns the identity column specification of this table column. Null means no identity column. | ||
*/ | ||
@Nullable | ||
IdentityColumnSpec identityColumnSpec(); | ||
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. to double check, only one of the 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. Great catch! Yes only one of the |
||
|
||
/** | ||
* Returns the column metadata in JSON format. | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 Always nice to see thoughtful pick for SQLSTATE :-)