MCPcopy Create free account
hub / github.com/google-research/language / populate_sql

Function populate_sql

language/xsp/data_preprocessing/sql_parsing.py:749–874  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

747
748
749def 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):

Callers 5

convert_spiderFunction · 0.90
convert_wikisqlFunction · 0.90
_parse_functionFunction · 0.85
_parse_comparisonFunction · 0.85
_parse_whereFunction · 0.85

Calls 15

_is_punctuationFunction · 0.85
_add_simple_stepFunction · 0.85
_is_parenthesisFunction · 0.85
_is_wildcardFunction · 0.85
_is_selectFunction · 0.85
_is_fromFunction · 0.85
_is_whereFunction · 0.85
_parse_whereFunction · 0.85
_is_functionFunction · 0.85
_parse_functionFunction · 0.85
_is_identifierFunction · 0.85
_parse_identifierFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…