Creates group size hints from extracted `SELECT` `OPTIONS` validating that either the old `EXPECTED GROUP SIZE` syntax was used or alternatively the new syntax with `AGGREGATE INPUT GROUP SIZE`, `DISTINCT ON INPUT GROUP SIZE`, and `LIMIT INPUT GROUP SIZE`. If the two syntax versions are mixed in the same `OPTIONS` clause, an error is returned.[^1] [^1]: <https://github.com/MaterializeInc/materiali
(select_option_extracted: SelectOptionExtracted)
| 92 | /// same `OPTIONS` clause, an error is returned.[^1] |
| 93 | /// [^1]: <https://github.com/MaterializeInc/materialize/blob/main/doc/developer/design/20230829_topk_size_hint.md> |
| 94 | fn try_from(select_option_extracted: SelectOptionExtracted) -> Result<Self, Self::Error> { |
| 95 | let SelectOptionExtracted { |
| 96 | expected_group_size, |
| 97 | aggregate_input_group_size, |
| 98 | distinct_on_input_group_size, |
| 99 | limit_input_group_size, |
| 100 | .. |
| 101 | } = select_option_extracted; |
| 102 | if expected_group_size.is_some() |
| 103 | && (aggregate_input_group_size.is_some() |
| 104 | || distinct_on_input_group_size.is_some() |
| 105 | || limit_input_group_size.is_some()) |
| 106 | { |
| 107 | Err(PlanError::InvalidGroupSizeHints) |
| 108 | } else { |
| 109 | let aggregate_input_group_size = aggregate_input_group_size.or(expected_group_size); |
| 110 | let distinct_on_input_group_size = distinct_on_input_group_size.or(expected_group_size); |
| 111 | let limit_input_group_size = limit_input_group_size.or(expected_group_size); |
| 112 | Ok(GroupSizeHints { |
| 113 | aggregate_input_group_size, |
| 114 | distinct_on_input_group_size, |
| 115 | limit_input_group_size, |
| 116 | }) |
| 117 | } |
| 118 | } |
| 119 | } |