Skip to content

Commit

Permalink
[Enhancement] Support partition by minute granularity time_slice (#52996
Browse files Browse the repository at this point in the history
)

Signed-off-by: meegoo <[email protected]>
  • Loading branch information
meegoo authored Nov 20, 2024
1 parent c68222c commit 9c0d29f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public class AnalyzerUtils {
ImmutableSet.of("hour", "day", "month", "year");
// The partition format supported by time_slice
public static final Set<String> TIME_SLICE_SUPPORTED_PARTITION_FORMAT =
ImmutableSet.of("hour", "day", "month", "year");
ImmutableSet.of("minute", "hour", "day", "month", "year");
// The partition format supported by mv date_trunc
public static final Set<String> MV_DATE_TRUNC_SUPPORTED_PARTITION_FORMAT =
ImmutableSet.of("hour", "day", "week", "month", "year");
Expand Down Expand Up @@ -1426,6 +1426,11 @@ private static AddPartitionClause getAddPartitionClauseForRangePartition(
// The start date here is passed by BE through function calculation,
// so it must be the start date of a certain partition.
switch (granularity.toLowerCase()) {
case "minute":
beginTime = beginTime.withSecond(0).withNano(0);
partitionName = partitionPrefix + beginTime.format(DateUtils.MINUTE_FORMATTER_UNIX);
endTime = beginTime.plusMinutes(interval);
break;
case "hour":
beginTime = beginTime.withMinute(0).withSecond(0).withNano(0);
partitionName = partitionPrefix + beginTime.format(DateUtils.HOUR_FORMATTER_UNIX);
Expand Down Expand Up @@ -1760,14 +1765,14 @@ public static List<String> checkAndExtractPartitionCol(FunctionCallExpr expr, Li
private static void checkPartitionColumnTypeValid(FunctionCallExpr expr, List<ColumnDef> columnDefs,
NodePosition pos, String partitionColumnName, String fmt) {
// For materialized views currently columnDefs == null
if (columnDefs != null && "hour".equalsIgnoreCase(fmt)) {
if (columnDefs != null && ("hour".equalsIgnoreCase(fmt) || "minute".equalsIgnoreCase(fmt))) {
ColumnDef partitionDef = findPartitionDefByName(columnDefs, partitionColumnName);
if (partitionDef == null) {
throw new ParsingException(PARSER_ERROR_MSG.unsupportedExprWithInfo(expr.toSql(), "PARTITION BY"), pos);
}
if (partitionDef.getType() != Type.DATETIME) {
throw new ParsingException(PARSER_ERROR_MSG.unsupportedExprWithInfoAndExplain(expr.toSql(),
"PARTITION BY", "The hour parameter only supports datetime type"), pos);
"PARTITION BY", "The hour/minute parameter only supports datetime type"), pos);
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions test/sql/test_automatic_partition/R/test_automatic_partition
Original file line number Diff line number Diff line change
Expand Up @@ -639,3 +639,15 @@ select * from ss;
2002-01-07 1 2
2002-01-06 1 2
-- !result

-- name: test_time_slice_with_minute_granularity
create table tt(k datetime) partition by time_slice(k, interval 10 minute);
-- result:
-- !result
insert into tt values(now());
-- result:
-- !result
select count(*) from tt;
-- result:
1
-- !result
6 changes: 6 additions & 0 deletions test/sql/test_automatic_partition/T/test_automatic_partition
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,9 @@ insert into ss values('2002-01-08', 1, 2);
select sleep(3);
function: wait_alter_table_not_pending()
select * from ss;


-- name: test_time_slice_with_minute_granularity
create table tt(k datetime) partition by time_slice(k, interval 10 minute);
insert into tt values(now());
select count(*) from tt;

0 comments on commit 9c0d29f

Please sign in to comment.