Skip to content
Merged
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 @@ -47,7 +47,7 @@
import java.util.Set;

public class MTMVPartitionExprDateTrunc implements MTMVPartitionExprService {
private static Set<String> timeUnits = ImmutableSet.of("year", "month", "day", "hour");
private static Set<String> timeUnits = ImmutableSet.of("year", "quarter", "week", "month", "day", "hour");
private String timeUnit;

public MTMVPartitionExprDateTrunc(FunctionCallExpr functionCallExpr) throws AnalysisException {
Expand Down Expand Up @@ -198,9 +198,15 @@ private DateTimeV2Literal dateIncrement(DateTimeV2Literal value) throws Analysis
case "year":
result = value.plusYears(1L);
break;
case "quarter":
result = value.plusMonths(3L);
Copy link
Contributor

Choose a reason for hiding this comment

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

why add 3 month, can add some comment to explain this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

1 quarter = 3month

Copy link
Contributor Author

Choose a reason for hiding this comment

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

value not have plusQuarter method,so use plusMonths(3L);

break;
case "month":
result = value.plusMonths(1L);
break;
case "week":
result = value.plusWeeks(1L);
break;
case "day":
result = value.plusDays(1L);
break;
Expand Down
10 changes: 10 additions & 0 deletions regression-test/data/mtmv_p0/test_rollup_partition_mtmv.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !date_range_quarter --
1 2020-01-01 2020-01-01
2 2020-04-01 2020-04-01
3 2020-02-01 2020-02-01

-- !date_range_week --
1 2020-01-01 2020-01-01
2 2020-01-02 2020-01-02
3 2020-01-08 2020-01-08

-- !date_range_month --
1 2020-01-01 2020-01-01
2 2020-01-02 2020-01-02
Expand Down
96 changes: 96 additions & 0 deletions regression-test/suites/mtmv_p0/test_rollup_partition_mtmv.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,102 @@ suite("test_rollup_partition_mtmv") {
exception "only support"
}

// quarter
sql """drop table if exists `${tableName}`"""
sql """drop materialized view if exists ${mvName};"""
sql """
CREATE TABLE `${tableName}` (
`k1` LARGEINT NOT NULL COMMENT '\"用户id\"',
`k2` DATE NOT NULL COMMENT '\"数据灌入日期时间\"',
`k3` DATE NOT NULL COMMENT '\"日期时间\"'
) ENGINE=OLAP
DUPLICATE KEY(`k1`)
COMMENT 'OLAP'
PARTITION BY range(`k2`)
(
PARTITION p_20200101 VALUES [("2020-01-01"),("2020-01-02")),
PARTITION p_20200401 VALUES [("2020-04-01"),("2020-04-02")),
PARTITION p_20200201 VALUES [("2020-02-01"),("2020-02-02"))
)
DISTRIBUTED BY HASH(`k1`) BUCKETS 2
PROPERTIES ('replication_num' = '1') ;
"""
sql """
insert into ${tableName} values(1,"2020-01-01", "2020-01-01"),(2,"2020-04-01", "2020-04-01"),(3,"2020-02-01", "2020-02-01");
"""

sql """
CREATE MATERIALIZED VIEW ${mvName}
BUILD DEFERRED REFRESH AUTO ON MANUAL
partition by (date_trunc(`k2`,'quarter'))
DISTRIBUTED BY RANDOM BUCKETS 2
PROPERTIES (
'replication_num' = '1'
)
AS
SELECT * FROM ${tableName};
"""
showPartitionsResult = sql """show partitions from ${mvName}"""
logger.info("showPartitionsResult: " + showPartitionsResult.toString())
assertEquals(2, showPartitionsResult.size())
assertTrue(showPartitionsResult.toString().contains("2020-01-01"))
assertTrue(showPartitionsResult.toString().contains("2020-04-01"))
assertTrue(showPartitionsResult.toString().contains("2020-07-01"))

sql """
REFRESH MATERIALIZED VIEW ${mvName} AUTO
"""
waitingMTMVTaskFinishedByMvName(mvName)
order_qt_date_range_quarter "SELECT * FROM ${mvName} order by k1,k2"

// week
sql """drop table if exists `${tableName}`"""
sql """drop materialized view if exists ${mvName};"""
sql """
CREATE TABLE `${tableName}` (
`k1` LARGEINT NOT NULL COMMENT '\"用户id\"',
`k2` DATE NOT NULL COMMENT '\"数据灌入日期时间\"',
`k3` DATE NOT NULL COMMENT '\"日期时间\"'
) ENGINE=OLAP
DUPLICATE KEY(`k1`)
COMMENT 'OLAP'
PARTITION BY range(`k2`)
(
PARTITION p_20200101 VALUES [("2020-01-01"),("2020-01-02")),
PARTITION p_20200102 VALUES [("2020-01-02"),("2020-01-03")),
PARTITION p_20200108 VALUES [("2020-01-08"),("2020-01-09"))
)
DISTRIBUTED BY HASH(`k1`) BUCKETS 2
PROPERTIES ('replication_num' = '1') ;
"""
sql """
insert into ${tableName} values(1,"2020-01-01", "2020-01-01"),(2,"2020-01-02", "2020-01-02"),(3,"2020-01-08", "2020-01-08");
"""

sql """
CREATE MATERIALIZED VIEW ${mvName}
BUILD DEFERRED REFRESH AUTO ON MANUAL
partition by (date_trunc(`k2`,'week'))
DISTRIBUTED BY RANDOM BUCKETS 2
PROPERTIES (
'replication_num' = '1'
)
AS
SELECT * FROM ${tableName};
"""
showPartitionsResult = sql """show partitions from ${mvName}"""
logger.info("showPartitionsResult: " + showPartitionsResult.toString())
assertEquals(2, showPartitionsResult.size())
assertTrue(showPartitionsResult.toString().contains("2019-12-30"))
assertTrue(showPartitionsResult.toString().contains("2020-01-06"))
assertTrue(showPartitionsResult.toString().contains("2020-01-13"))

sql """
REFRESH MATERIALIZED VIEW ${mvName} AUTO
"""
waitingMTMVTaskFinishedByMvName(mvName)
order_qt_date_range_week "SELECT * FROM ${mvName} order by k1,k2"

// range date month
sql """drop table if exists `${tableName}`"""
sql """drop materialized view if exists ${mvName};"""
Expand Down