-
Notifications
You must be signed in to change notification settings - Fork 28.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPARK-51395][SQL] Refine handling of default values in procedures
- Loading branch information
1 parent
cdba396
commit 425e456
Showing
8 changed files
with
469 additions
and
15 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/DefaultValue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* 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 java.util.Objects; | ||
import javax.annotation.Nullable; | ||
|
||
import org.apache.spark.annotation.Evolving; | ||
import org.apache.spark.sql.connector.expressions.Expression; | ||
|
||
@Evolving | ||
public class DefaultValue { | ||
private final String sql; | ||
private final Expression expr; | ||
|
||
public DefaultValue(String sql) { | ||
this(sql, null /* no expression */); | ||
} | ||
|
||
public DefaultValue(Expression expr) { | ||
this(null /* no sql */, expr); | ||
} | ||
|
||
public DefaultValue(String sql, Expression expr) { | ||
if (sql == null && expr == null) { | ||
throw new IllegalArgumentException("SQL and expression can't be both null"); | ||
} | ||
this.sql = sql; | ||
this.expr = expr; | ||
} | ||
|
||
@Nullable | ||
public String getSql() { | ||
return sql; | ||
} | ||
|
||
@Nullable | ||
public Expression getExpression() { | ||
return expr; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (this == other) return true; | ||
if (other == null || getClass() != other.getClass()) return false; | ||
DefaultValue that = (DefaultValue) other; | ||
return Objects.equals(sql, that.sql) && Objects.equals(expr, that.expr); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(sql, expr); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("DefaultValue{sql=%s, expression=%s}", sql, expr); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.