Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,8 @@ public static LocalDateTime getTime(DateTimeFormatter formatter, String value) {
TemporalAccessor accessor = formatter.parse(value);
return LocalDateTime.of(
getOrDefault(accessor, ChronoField.YEAR),
getOrDefault(accessor, ChronoField.MONTH_OF_YEAR),
getOrDefault(accessor, ChronoField.DAY_OF_MONTH),
getMonthOrDefault(accessor),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By changing this, you actually changed the function str_to_date's behaviour of FE. you should add some regression cases to make sure the behaviour is same of BE and FE. could use qt_sql and testFoldConst in reg.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

getDayOrDefault(accessor),
getHourOrDefault(accessor),
getOrDefault(accessor, ChronoField.MINUTE_OF_HOUR),
getOrDefault(accessor, ChronoField.SECOND_OF_MINUTE),
Expand All @@ -382,6 +382,28 @@ public static int getOrDefault(final TemporalAccessor accessor, final ChronoFiel
return accessor.isSupported(field) ? accessor.get(field) : /* default value */ 0;
}

/**
* get month from accessor, if not support day field, return 1
*/
public static int getMonthOrDefault(final TemporalAccessor accessor) {
if (accessor.isSupported(ChronoField.MONTH_OF_YEAR)) {
return accessor.get(ChronoField.MONTH_OF_YEAR);
} else {
return 1;
}
}

/**
* get day from accessor, if not support day field, return 1
*/
public static int getDayOrDefault(final TemporalAccessor accessor) {
if (accessor.isSupported(ChronoField.DAY_OF_MONTH)) {
return accessor.get(ChronoField.DAY_OF_MONTH);
} else {
return 1;
}
}

/**
* get hour from accessor, if not support hour field, return 0
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,13 @@ public void testGetExprTimeSec() throws AnalysisException {
expr = new DateLiteral(Type.DATE, true);
exprTimeSec = MTMVUtil.getExprTimeSec(expr, Optional.empty());
Assert.assertEquals(253402185600L, exprTimeSec);

expr = new StringLiteral("202001");
exprTimeSec = MTMVUtil.getExprTimeSec(expr, Optional.of("%Y%m"));
Assert.assertEquals(1577808000L, exprTimeSec);

expr = new StringLiteral("2020");
exprTimeSec = MTMVUtil.getExprTimeSec(expr, Optional.of("%Y"));
Assert.assertEquals(1577808000L, exprTimeSec);
}
}
12 changes: 12 additions & 0 deletions regression-test/data/correctness/test_str_to_date.out
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
-- !const_test4 --
\N

-- !const_test5 --
0000-01-01T09:30:17

-- !const_test6 --
0000-01-01T09:30:17

-- !short_1 --
2023-01-01

Expand All @@ -31,6 +37,12 @@
-- !short_4 --
\N

-- !short_5 --
2025-01-01

-- !short_6 --
2025-03-01

-- !select_from_table2 --
1 2019-12-01T00:00
2 2020-12-03T00:00
Expand Down
3 changes: 3 additions & 0 deletions regression-test/data/mtmv_p0/test_limit_partition_mtmv.out
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@
1 2038-01-02
2 2020-01-02

-- !date_with_month --
13 203801

17 changes: 9 additions & 8 deletions regression-test/suites/correctness/test_str_to_date.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,20 @@ suite("test_str_to_date") {
exception "is invalid"
}

test {
sql "SELECT /*+SET_VAR(debug_skip_fold_constant=false) */STR_TO_DATE('09:30:17', '%h:%i:%s');"
exception "is invalid"
}
test {
sql "SELECT /*+SET_VAR(debug_skip_fold_constant=true) */STR_TO_DATE('09:30:17', '%h:%i:%s');"
exception "is invalid"
}
qt_const_test5 """
SELECT /*+SET_VAR(debug_skip_fold_constant=false) */STR_TO_DATE('09:30:17', '%h:%i:%s');
"""

qt_const_test6 """
SELECT /*+SET_VAR(debug_skip_fold_constant=false) */STR_TO_DATE('09:30:17', '%h:%i:%s');
"""

qt_short_1 " select STR_TO_DATE('2023', '%Y') "
qt_short_2 " select STR_TO_DATE(null, '%Y') "
qt_short_3 " select STR_TO_DATE('2023', null) "
qt_short_4 " select STR_TO_DATE(null, null) "
qt_short_5 " select STR_TO_DATE('202501', '%Y%m') "
qt_short_6 " select STR_TO_DATE('202503', '%Y%m') "

test {
sql """
Expand Down
48 changes: 48 additions & 0 deletions regression-test/suites/mtmv_p0/test_limit_partition_mtmv.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,52 @@ suite("test_limit_partition_mtmv") {
assertTrue(showPartitionsResult.toString().contains("p_20380101_20380103"))
assertTrue(showPartitionsResult.toString().contains("p_20200101_20200103"))
order_qt_date_range_all "SELECT * FROM ${mvName} order by k1,k2"

// with month format
sql """drop table if exists `${tableName}`"""
sql """drop materialized view if exists ${mvName};"""
sql """
CREATE TABLE `${tableName}` (
id BIGINT,
dt CHAR(6)
)
DUPLICATE KEY(id)
PARTITION BY LIST(dt)
(
PARTITION p202511 VALUES IN ("202311"),
PARTITION p202512 VALUES IN ("202312"),
PARTITION p203801 VALUES IN ("203801")
)
DISTRIBUTED BY HASH(id) BUCKETS 2
PROPERTIES ("replication_num" = "1");
"""
sql """
insert into ${tableName} values(11,"202311"),(12,"202312"),(13,"203801");
"""

sql """
CREATE MATERIALIZED VIEW ${mvName}
BUILD DEFERRED REFRESH AUTO ON MANUAL
partition by(`dt`)
DISTRIBUTED BY RANDOM BUCKETS 2
PROPERTIES (
'replication_num' = '1',
'partition_sync_limit'='2',
'partition_sync_time_unit'='MONTH',
'partition_date_format'='%Y%m'
)
AS
SELECT * FROM ${tableName};
"""
sql """
REFRESH MATERIALIZED VIEW ${mvName} AUTO
"""
jobName = getJobName(dbName, mvName);
log.info(jobName)
waitingMTMVTaskFinished(jobName)
showPartitionsResult = sql """show partitions from ${mvName}"""
logger.info("showPartitionsResult: " + showPartitionsResult.toString())
assertEquals(1, showPartitionsResult.size())
assertTrue(showPartitionsResult.toString().contains("p_203801"))
order_qt_date_with_month "SELECT * FROM ${mvName} order by dt"
}
Loading