Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[enhance](mtmv)mtmv date trunc support hour #37678

Merged
merged 6 commits into from
Jul 19, 2024
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");
private static Set<String> timeUnits = ImmutableSet.of("year", "month", "day", "hour");
private String timeUnit;

public MTMVPartitionExprDateTrunc(FunctionCallExpr functionCallExpr) throws AnalysisException {
Expand Down Expand Up @@ -202,6 +202,9 @@ private DateTimeV2Literal dateIncrement(DateTimeV2Literal value) throws Analysis
case "day":
result = value.plusDays(1L);
break;
case "hour":
result = value.plusHours(1L);
break;
default:
throw new AnalysisException(
"async materialized view partition roll up not support timeUnit: " + timeUnit);
Expand Down
39 changes: 28 additions & 11 deletions regression-test/suites/mtmv_p0/test_rollup_partition_mtmv.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -661,21 +661,21 @@ suite("test_rollup_partition_mtmv") {
log.info(e.getMessage())
}

// not support trunc hour
// not support trunc minute
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 '\"数据灌入日期时间\"'
`k2` DATETIME 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_20200201 VALUES [("2020-02-01"),("2020-02-02"))
PARTITION p_1 VALUES [("2020-01-01 00:00:00"),("2020-01-01 00:30:00")),
PARTITION p_2 VALUES [("2020-01-01 00:30:00"),("2020-01-01 01:00:00")),
PARTITION p_3 VALUES [("2020-01-01 01:00:00"),("2020-01-01 01:30:00"))
)
DISTRIBUTED BY HASH(`k1`) BUCKETS 2
PROPERTIES ('replication_num' = '1') ;
Expand All @@ -685,7 +685,7 @@ suite("test_rollup_partition_mtmv") {
sql """
CREATE MATERIALIZED VIEW ${mvName}
BUILD DEFERRED REFRESH AUTO ON MANUAL
partition by (date_trunc(`k2`,'hour'))
partition by (date_trunc(`k2`,'minute'))
DISTRIBUTED BY RANDOM BUCKETS 2
PROPERTIES (
'replication_num' = '1'
Expand All @@ -698,31 +698,48 @@ suite("test_rollup_partition_mtmv") {
log.info(e.getMessage())
}

// support hour
sql """
CREATE MATERIALIZED VIEW ${mvName}
BUILD DEFERRED REFRESH AUTO ON MANUAL
partition by (date_trunc(`k2`,'hour'))
DISTRIBUTED BY RANDOM BUCKETS 2
PROPERTIES (
'replication_num' = '1'
)
AS
SELECT * FROM ${tableName};
"""

def hour_partitions = sql """show partitions from ${mvName}"""
logger.info("hour_partitions: " + hour_partitions.toString())
assertEquals(2, hour_partitions.size())

sql """drop materialized view if exists ${mvName};"""
try {
sql """
CREATE MATERIALIZED VIEW ${mvName}
BUILD DEFERRED REFRESH AUTO ON MANUAL
partition by (hour_alias)
partition by (minute_alias)
DISTRIBUTED BY RANDOM BUCKETS 2
PROPERTIES (
'replication_num' = '1'
)
AS
SELECT date_trunc(`k2`,'hour') as hour_alias, * FROM ${tableName};
SELECT date_trunc(`k2`,'minute') as minute_alias, * FROM ${tableName};
"""
Assert.fail();
} catch (Exception e) {
log.info(e.getMessage())
assertTrue(e.getMessage().contains("timeUnit not support: hour"))
assertTrue(e.getMessage().contains("timeUnit not support: minute"))
}

sql """drop materialized view if exists ${mvName};"""
try {
sql """
CREATE MATERIALIZED VIEW ${mvName}
BUILD IMMEDIATE REFRESH AUTO ON MANUAL
partition by (date_trunc(minute_alias, 'hour'))
partition by (date_trunc(minute_alias, 'minute'))
DISTRIBUTED BY RANDOM BUCKETS 2
PROPERTIES (
'replication_num' = '1'
Expand All @@ -733,6 +750,6 @@ suite("test_rollup_partition_mtmv") {
Assert.fail();
} catch (Exception e) {
log.info(e.getMessage())
assertTrue(e.getMessage().contains("timeUnit not support: hour"))
assertTrue(e.getMessage().contains("timeUnit not support: minute"))
}
}
Loading