(insert, db_name, db_suffix, table_name, file_format,
hdfs_path, for_impala=False, scale_factor="")
| 581 | |
| 582 | |
| 583 | def build_insert_into_statement(insert, db_name, db_suffix, table_name, file_format, |
| 584 | hdfs_path, for_impala=False, scale_factor=""): |
| 585 | can_hint = for_impala and (file_format == 'parquet' or is_iceberg_table(file_format)) |
| 586 | params = build_replacement_params( |
| 587 | db_name, |
| 588 | db_suffix, |
| 589 | table_name, |
| 590 | hdfs_location=hdfs_path, |
| 591 | impala_home=IMPALA_HOME, |
| 592 | hint="", |
| 593 | part_predicate="", |
| 594 | scale_factor=scale_factor) |
| 595 | |
| 596 | m = PARTITIONED_INSERT_RE.search(insert) |
| 597 | if m: |
| 598 | insert_statement = build_partitioned_load(insert, m, can_hint, params) |
| 599 | else: |
| 600 | if can_hint: |
| 601 | params[VAR_HINT] = HINT_SHUFFLE |
| 602 | insert_statement = insert.format(**params) |
| 603 | |
| 604 | # Kudu tables are managed and don't support OVERWRITE, so we replace OVERWRITE |
| 605 | # with INTO to make this a regular INSERT. |
| 606 | if file_format == 'kudu': |
| 607 | insert_statement = insert_statement.replace("OVERWRITE", "INTO") |
| 608 | |
| 609 | if for_impala: |
| 610 | return insert_statement |
| 611 | |
| 612 | statement = SET_PARTITION_MODE_NONSTRICT_STATEMENT + "\n" |
| 613 | statement += SET_DYNAMIC_PARTITION_STATEMENT + "\n" |
| 614 | statement += SET_MAX_DYNAMIC_PARTITIONS_STATEMENT + "\n" |
| 615 | statement += "set hive.auto.convert.join=true;\n" |
| 616 | |
| 617 | # For some reason (hive bug?) we need to have the CombineHiveInputFormat set |
| 618 | # for cases where we are compressing in bzip on certain tables that |
| 619 | # have multiple files. |
| 620 | if 'multi' in table_name and ('bzip' in db_suffix): |
| 621 | statement += SET_HIVE_INPUT_FORMAT % "CombineHiveInputFormat" |
| 622 | else: |
| 623 | statement += SET_HIVE_INPUT_FORMAT % "HiveInputFormat" |
| 624 | return statement + insert_statement |
| 625 | |
| 626 | |
| 627 | def build_hbase_insert(db_name, db_suffix, table_name): |
no test coverage detected