Sign in to run and submit your work
Reading is open to everyone. Running code and saving drafts need an account so your work is yours and comes back on your next visit.
or
CODE WORKSPACE
Events land in object storage under partition folders — year=2026/month=03/day=02 — and the query engine prunes on those folder names. Which folder a row goes in is decided from its timestamp, and the producers send timestamps with a Z suffix, with a numeric offset, and sometimes with no zone at all.
Write partition_path(table, timestamp, granularity). Return the path, or None when there is not one.
Function to write
partition_path(table: str, timestamp: str, granularity: str) -> str | NoneThe partition path as a slash-joined string, or None when the inputs do not describe one.
How to approach it
Convert to UTC first, then read the parts. Never slice the raw string.
Sample cases
+ 2 held back until you submit
an offset that changes the day
Half past one in India is the previous evening in UTC, so the day segment changes.
Input
Argument 1
'events'Argument 2
'2026-03-02T01:30:00+05:30'Argument 3
'day'Returns
'events/year=2026/month=03/day=01'hourly granularity
An hour partition carries four segments and the minutes are discarded, not rounded.
Input
Argument 1
'events'Argument 2
'2026-03-02T09:07:41Z'Argument 3
'hour'Returns
'events/year=2026/month=03/day=02/hour=09'a timestamp with no zone
A naive timestamp is already UTC, and the trailing slash on the table is not doubled.
Input
Argument 1
'orders/'Argument 2
'2026-01-05T23:00:00'Argument 3
'month'Returns
'orders/year=2026/month=01'a timestamp that is not one
An empty timestamp has no partition, so the answer is None rather than a broken path.
Input
Argument 1
'events'Argument 2
''Argument 3
'day'Returns
None
Constraints
granularity is month, day or hour, and decides how many segments the path has: year and month, plus day, plus hour.month=03, not month=3 — so paths sort in the same order as the timestamps they came from.hour=09.None when the timestamp cannot be parsed, the granularity is unknown, or the table name is missing — never a partly built path.Worked example
2026-03-02T01:30:00+05:30 is half past one in the morning in India, which is 20:00 on the first of March in UTC. The row belongs in day=01, not day=02. Slicing the first ten characters off the string — which is what almost every first attempt does — files it under the second, and the day's numbers are wrong at both ends by however many events crossed the boundary.
The zero-padding rule looks cosmetic and is not. Partition folders are compared as text by every engine that lists them, so month=3 sorts after month=12 and a range scan quietly reads the wrong set of folders.
What this tests
That a partition is a decision about an instant, not about the characters somebody wrote it in. Timezone conversion before truncation is the whole exercise, and it is the single most common cause of rows landing in the wrong day.
partition_path(table: str, timestamp: str, granularity: str) -> str | NoneSubmit for review to find out what your query gets right, what it gets wrong, and how it compares with the best working query for this exercise.
This scenario runs a full workspace — editor, canvas and results side by side. It needs a laptop or desktop to be usable. Open this page on a bigger screen to start building.