statement execution chooser. this also returns a list of shard ids, which can just be all of them. but here we'll search into the execution context in order to try to narrow down the list of shards to SELECT.
(context)
| 165 | |
| 166 | |
| 167 | def execute_chooser(context): |
| 168 | """statement execution chooser. |
| 169 | |
| 170 | this also returns a list of shard ids, which can just be all of them. but |
| 171 | here we'll search into the execution context in order to try to narrow down |
| 172 | the list of shards to SELECT. |
| 173 | |
| 174 | """ |
| 175 | ids = [] |
| 176 | |
| 177 | # we'll grab continent names as we find them |
| 178 | # and convert to shard ids |
| 179 | for column, operator, value in _get_select_comparisons(context.statement): |
| 180 | # "shares_lineage()" returns True if both columns refer to the same |
| 181 | # statement column, adjusting for any annotations present. |
| 182 | # (an annotation is an internal clone of a Column object |
| 183 | # and occur when using ORM-mapped attributes like |
| 184 | # "WeatherLocation.continent"). A simpler comparison, though less |
| 185 | # accurate, would be "column.key == 'continent'". |
| 186 | if column.shares_lineage(WeatherLocation.__table__.c.continent): |
| 187 | if operator == operators.eq: |
| 188 | ids.append(shard_lookup[value]) |
| 189 | elif operator == operators.in_op: |
| 190 | ids.extend(shard_lookup[v] for v in value) |
| 191 | |
| 192 | if len(ids) == 0: |
| 193 | return ["north_america", "asia", "europe", "south_america"] |
| 194 | else: |
| 195 | return ids |
| 196 | |
| 197 | |
| 198 | def _get_select_comparisons(statement): |
nothing calls this directly
no test coverage detected