-
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-16730][SQL] Implement function aliases for type casts #14362
Conversation
@@ -200,24 +200,6 @@ class TypeCoercionSuite extends PlanTest { | |||
widenTest(ArrayType(IntegerType), StructType(Seq()), None) | |||
} | |||
|
|||
private def ruleTest(rule: Rule[LogicalPlan], initial: Expression, transformed: Expression) { |
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.
I moved this into PlanTest
@cloud-fan and @hvanhovell can you take a look? |
case u: UnresolvedFunction | ||
if u.name.database.isEmpty && u.children.size == 1 && !u.isDistinct => | ||
u.name.funcName.toLowerCase match { | ||
case "boolean" => Cast(u.children.head, BooleanType) |
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.
can we use FunctionRegister
to handle these?
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.
do you mean putting in FunctionRegistry?
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.
yup, but not sure if it can work
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 for this. I think you can make it work. Implement a method that creates the same as FunctionRegistry.expression[T <: Expression](name: String)
method, e.g.:
def cast(name: String, dt: DataType): (String, (ExpressionInfo, FunctionBuilder)) = {
val info = new ExpressionInfo(classOf[Cast].getName, name)
name -> (info, Cast(_, dt))
}
and use that method to register these casts...
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.
That was in #14364
Test build #62869 has finished for PR 14362 at commit
|
Closing this one in favor of #14364 |
What changes were proposed in this pull request?
Spark 1.x supports using the Hive type name as function names for doing casts, e.g.
The above query would work in Spark 1.x because Spark 1.x fail back to Hive for unimplemented functions, and break in Spark 2.0 because the fall back was removed.
This patch implements function aliases using an analyzer rule for the following cast functions:
How was this patch tested?
Added unit tests for SubstituteFunctionAliases as well as end-to-end tests for SQLCompatibilityFunctionSuite.