(insert, re_match, can_hint, params)
| 549 | |
| 550 | |
| 551 | def build_partitioned_load(insert, re_match, can_hint, params): |
| 552 | part_col = re_match.group(1) |
| 553 | min_val = int(re_match.group(2)) |
| 554 | max_val = int(re_match.group(3)) |
| 555 | batch = int(re_match.group(4)) |
| 556 | insert = PARTITIONED_INSERT_RE.sub("", insert) |
| 557 | statements = [] |
| 558 | params[VAR_HINT] = HINT_SHUFFLE if can_hint else '' |
| 559 | first_part = min_val |
| 560 | while first_part < max_val: |
| 561 | if first_part + batch >= max_val: |
| 562 | # This is the last batch |
| 563 | if first_part == min_val: |
| 564 | # There is only 1 batch in this insert. No predicate needed. |
| 565 | params[VAR_PART_PREDICATE] = '' |
| 566 | else: |
| 567 | # Insert the remaining partitions + NULL partition |
| 568 | params[VAR_PART_PREDICATE] = "WHERE {0} <= {1} OR {2} IS NULL".format( |
| 569 | first_part, part_col, part_col) |
| 570 | elif first_part == min_val: |
| 571 | # This is the first batch. |
| 572 | params[VAR_PART_PREDICATE] = "WHERE {0} < {1}".format( |
| 573 | part_col, first_part + batch) |
| 574 | else: |
| 575 | # This is the middle batch. |
| 576 | params[VAR_PART_PREDICATE] = "WHERE {0} <= {1} AND {2} < {3}".format( |
| 577 | first_part, part_col, part_col, first_part + batch) |
| 578 | statements.append(insert.format(**params)) |
| 579 | first_part += batch |
| 580 | return "\n".join(statements) |
| 581 | |
| 582 | |
| 583 | def build_insert_into_statement(insert, db_name, db_suffix, table_name, file_format, |
no test coverage detected