You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by ta...@apache.org on 2023/06/26 14:55:15 UTC
[calcite] 03/04: add ReturnTypes.VARCHAR_NULLABLE
This is an automated email from the ASF dual-hosted git repository.
tanner pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git
commit 0c77afd6af698c4c2170a9a19dd7a143a52de4fb
Author: zoudan <zo...@bytedance.com>
AuthorDate: Wed Jun 14 10:28:34 2023 +0800
add ReturnTypes.VARCHAR_NULLABLE
---
.../org/apache/calcite/sql/fun/SqlLibraryOperators.java | 12 ++++--------
.../main/java/org/apache/calcite/sql/type/ReturnTypes.java | 13 +++++++++++++
2 files changed, 17 insertions(+), 8 deletions(-)
diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java b/core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java
index 1c81280150..38f3e4110a 100644
--- a/core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java
+++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java
@@ -469,8 +469,7 @@ public abstract class SqlLibraryOperators {
@LibraryOperator(libraries = {MYSQL})
public static final SqlFunction COMPRESS =
SqlBasicFunction.create("COMPRESS",
- ReturnTypes.explicit(SqlTypeName.VARBINARY)
- .andThen(SqlTypeTransforms.TO_NULLABLE),
+ ReturnTypes.VARBINARY_NULLABLE,
OperandTypes.STRING, SqlFunctionCategory.STRING);
@LibraryOperator(libraries = {MYSQL})
@@ -1225,8 +1224,7 @@ public abstract class SqlLibraryOperators {
@LibraryOperator(libraries = {BIG_QUERY, MYSQL})
public static final SqlFunction FROM_BASE64 =
SqlBasicFunction.create("FROM_BASE64",
- ReturnTypes.explicit(SqlTypeName.VARBINARY)
- .andThen(SqlTypeTransforms.TO_NULLABLE),
+ ReturnTypes.VARBINARY_NULLABLE,
OperandTypes.STRING, SqlFunctionCategory.STRING);
@LibraryOperator(libraries = {MYSQL})
@@ -1239,15 +1237,13 @@ public abstract class SqlLibraryOperators {
@LibraryOperator(libraries = {BIG_QUERY})
public static final SqlFunction FROM_BASE32 =
SqlBasicFunction.create("FROM_BASE32",
- ReturnTypes.explicit(SqlTypeName.VARBINARY)
- .andThen(SqlTypeTransforms.TO_NULLABLE),
+ ReturnTypes.VARBINARY_NULLABLE,
OperandTypes.STRING, SqlFunctionCategory.STRING);
@LibraryOperator(libraries = {BIG_QUERY})
public static final SqlFunction TO_BASE32 =
SqlBasicFunction.create("TO_BASE32",
- ReturnTypes.explicit(SqlTypeName.VARCHAR)
- .andThen(SqlTypeTransforms.TO_NULLABLE),
+ ReturnTypes.VARCHAR_NULLABLE,
OperandTypes.STRING.or(OperandTypes.BINARY),
SqlFunctionCategory.STRING);
diff --git a/core/src/main/java/org/apache/calcite/sql/type/ReturnTypes.java b/core/src/main/java/org/apache/calcite/sql/type/ReturnTypes.java
index 5b9d7aa73c..e10107f28b 100644
--- a/core/src/main/java/org/apache/calcite/sql/type/ReturnTypes.java
+++ b/core/src/main/java/org/apache/calcite/sql/type/ReturnTypes.java
@@ -481,6 +481,19 @@ public abstract class ReturnTypes {
public static final SqlReturnTypeInference VARCHAR_NULLABLE =
VARCHAR.andThen(SqlTypeTransforms.TO_NULLABLE);
+ /**
+ * Type-inference strategy that always returns "VARBINARY".
+ */
+ public static final SqlReturnTypeInference VARBINARY =
+ ReturnTypes.explicit(SqlTypeName.VARBINARY);
+
+ /**
+ * Type-inference strategy that always returns "VARBINARY" with nulls
+ * allowed if any of the operands allow nulls.
+ */
+ public static final SqlReturnTypeInference VARBINARY_NULLABLE =
+ VARBINARY.andThen(SqlTypeTransforms.TO_NULLABLE);
+
/**
* Type-inference strategy for Histogram agg support.
*/