Creates a sequence of output / decoder actions from a raw SQL query. Args: sql: The SQL query to convert. example: The NLToSQLExample object to add output actions. anonymize_values: Whether to anonymize values by replacing with a placeholder. Raises: ParseError: if the SQ
(sql, example, anonymize_values)
| 747 | |
| 748 | |
| 749 | def populate_sql(sql, example, anonymize_values): |
| 750 | """Creates a sequence of output / decoder actions from a raw SQL query. |
| 751 | |
| 752 | Args: |
| 753 | sql: The SQL query to convert. |
| 754 | example: The NLToSQLExample object to add output actions. |
| 755 | anonymize_values: Whether to anonymize values by replacing with a |
| 756 | placeholder. |
| 757 | |
| 758 | Raises: |
| 759 | ParseError: if the SQL query can't be parsed. |
| 760 | |
| 761 | Returns: |
| 762 | Boolean indicating whether all actions copying values from |
| 763 | the input utterance were successfully completed. |
| 764 | """ |
| 765 | successful_copy = True |
| 766 | for item in sql: |
| 767 | if item.ttype == sqlparse.tokens.Text.Whitespace: |
| 768 | continue |
| 769 | |
| 770 | if _is_punctuation(item) and (item.value in ('(', ')')): |
| 771 | _add_simple_step(item, example) |
| 772 | continue |
| 773 | |
| 774 | if _is_punctuation(item) and (item.value in (',',)): |
| 775 | _add_simple_step(item, example) |
| 776 | continue |
| 777 | |
| 778 | if _is_parenthesis(item): |
| 779 | successful_copy = populate_sql(item, example, |
| 780 | anonymize_values) and successful_copy |
| 781 | continue |
| 782 | |
| 783 | if _is_wildcard(item): |
| 784 | _add_simple_step(item, example) |
| 785 | continue |
| 786 | |
| 787 | if _is_select(item) or _is_from(item): |
| 788 | _add_simple_step(item, example) |
| 789 | continue |
| 790 | |
| 791 | if _is_where(item): |
| 792 | successful_copy = _parse_where(item, example, |
| 793 | anonymize_values) and successful_copy |
| 794 | continue |
| 795 | |
| 796 | if _is_function(item): |
| 797 | successful_copy = _parse_function(item, example, |
| 798 | anonymize_values) and successful_copy |
| 799 | continue |
| 800 | |
| 801 | if _is_identifier(item): |
| 802 | successful_copy = _parse_identifier(item, example, |
| 803 | anonymize_values) and successful_copy |
| 804 | continue |
| 805 | |
| 806 | if _is_identifier_list(item): |
no test coverage detected
searching dependent graphs…