From 150ccb92df132da33dc6f98fa5363403f546394a Mon Sep 17 00:00:00 2001 From: LiuNeng <1398775315@qq.com> Date: Mon, 17 Jun 2024 18:40:03 +0800 Subject: [PATCH] [CH] Support function base64/unbase64 (#6077) [CH] Support function base64/unbase64 Co-authored-by: liuneng1994 --- ...GlutenClickhouseStringFunctionsSuite.scala | 40 +++++++++++++++++++ .../expression/ExpressionMappings.scala | 2 + .../gluten/expression/ExpressionNames.scala | 2 + 3 files changed, 44 insertions(+) diff --git a/backends-clickhouse/src/test/scala/org/apache/gluten/execution/GlutenClickhouseStringFunctionsSuite.scala b/backends-clickhouse/src/test/scala/org/apache/gluten/execution/GlutenClickhouseStringFunctionsSuite.scala index 029a763c983c..163a8fedab7e 100644 --- a/backends-clickhouse/src/test/scala/org/apache/gluten/execution/GlutenClickhouseStringFunctionsSuite.scala +++ b/backends-clickhouse/src/test/scala/org/apache/gluten/execution/GlutenClickhouseStringFunctionsSuite.scala @@ -97,4 +97,44 @@ class GlutenClickhouseStringFunctionsSuite extends GlutenClickHouseWholeStageTra } } + test("base64") { + val tableName = "base64_table" + withTable(tableName) { + sql(s"create table $tableName(data String) using parquet") + sql(s""" + |insert into $tableName values + | ("hello") + """.stripMargin) + + val sql_str = + s""" + |select + | base64(data) + | from $tableName + """.stripMargin + + runQueryAndCompare(sql_str) { _ => } + } + } + + test("unbase64") { + val tableName = "unbase64_table" + withTable(tableName) { + sql(s"create table $tableName(data String) using parquet") + sql(s""" + |insert into $tableName values + | ("U3BhcmsgU1FM") + """.stripMargin) + + val sql_str = + s""" + |select + | unbase64(data) + | from $tableName + """.stripMargin + + runQueryAndCompare(sql_str) { _ => } + } + } + } diff --git a/gluten-core/src/main/scala/org/apache/gluten/expression/ExpressionMappings.scala b/gluten-core/src/main/scala/org/apache/gluten/expression/ExpressionMappings.scala index 230d91005e9c..f0082456fb18 100644 --- a/gluten-core/src/main/scala/org/apache/gluten/expression/ExpressionMappings.scala +++ b/gluten-core/src/main/scala/org/apache/gluten/expression/ExpressionMappings.scala @@ -101,6 +101,8 @@ object ExpressionMappings { Sig[Encode](ENCODE), Sig[Uuid](UUID), Sig[BitLength](BIT_LENGTH), + Sig[UnBase64](UNBASE64), + Sig[Base64](BASE64), // URL functions Sig[ParseUrl](PARSE_URL), diff --git a/shims/common/src/main/scala/org/apache/gluten/expression/ExpressionNames.scala b/shims/common/src/main/scala/org/apache/gluten/expression/ExpressionNames.scala index f817612a1e8d..20db380180e3 100644 --- a/shims/common/src/main/scala/org/apache/gluten/expression/ExpressionNames.scala +++ b/shims/common/src/main/scala/org/apache/gluten/expression/ExpressionNames.scala @@ -127,6 +127,8 @@ object ExpressionNames { final val ENCODE = "encode" final val UUID = "uuid" final val BIT_LENGTH = "bit_length" + final val UNBASE64 = "unbase64" + final val BASE64 = "base64" // URL functions final val PARSE_URL = "parse_url"