-
- Downloads
[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.
Showing
- sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/literals.scala 22 additions, 4 deletions.../org/apache/spark/sql/catalyst/expressions/literals.scala
- sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala 19 additions, 10 deletions...ala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
- sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/ExpressionParserSuite.scala 7 additions, 6 deletions...che/spark/sql/catalyst/parser/ExpressionParserSuite.scala
- sql/core/src/test/resources/sql-tests/inputs/literals.sql 7 additions, 0 deletionssql/core/src/test/resources/sql-tests/inputs/literals.sql
- sql/core/src/test/resources/sql-tests/results/literals.sql.out 37 additions, 5 deletions...ore/src/test/resources/sql-tests/results/literals.sql.out
- sql/hive/src/test/scala/org/apache/spark/sql/catalyst/ExpressionSQLBuilderSuite.scala 1 addition, 0 deletions...apache/spark/sql/catalyst/ExpressionSQLBuilderSuite.scala
Loading
Please register or sign in to comment