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/hive | |
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/hive')
-rw-r--r-- | sql/hive/src/test/scala/org/apache/spark/sql/catalyst/ExpressionSQLBuilderSuite.scala | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/sql/hive/src/test/scala/org/apache/spark/sql/catalyst/ExpressionSQLBuilderSuite.scala b/sql/hive/src/test/scala/org/apache/spark/sql/catalyst/ExpressionSQLBuilderSuite.scala index 43a218b4d1..d2b2f38fa1 100644 --- a/sql/hive/src/test/scala/org/apache/spark/sql/catalyst/ExpressionSQLBuilderSuite.scala +++ b/sql/hive/src/test/scala/org/apache/spark/sql/catalyst/ExpressionSQLBuilderSuite.scala @@ -40,6 +40,7 @@ class ExpressionSQLBuilderSuite extends SQLBuilderTest { checkSQL(Literal(Double.NegativeInfinity), "CAST('-Infinity' AS DOUBLE)") checkSQL(Literal(Double.NaN), "CAST('NaN' AS DOUBLE)") checkSQL(Literal(BigDecimal("10.0000000").underlying), "10.0000000BD") + checkSQL(Literal(Array(0x01, 0xA3).map(_.toByte)), "X'01A3'") checkSQL( Literal(Timestamp.valueOf("2016-01-01 00:00:00")), "TIMESTAMP('2016-01-01 00:00:00.0')") // TODO tests for decimals |