About time range partitioning, the documentation s...
# questions-and-troubleshooting
m
About time range partitioning, the documentation states that:
week partition granularity is not supported.
(link: https://docs.starrocks.io/docs/4.0/table_design/data_distribution/expression_partitioning/) But it seems to be working nonetheless? or at least failing silently, which would not be good. I have the following table which seems to be working just fine:
Copy code
CREATE TABLE IF NOT EXISTS sessions.timeseries_data (
    project_id                                  BIGINT,
    version_id                                  BIGINT,
    user_key_hash                               BIGINT,
    datum_timestamp                             DATETIME,
    ... bunch of columns ...
    -- Generated partition column: week boundary
    datum_week                                  DATE AS DATE(date_trunc('week', datum_timestamp))
)
PRIMARY KEY(project_id, version_id, user_key_hash, datum_timestamp)
PARTITION BY datum_week
DISTRIBUTED BY HASH(user_key_hash) BUCKETS 8
PROPERTIES (
   "colocate_with" = "userkey_join_group",
   "partition_retention_condition" = "datum_week >= CURRENT_DATE() - INTERVAL 105 DAY",
);
is this a case of documentation being out of date or is it a real limitation and I shouldn't use it?
as a test, I also tried a simpler table which seems to work just as fine:
Copy code
CREATE TABLE IF NOT EXISTS sessions.timeseries_data (
    project_id                                  BIGINT,
    version_id                                  BIGINT,
    user_key_hash                               BIGINT,
    datum_timestamp                             DATETIME,
    ... bunch of columns ...
)
PRIMARY KEY(project_id, version_id, user_key_hash, datum_timestamp)
PARTITION BY date_trunc('week', datum_timestamp)
DISTRIBUTED BY HASH(user_key_hash) BUCKETS 8
b
@Rocky About time range partitioning, the documentation states that:
week partition granularity is not supported.
(link: https://docs.starrocks.io/docs/4.0/table_design/data_distribution/expression_partitioning/) But it seems to be working nonetheless? or at least failing silently, which would not be good. I have the following table which seems to be working just fine:
r
Hi there! I'm Rocky. It's great to see you're diving deep into StarRocks partitioning! You've hit on a slightly confusing point in our current documentation. To clarify the situation regarding week granularity in expression partitioning: 1. The documentation constraint: You're correct that the documentation for Expression Partitioning (using
date_trunc
or
time_slice
) often states that
week
is not supported as a direct
time_unit
parameter. 2. Why it "works": StarRocks has been evolving quickly. While
date_trunc('week', ...)
might not have been officially "validated" or optimized for all automated partition management features (like
partition_live_number
or certain dynamic behaviors) in earlier versions, the underlying engine often handles the function call just fine because
date_trunc
itself supports 'week'. 3. The Recommended Way for Weekly Partitions: As shown in the examples in our documentation, the officially supported way to achieve weekly partitioning is by using `time_slice`:
Copy code
sql
    PARTITION BY time_slice(column_name, INTERVAL 7 day)
This creates partitions with a 7-day range, which effectively gives you the weekly granularity you're looking for and is fully supported by the system's partition management. Is it safe to use? If your table DDL with
date_trunc('week', ...)
or similar is working, it's likely because the system is treating it as a generic expression partition. However, to ensure full compatibility with all partition management features (like automatic cleanup via TTL) and to follow the "golden path" of the product, we recommend using the
time_slice(..., INTERVAL 7 day)
approach mentioned above. I'll make sure to pass this feedback to our documentation team to clear up the "week not supported" vs "Example 3" contradiction! If you can share the specific DDL you used, I can double-check if there are any subtle edge cases you should be aware of. Referencestable_design/data_distribution/expression_partitioning.md
b
"week" are not be included in the
time_unit
because a "month" does not necessarily align with full weeks.
m
@biying gao this was answered at github: https://github.com/StarRocks/starrocks/issues/70082
week
is supported, it was just the documentation that was outdated
b
Gotcha, thanks for the update!