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

Function _parse_where

language/xsp/data_preprocessing/sql_parsing.py:666–746  ·  view source on GitHub ↗

Parse the part relative to the WHERE clause of the SQL query.

(sql, example, anonymize_values)

Source from the content-addressed store, hash-verified

664
665
666def _parse_where(sql, example, anonymize_values):
667 """Parse the part relative to the WHERE clause of the SQL query."""
668 successful_copy = True
669 for item in sql:
670 if item.ttype == sqlparse.tokens.Text.Whitespace:
671 continue
672
673 if _is_keyword(item) and item.value.lower() in ('where',):
674 _add_simple_step(item, example)
675 continue
676
677 if _is_comparison(item):
678 successful_copy = _parse_comparison(item, example,
679 anonymize_values) and successful_copy
680 continue
681
682 if _is_comparison_operator(item):
683 _add_simple_step(item, example)
684 continue
685
686 if _is_identifier(item):
687 successful_copy = _parse_identifier(item, example,
688 anonymize_values) and successful_copy
689 continue
690
691 if _is_identifier_list(item):
692 successful_copy = _parse_identifier_list(
693 item, example, anonymize_values) and successful_copy
694 continue
695
696 if _is_keyword(item) and item.value.lower() in ('between', 'and', 'or'):
697 _add_simple_step(item, example)
698 continue
699
700 if _is_keyword(item) and item.value.lower() in ('not', 'in', 'intersect'):
701 _add_simple_step(item, example)
702 continue
703
704 if _is_keyword(item) and item.value.lower() in ('distinct',):
705 _add_simple_step(item, example)
706 continue
707
708 if _is_integer(item):
709 prev_len = len(example.gold_sql_query.actions)
710 successful_copy = _add_simple_value(item, example,
711 anonymize_values) and successful_copy
712 if len(example.gold_sql_query.actions) == prev_len:
713 raise ValueError(
714 'Gold query did not change length when adding simple value!')
715 continue
716
717 # Like '%asd%'
718 if _is_keyword(item) and item.value.lower() in ('like',):
719 _add_simple_step(item, example)
720 continue
721
722 if _is_literal(item):
723 prev_len = len(example.gold_sql_query.actions)

Callers 1

populate_sqlFunction · 0.85

Calls 15

_is_keywordFunction · 0.85
_add_simple_stepFunction · 0.85
_is_comparisonFunction · 0.85
_parse_comparisonFunction · 0.85
_is_comparison_operatorFunction · 0.85
_is_identifierFunction · 0.85
_parse_identifierFunction · 0.85
_is_identifier_listFunction · 0.85
_parse_identifier_listFunction · 0.85
_is_integerFunction · 0.85
_add_simple_valueFunction · 0.85
_is_literalFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…