diff options
author | Herman van Hovell <hvanhovell@databricks.com> | 2016-09-01 12:01:22 -0700 |
---|---|---|
committer | Josh Rosen <joshrosen@databricks.com> | 2016-09-01 12:01:22 -0700 |
commit | 2be5f8d7e0819de03971d0af6fa310793d2d0e65 (patch) | |
tree | 602c660b7215536f901af5cc729664a5f0b4cf49 /sql/catalyst/src/test | |
parent | a0aac4b775bc8c275f96ad0fbf85c9d8a3690588 (diff) | |
download | spark-2be5f8d7e0819de03971d0af6fa310793d2d0e65.tar.gz spark-2be5f8d7e0819de03971d0af6fa310793d2d0e65.tar.bz2 spark-2be5f8d7e0819de03971d0af6fa310793d2d0e65.zip |
[SPARK-17263][SQL] Add hexadecimal literal parsing
## What changes were proposed in this pull request?
This PR adds the ability to parse SQL (hexadecimal) binary literals (AKA bit strings). It follows the following syntax `X'[Hexadecimal Characters]+'`, for example: `X'01AB'` would create a binary the following binary array `0x01AB`.
If an uneven number of hexadecimal characters is passed, then the upper 4 bits of the initial byte are kept empty, and the lower 4 bits are filled using the first character. For example `X'1C7'` would create the following binary array `0x01C7`.
Binary data (Array[Byte]) does not have a proper `hashCode` and `equals` functions. This meant that comparing `Literal`s containing binary data was a pain. I have updated Literal.hashCode and Literal.equals to deal properly with binary data.
## How was this patch tested?
Added tests to the `ExpressionParserSuite`, `SQLQueryTestSuite` and `ExpressionSQLBuilderSuite`.
Author: Herman van Hovell <hvanhovell@databricks.com>
Closes #14832 from hvanhovell/SPARK-17263.
Diffstat (limited to 'sql/catalyst/src/test')
-rw-r--r-- | sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/ExpressionParserSuite.scala | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/ExpressionParserSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/ExpressionParserSuite.scala index dbc5db39ae..4e399eef1f 100644 --- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/ExpressionParserSuite.scala +++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/ExpressionParserSuite.scala @@ -331,16 +331,17 @@ class ExpressionParserSuite extends PlanTest { test("type constructors") { // Dates. assertEqual("dAte '2016-03-11'", Literal(Date.valueOf("2016-03-11"))) - intercept[IllegalArgumentException] { - parseExpression("DAtE 'mar 11 2016'") - } + intercept("DAtE 'mar 11 2016'") // Timestamps. assertEqual("tImEstAmp '2016-03-11 20:54:00.000'", Literal(Timestamp.valueOf("2016-03-11 20:54:00.000"))) - intercept[IllegalArgumentException] { - parseExpression("timestamP '2016-33-11 20:54:00.000'") - } + intercept("timestamP '2016-33-11 20:54:00.000'") + + // Binary. + assertEqual("X'A'", Literal(Array(0x0a).map(_.toByte))) + assertEqual("x'A10C'", Literal(Array(0xa1, 0x0c).map(_.toByte))) + intercept("x'A1OC'") // Unsupported datatype. intercept("GEO '(10,-6)'", "Literals of type 'GEO' are currently not supported.") |