-
Notifications
You must be signed in to change notification settings - Fork 72
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
feat(spark): bitwise functions #309
Changes from all commits
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 |
---|---|---|
|
@@ -29,6 +29,8 @@ import scala.collection.JavaConverters.asScalaBufferConverter | |
private class ToSparkType | ||
extends TypeVisitor.TypeThrowsVisitor[DataType, RuntimeException]("Unknown expression type.") { | ||
|
||
override def visit(expr: Type.I8): DataType = ByteType | ||
override def visit(expr: Type.I16): DataType = ShortType | ||
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. while you're at it, mind adding these also to ToSparkType? 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. This is in 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. Ah right, all good then! |
||
override def visit(expr: Type.I32): DataType = IntegerType | ||
override def visit(expr: Type.I64): DataType = LongType | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,15 @@ class ToSparkExpression( | |
Literal.FalseLiteral | ||
} | ||
} | ||
|
||
override def visit(expr: SExpression.I8Literal): Expression = { | ||
Literal(expr.value().asInstanceOf[Byte], ToSubstraitType.convert(expr.getType)) | ||
} | ||
|
||
override def visit(expr: SExpression.I16Literal): Expression = { | ||
Literal(expr.value().asInstanceOf[Short], ToSubstraitType.convert(expr.getType)) | ||
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. and here also the other direction for the conversion? 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. It's already covered in the other direction in |
||
} | ||
|
||
override def visit(expr: SExpression.I32Literal): Expression = { | ||
Literal(expr.value(), ToSubstraitType.convert(expr.getType)) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -146,11 +146,12 @@ abstract class ToSubstraitExpression extends HasOutputStack[Seq[Attribute]] { | |
"org.apache.spark.sql.catalyst.expressions.PromotePrecision") => | ||
translateUp(p.children.head) | ||
case CaseWhen(branches, elseValue) => translateCaseWhen(branches, elseValue) | ||
case In(value, list) => translateIn(value, list) | ||
case InSet(value, set) => translateIn(value, set.toSeq.map(v => Literal(v))) | ||
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. nit: mind moving this next to 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. Sure, although |
||
case scalar @ ScalarFunction(children) => | ||
Util | ||
.seqToOption(children.map(translateUp)) | ||
.flatMap(toScalarFunction.convert(scalar, _)) | ||
case In(value, list) => translateIn(value, list) | ||
case p: PlanExpression[_] => translateSubQuery(p) | ||
case other => default(other) | ||
} | ||
|
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.
It looks like in Spark the base can be either int or long, and return type is set accordingly. I we should add both options?
Quickly testing this, it works for
select shiftright(col, 2) from (values (bigint(1234)) as table(col))
but not forselect shiftright(col, 2) from (values (1234) as table(col))
, so yep I think we need to list both versions here.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.
Overall I think it's fine to add the function here initially, but it'd be good to also file the PR/Issue on the core functions since this seems general enough, I think :)
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 agree, although that might take a bit longer ;)