This is an automated email from the ASF dual-hosted git repository.
huajianlan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new d592e279c10 [fix](sql_cache) fix sql cache result wrong of
from_unixtime(col, 'yyyy-MM-dd HH:mm:ss') (#44631)
d592e279c10 is described below
commit d592e279c1058de37994135a4cc20fd35698a9c1
Author: 924060929 <[email protected]>
AuthorDate: Wed Nov 27 12:18:56 2024 +0800
[fix](sql_cache) fix sql cache result wrong of from_unixtime(col,
'yyyy-MM-dd HH:mm:ss') (#44631)
fix sql cache result wrong of from_unixtime(col, 'yyyy-MM-dd HH:mm:ss')
which introduced by #33262
the wrong result: is `yyyy-MM-dd HH:mm:ss`
---
.../nereids/rules/expression/rules/SupportJavaDateFormatter.java | 3 ++-
.../functions/executable/DateTimeExtractAndTransform.java | 9 +++++++++
.../src/main/java/org/apache/doris/qe/SessionVariable.java | 2 +-
.../suites/nereids_p0/cache/parse_sql_from_sql_cache.groovy | 7 +++++++
4 files changed, 19 insertions(+), 2 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/SupportJavaDateFormatter.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/SupportJavaDateFormatter.java
index 27b929a2b9f..f5b442a3989 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/SupportJavaDateFormatter.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/SupportJavaDateFormatter.java
@@ -76,7 +76,8 @@ public class SupportJavaDateFormatter implements
ExpressionPatternRuleFactory {
return function;
}
- private static Expression translateJavaFormatter(Expression formatterExpr)
{
+ /** translateJavaFormatter */
+ public static Expression translateJavaFormatter(Expression formatterExpr) {
if (formatterExpr.isLiteral() &&
formatterExpr.getDataType().isStringLikeType()) {
Literal literal = (Literal) formatterExpr;
String originFormatter = literal.getStringValue();
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/DateTimeExtractAndTransform.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/DateTimeExtractAndTransform.java
index 440f93cac59..c9082715318 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/DateTimeExtractAndTransform.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/DateTimeExtractAndTransform.java
@@ -20,6 +20,7 @@ package
org.apache.doris.nereids.trees.expressions.functions.executable;
import org.apache.doris.catalog.ScalarType;
import org.apache.doris.catalog.Type;
import org.apache.doris.nereids.exceptions.AnalysisException;
+import
org.apache.doris.nereids.rules.expression.rules.SupportJavaDateFormatter;
import org.apache.doris.nereids.trees.expressions.ExecFunction;
import org.apache.doris.nereids.trees.expressions.Expression;
import org.apache.doris.nereids.trees.expressions.literal.BigIntLiteral;
@@ -293,12 +294,14 @@ public class DateTimeExtractAndTransform {
*/
@ExecFunction(name = "date_format")
public static Expression dateFormat(DateLiteral date, StringLikeLiteral
format) {
+ format = (StringLikeLiteral)
SupportJavaDateFormatter.translateJavaFormatter(format);
return new
VarcharLiteral(DateUtils.formatBuilder(format.getValue()).toFormatter().format(
java.time.LocalDate.of(((int) date.getYear()), ((int)
date.getMonth()), ((int) date.getDay()))));
}
@ExecFunction(name = "date_format")
public static Expression dateFormat(DateTimeLiteral date,
StringLikeLiteral format) {
+ format = (StringLikeLiteral)
SupportJavaDateFormatter.translateJavaFormatter(format);
return new
VarcharLiteral(DateUtils.formatBuilder(format.getValue()).toFormatter().format(
java.time.LocalDateTime.of(((int) date.getYear()), ((int)
date.getMonth()), ((int) date.getDay()),
((int) date.getHour()), ((int) date.getMinute()),
((int) date.getSecond()))));
@@ -306,12 +309,14 @@ public class DateTimeExtractAndTransform {
@ExecFunction(name = "date_format")
public static Expression dateFormat(DateV2Literal date, StringLikeLiteral
format) {
+ format = (StringLikeLiteral)
SupportJavaDateFormatter.translateJavaFormatter(format);
return new
VarcharLiteral(DateUtils.formatBuilder(format.getValue()).toFormatter().format(
java.time.LocalDate.of(((int) date.getYear()), ((int)
date.getMonth()), ((int) date.getDay()))));
}
@ExecFunction(name = "date_format")
public static Expression dateFormat(DateTimeV2Literal date,
StringLikeLiteral format) {
+ format = (StringLikeLiteral)
SupportJavaDateFormatter.translateJavaFormatter(format);
return new
VarcharLiteral(DateUtils.formatBuilder(format.getValue()).toFormatter().format(
java.time.LocalDateTime.of(((int) date.getYear()), ((int)
date.getMonth()), ((int) date.getDay()),
((int) date.getHour()), ((int) date.getMinute()),
((int) date.getSecond()))));
@@ -479,6 +484,8 @@ public class DateTimeExtractAndTransform {
*/
@ExecFunction(name = "from_unixtime")
public static Expression fromUnixTime(BigIntLiteral second,
StringLikeLiteral format) {
+ format = (StringLikeLiteral)
SupportJavaDateFormatter.translateJavaFormatter(format);
+
// 32536771199L is max valid timestamp of mysql from_unix_time
if (second.getValue() < 0 || second.getValue() > 32536771199L) {
return new NullLiteral(VarcharType.SYSTEM_DEFAULT);
@@ -531,6 +538,7 @@ public class DateTimeExtractAndTransform {
*/
@ExecFunction(name = "unix_timestamp")
public static Expression unixTimestamp(StringLikeLiteral date,
StringLikeLiteral format) {
+ format = (StringLikeLiteral)
SupportJavaDateFormatter.translateJavaFormatter(format);
DateTimeFormatter formatter =
DateUtils.formatBuilder(format.getValue()).toFormatter();
LocalDateTime dateObj;
try {
@@ -616,6 +624,7 @@ public class DateTimeExtractAndTransform {
*/
@ExecFunction(name = "str_to_date")
public static Expression strToDate(StringLikeLiteral str,
StringLikeLiteral format) {
+ format = (StringLikeLiteral)
SupportJavaDateFormatter.translateJavaFormatter(format);
if
(org.apache.doris.analysis.DateLiteral.hasTimePart(format.getStringValue())) {
DataType returnType =
DataType.fromCatalogType(ScalarType.getDefaultDateType(Type.DATETIME));
if (returnType instanceof DateTimeV2Type) {
diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java
b/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java
index 2c09ee73f57..71b746c7907 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java
@@ -1011,7 +1011,7 @@ public class SessionVariable implements Serializable,
Writable {
@VariableMgr.VarAttr(name = ENABLE_ODBC_TRANSCATION)
public boolean enableOdbcTransaction = false;
- @VariableMgr.VarAttr(name = ENABLE_SQL_CACHE)
+ @VariableMgr.VarAttr(name = ENABLE_SQL_CACHE, fuzzy = true)
public boolean enableSqlCache = false;
@VariableMgr.VarAttr(name = ENABLE_QUERY_CACHE)
diff --git
a/regression-test/suites/nereids_p0/cache/parse_sql_from_sql_cache.groovy
b/regression-test/suites/nereids_p0/cache/parse_sql_from_sql_cache.groovy
index 6aeeeed0ead..54ab7028888 100644
--- a/regression-test/suites/nereids_p0/cache/parse_sql_from_sql_cache.groovy
+++ b/regression-test/suites/nereids_p0/cache/parse_sql_from_sql_cache.groovy
@@ -820,6 +820,13 @@ suite("parse_sql_from_sql_cache") {
assertTrue(profileString.contains("Is Cached: Yes"))
}
}
+ }),
+ extraThread("sql_cache_with_date_format", {
+ sql "set enable_sql_cache=true"
+ for (def i in 0..3) {
+ def result = sql "select FROM_UNIXTIME(UNIX_TIMESTAMP(),
'yyyy-MM-dd HH:mm:ss')"
+ assertNotEquals("yyyy-MM-dd HH:mm:ss", result[0][0])
+ }
})
).get()
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]