# orca.partitions

> A module of Orca's API.

Partition sets: which keys a pipeline is partitioned by, from when.

```mojo
comptime Taxi = Pipeline[
    "taxi", Download, Load, Compact, partitions=Monthly["2011-01"]
]
comptime Weather = Pipeline["weather", Fetch, partitions=Daily["2020-01-01"]]
comptime Labels = Pipeline["labels", Label, partitions=Keyed["av2.logs", "log_id"]]
```

A pipeline's first step takes its key (`Month` for `Monthly`, `Day` for
`Daily`, `Name` for `orca.keyed.Keyed`), or a `Seq` of them for a first
gather step. `start` is the first partition: keys before it are refused,
and phase 2's scheduler and backfills count from it. A pipeline without
`partitions=` is `Monthly[]`, with no start.

Each set reads `--partitions` itself (`parse`): time keys take keys and
ranges, keyed partitions lists of names. Only time keys have a calendar, so
only they `fill` a schedule's partition, and only keyed partitions have
current `keys`, read from their dataset.

## Structs

### `Monthly`

```mojo
struct Monthly[first: StringSpan[ImmStaticOrigin] = StringSpan("")]
```

A partition per month, from `first` (`YYYY-MM`) if given.

Implements: `Movable`, `Partitions`

#### `K`

```mojo
comptime K = Month
```

#### `kind`

```mojo
def kind() -> StaticString
```

#### `start`

```mojo
def start() -> StaticString
```

#### `dataset`

```mojo
def dataset() -> StaticString
```

#### `column`

```mojo
def column() -> StaticString
```

#### `parse`

```mojo
def parse(s: StringSpan, check: Bool) -> List[Month]
```

#### `fill`

```mojo
def fill(year: Int, month: Int, day: Int, previous: Bool) -> Month
```

#### `keys`

```mojo
def keys() -> Tuple[Int64, List[String]]
```

### `Daily`

```mojo
struct Daily[first: StringSpan[ImmStaticOrigin] = StringSpan("")]
```

A partition per day, from `first` (`YYYY-MM-DD`) if given.

Implements: `Movable`, `Partitions`

#### `K`

```mojo
comptime K = Day
```

#### `kind`

```mojo
def kind() -> StaticString
```

#### `start`

```mojo
def start() -> StaticString
```

#### `dataset`

```mojo
def dataset() -> StaticString
```

#### `column`

```mojo
def column() -> StaticString
```

#### `parse`

```mojo
def parse(s: StringSpan, check: Bool) -> List[Day]
```

#### `fill`

```mojo
def fill(year: Int, month: Int, day: Int, previous: Bool) -> Day
```

#### `keys`

```mojo
def keys() -> Tuple[Int64, List[String]]
```

## Traits

### `Partitions`

```mojo
undefined
```

#### `K`

The partition key.

#### `kind`

```mojo
def kind() -> StaticString
```

`monthly`, `daily` or `keyed`, as `describe` writes it.

#### `start`

```mojo
def start() -> StaticString
```

The first partition, as text; empty for none.

#### `dataset`

```mojo
def dataset() -> StaticString
```

The dataset keyed partitions' keys come from; empty for time.

#### `column`

```mojo
def column() -> StaticString
```

#### `parse`

```mojo
def parse(s: StringSpan, check: Bool) -> List[Self.K]
```

The keys `s` names, as `run --partitions` takes them. With `check`, keyed partitions refuse a name their dataset doesn't have now; a resume doesn't check, as the run's keys were checked when it was made.

#### `fill`

```mojo
def fill(year: Int, month: Int, day: Int, previous: Bool) -> Self.K
```

The key a date falls in, or the one before it; raises for keys that aren't dates.

#### `keys`

```mojo
def keys() -> Tuple[Int64, List[String]]
```

The keys dataset's current snapshot and its keys, sorted; raises for time keys.

## Functions

### `parse_partitions`

```mojo
def parse_partitions[P: Partitions](s: StringSpan) -> List[P.K]
```

The keys of `P` that `s` names, as `run --partitions` takes them: for time keys a key, `A..B`, or a comma-separated list of either; for keyed partitions a list of names, `@all` or `@file:<path>`.
