Skip to content

Commit

Permalink
Rebase commit
Browse files Browse the repository at this point in the history
  • Loading branch information
xuzifu666 committed Feb 6, 2025
1 parent 46a69c1 commit 0a6a35e
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@
import static org.apache.calcite.sql.fun.SqlLibraryOperators.ASINH;
import static org.apache.calcite.sql.fun.SqlLibraryOperators.ATAND;
import static org.apache.calcite.sql.fun.SqlLibraryOperators.ATANH;
import static org.apache.calcite.sql.fun.SqlLibraryOperators.BASE64;
import static org.apache.calcite.sql.fun.SqlLibraryOperators.BIN;
import static org.apache.calcite.sql.fun.SqlLibraryOperators.BITAND_AGG;
import static org.apache.calcite.sql.fun.SqlLibraryOperators.BITOR_AGG;
Expand Down Expand Up @@ -337,7 +336,6 @@
import static org.apache.calcite.sql.fun.SqlLibraryOperators.UNIX_MICROS;
import static org.apache.calcite.sql.fun.SqlLibraryOperators.UNIX_MILLIS;
import static org.apache.calcite.sql.fun.SqlLibraryOperators.UNIX_SECONDS;
import static org.apache.calcite.sql.fun.SqlLibraryOperators.UN_BASE64;
import static org.apache.calcite.sql.fun.SqlLibraryOperators.URL_DECODE;
import static org.apache.calcite.sql.fun.SqlLibraryOperators.URL_ENCODE;
import static org.apache.calcite.sql.fun.SqlLibraryOperators.XML_TRANSFORM;
Expand Down Expand Up @@ -688,8 +686,6 @@ void populate1() {
defineMethod(INITCAP, BuiltInMethod.INITCAP.method, NullPolicy.STRICT);
defineMethod(TO_BASE64, BuiltInMethod.TO_BASE64.method, NullPolicy.STRICT);
defineMethod(FROM_BASE64, BuiltInMethod.FROM_BASE64.method, NullPolicy.STRICT);
defineMethod(BASE64, BuiltInMethod.TO_BASE64.method, NullPolicy.STRICT);
defineMethod(UN_BASE64, BuiltInMethod.FROM_BASE64.method, NullPolicy.STRICT);
defineMethod(TO_BASE32, BuiltInMethod.TO_BASE32.method, NullPolicy.STRICT);
defineMethod(FROM_BASE32, BuiltInMethod.FROM_BASE32.method, NullPolicy.STRICT);
defineMethod(HEX, BuiltInMethod.HEX.method, NullPolicy.STRICT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ public static ByteString uuidToBinary(UUID uuid) {
return new ByteString(dest);
}

/** SQL TO_BASE64(string)/BASE64(string) function. */
/** SQL TO_BASE64(string) function. */
public static String toBase64(String string) {
return toBase64_(string.getBytes(UTF_8));
}
Expand All @@ -320,7 +320,7 @@ private static String toBase64_(byte[] bytes) {
return str.substring(0, str.length() - 1);
}

/** SQL FROM_BASE64(string)/UNBASE64(string) function. */
/** SQL FROM_BASE64(string) function. */
public static @Nullable ByteString fromBase64(String base64) {
try {
base64 = FROM_BASE64_REGEXP.matcher(base64).replaceAll("");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1855,19 +1855,6 @@ private static RelDataType deriveTypeMapFromEntries(SqlOperatorBinding opBinding
OperandTypes.STRING.or(OperandTypes.BINARY),
SqlFunctionCategory.STRING);

@LibraryOperator(libraries = {HIVE})
public static final SqlFunction BASE64 =
SqlBasicFunction.create("BASE64",
ReturnTypes.VARCHAR_NULLABLE,
OperandTypes.STRING.or(OperandTypes.BINARY),
SqlFunctionCategory.STRING);

@LibraryOperator(libraries = {HIVE})
public static final SqlFunction UN_BASE64 =
SqlBasicFunction.create("UNBASE64",
ReturnTypes.VARBINARY_FORCE_NULLABLE,
OperandTypes.STRING, SqlFunctionCategory.STRING);

@LibraryOperator(libraries = {BIG_QUERY})
public static final SqlFunction FROM_BASE32 =
SqlBasicFunction.create("FROM_BASE32",
Expand Down
4 changes: 1 addition & 3 deletions site/_docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -2917,13 +2917,11 @@ In the following:
| p | LOG([, base ], numeric1 ) | Returns the logarithm of *numeric1* to base *base*, or base 10 if *numeric1* is not present, or error if *numeric1* is 0 or negative
| m s | LOG2(numeric) | Returns the base 2 logarithm of *numeric*
| s | LOG1P(numeric) | Returns the natural logarithm of 1 plus *numeric*
| b o p r s h | LPAD(string, length [, pattern ]) | Returns a string or bytes value that consists of *string* prepended to *length* with *pattern*
| b o p r s h | LPAD(string, length [, pattern ]) | Returns a string or bytes value that consists of *string* prepended to *length* with *pattern*
| b | TO_BASE32(string) | Converts the *string* to base-32 encoded form and returns an encoded string
| b | FROM_BASE32(string) | Returns the decoded result of a base-32 *string* as a string
| m | TO_BASE64(string) | Converts the *string* to base-64 encoded form and returns a encoded string
| b m | FROM_BASE64(string) | Returns the decoded result of a base-64 *string* as a string. If the input argument is an invalid base-64 *string* the function returns `NULL`
| h | BASE64(string) | Converts the *string* to base-64 encoded form and returns a encoded string
| h | UNBASE64(string) | Returns the decoded result of a base-64 *string* as a string. If the input argument is an invalid base-64 *string* the function returns `NULL`
| h s | HEX(string) | Converts *string* into a hexadecimal varchar
| b | TO_HEX(binary) | Converts *binary* into a hexadecimal varchar
| b | FROM_HEX(varchar) | Converts a hexadecimal-encoded *varchar* into bytes
Expand Down
38 changes: 0 additions & 38 deletions testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5173,44 +5173,6 @@ void testBitGetFunc(SqlOperatorFixture f, String functionName) {
f.checkString("to_base64(x'61')", "YQ==", "VARCHAR NOT NULL");
}

/** Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-6812">[CALCITE-6812]
* Add base64 function (enabled in Hive library)</a>. */
@Test void testBase64() {
final SqlOperatorFixture f = fixture().withLibrary(SqlLibrary.HIVE);
f.setFor(SqlLibraryOperators.BASE64);
f.checkString("base64(cast('a' as binary))", "YQ==", "VARCHAR NOT NULL");
f.checkString("base64('')", "", "VARCHAR NOT NULL");
f.checkNull("base64(null)");
f.checkString("base64('This is a test String.')",
"VGhpcyBpcyBhIHRlc3QgU3RyaW5nLg==",
"VARCHAR NOT NULL");
}

@Test void testUnBase64() {
final SqlOperatorFixture f0 = fixture()
.setFor(SqlLibraryOperators.UN_BASE64);
final Consumer<SqlOperatorFixture> consumer = f -> {
f.checkString("unbase64('VGhpcyBpcyBhIHRlc3QgU3RyaW5nLg==')",
"546869732069732061207465737420537472696e672e",
"VARBINARY");
f.checkString("unbase64('VGhpcyBpcyBhIHRlc\t3QgU3RyaW5nLg==')",
"546869732069732061207465737420537472696e672e",
"VARBINARY");
f.checkString("unbase64('VGhpcyBpcyBhIHRlc\t3QgU3\nRyaW5nLg==')",
"546869732069732061207465737420537472696e672e",
"VARBINARY");
f.checkString("unbase64('VGhpcyB pcyBhIHRlc3Qg\tU3Ry\naW5nLg==')",
"546869732069732061207465737420537472696e672e",
"VARBINARY");
f.checkNull("unbase64('-1')");
f.checkNull("unbase64('-100')");
f.checkNull("unbase64(null)");
};
f0.forEachLibrary(list(SqlLibrary.HIVE), consumer);

}

@Test void testToChar() {
final SqlOperatorFixture f0 = fixture().setFor(SqlLibraryOperators.TO_CHAR);
final Consumer<SqlOperatorFixture> consumer = f -> {
Expand Down

0 comments on commit 0a6a35e

Please sign in to comment.