-
Notifications
You must be signed in to change notification settings - Fork 984
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
Drill 7955: Extend XOR bitwise functions to match AND and OR #2264
Changes from all commits
e8edd4c
188574f
6174d3c
948af32
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 |
---|---|---|
|
@@ -112,7 +112,7 @@ unaryMathFunctions : [ | |
} | ||
], | ||
binaryMathFunctions : [ | ||
{className: "Div", funcName: "div", javaFunc : " / ", types: [ | ||
{className: "Div", funcName: "div", aliasName: "", javaFunc : " / ", types: [ | ||
{input: "Int", outputType: "Int", castType: "int"}, | ||
{input: "BigInt", outputType: "BigInt", castType: "long"}, | ||
{input: "Float4", outputType: "Float4", castType: "float", roundingRequired: "true"}, | ||
|
@@ -125,7 +125,7 @@ unaryMathFunctions : [ | |
{input: "UInt8", outputType: "UInt8", castType: "long"} | ||
] | ||
}, | ||
{className: "Mod", funcName: "mod", javaFunc : " % ", types: [ | ||
{className: "Mod", funcName: "mod", aliasName: "", javaFunc : " % ", types: [ | ||
{input: "Int", outputType: "Int", castType: "int"}, | ||
{input: "BigInt", outputType: "BigInt", castType: "long"}, | ||
{input: "Float4", outputType: "Float4", castType: "float"}, | ||
|
@@ -138,7 +138,7 @@ unaryMathFunctions : [ | |
{input: "UInt8", outputType: "UInt8", castType: "long"} | ||
] | ||
}, | ||
{className: "LeftShift", funcName: "lshift", javaFunc: " << ", types: [ | ||
{className: "LeftShift", funcName: "lshift", aliasName: "", javaFunc: " << ", types: [ | ||
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. Would we want this for all 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. See my comment for |
||
{input: "Int", outputType: "Int", castType: "int"}, | ||
{input: "BigInt", outputType: "BigInt", castType: "long"}, | ||
{input: "SmallInt", outputType: "SmallInt", castType: "short"}, | ||
|
@@ -149,7 +149,18 @@ unaryMathFunctions : [ | |
{input: "UInt8", outputType: "UInt8", castType: "long"} | ||
] | ||
}, | ||
{className: "RightShift", funcName: "rshift", javaFunc: " >> ", types: [ | ||
{className: "RightShift", funcName: "rshift", aliasName: "", javaFunc: " >> ", types: [ | ||
{input: "Int", outputType: "Int", castType: "int"}, | ||
{input: "BigInt", outputType: "BigInt", castType: "long"}, | ||
{input: "SmallInt", outputType: "SmallInt", castType: "short"}, | ||
{input: "TinyInt", outputType: "TinyInt", castType: "byte"}, | ||
{input: "UInt1", outputType: "UInt1", castType: "byte"}, | ||
{input: "UInt2", outputType: "UInt2", castType: "char"}, | ||
{input: "UInt4", outputType: "UInt4", castType: "int"}, | ||
{input: "UInt8", outputType: "UInt8", castType: "long"} | ||
] | ||
}, | ||
{className: "Xor", funcName: "xor", aliasName: "^", javaFunc: " ^ ", types: [ | ||
{input: "Int", outputType: "Int", castType: "int"}, | ||
{input: "BigInt", outputType: "BigInt", castType: "long"}, | ||
{input: "SmallInt", outputType: "SmallInt", castType: "short"}, | ||
|
@@ -423,4 +434,4 @@ trigoMathFunctions : [ | |
] | ||
} | ||
] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,6 @@ | |
import org.apache.drill.exec.expr.annotations.Output; | ||
import org.apache.drill.exec.expr.annotations.Param; | ||
import org.apache.drill.exec.expr.holders.BitHolder; | ||
import org.apache.drill.exec.expr.holders.IntHolder; | ||
|
||
/** | ||
* Function templates for Bit/BOOLEAN functions other than comparison | ||
|
@@ -71,22 +70,4 @@ public void eval() { | |
} | ||
} | ||
|
||
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. Out of curiosity, why is this being deleted? 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. The addition of xor to MathFunc.tdd made it a redundant special case: 32-bit ints are already provided for by the new FreeMarker version. We get a small bit of clean-up for free here because the deleted IntXor function was out of place in BitFunctions.java, which otherwise only contains functions that operate on the boolean type BIT. |
||
|
||
@FunctionTemplate(names = {FunctionNames.XOR, "^"}, | ||
scope = FunctionScope.SIMPLE, | ||
nulls = NullHandling.NULL_IF_NULL) | ||
public static class IntXor implements DrillSimpleFunc { | ||
|
||
@Param IntHolder left; | ||
@Param IntHolder right; | ||
@Output IntHolder out; | ||
|
||
@Override | ||
public void setup() {} | ||
|
||
@Override | ||
public void eval() { | ||
out.value = left.value ^ right.value; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
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. Suggestion: this form of test was used very early on in Drill before the full SQL stack worked. Consider writing a SQL-based test. Since we are trying to support all types, I wonder if we should have a test which generates the needed SQL. Something like: SELECT CAST(A AS SMALLINT) XOR CAST(B AS SMALLINT)
FROM (VALUES ...) Then generate the SQL for each supported data type and verify the results. 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. Thanks for the review @paul-rogers, I'll certain allow more time for reviews to arrive, in future. The naming of these functions put me into a bit of a spin, to the point where I couldn't formulate very good questions about naming when I asked on the Slack channel.
I'd be grateful for any suggestion of where to take this in a follow-up commit... |
||
head : { | ||
version : 1, | ||
generator : { | ||
type : "optiq", | ||
info : "na" | ||
}, | ||
type : "APACHE_DRILL_PHYSICAL" | ||
}, | ||
graph:[ | ||
{ | ||
@id:1, | ||
pop:"mock-sub-scan", | ||
url: "http://apache.org", | ||
entries:[ | ||
{records: 1, types: [ | ||
{name: "blue", type: "BIGINT", mode: "REQUIRED"} | ||
]} | ||
] | ||
}, { | ||
pop : "project", | ||
@id : 2, | ||
exprs : [ | ||
{ ref : "ref1", expr : " lshift(3,10) "}, | ||
{ ref : "ref2", expr : " rshift(3072, 10) "}, | ||
{ ref : "ref3", expr : " xor(7, 9) " } | ||
], | ||
child : 1 | ||
}, { | ||
pop : "screen", | ||
@id : 3, | ||
child : 2 | ||
} ] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{"A" : 7, "B" : 2, "C" : true, "D" : 1} | ||
{"A" : 4, "B" : -2, "C" : false, "D" : 0} | ||
{"A" : 4, "B" : 4, "C" : false, "D" : 0} | ||
{"A" : 4, "B" : -4, "C" : true, "D" : 1} | ||
{"A" : 4, "B" : -4, "C" : true, "D" : 1} |
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.
Same comment as elsewhere... would we want this for other
INT
like data types or does Drill handle that elsewhere?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 believe it does handle all widths already. If you look a full listing of MathFunc.tdd, rather than what this diff reveals, you'll see integer types from 8 bits to 64 bits.