| 759 | |
| 760 | |
| 761 | def get_keywords(sql): |
| 762 | res = set() |
| 763 | if len(sql['where']) > 0: |
| 764 | res.add('where') |
| 765 | if len(sql['groupBy']) > 0: |
| 766 | res.add('group') |
| 767 | if len(sql['having']) > 0: |
| 768 | res.add('having') |
| 769 | if len(sql['orderBy']) > 0: |
| 770 | res.add(sql['orderBy'][0]) |
| 771 | res.add('order') |
| 772 | if sql['limit'] is not None: |
| 773 | res.add('limit') |
| 774 | if sql['except'] is not None: |
| 775 | res.add('except') |
| 776 | if sql['union'] is not None: |
| 777 | res.add('union') |
| 778 | if sql['intersect'] is not None: |
| 779 | res.add('intersect') |
| 780 | |
| 781 | # or keyword |
| 782 | ao = sql['from']['conds'][1::2] + sql['where'][1::2] + sql['having'][1::2] |
| 783 | if len([token for token in ao if token == 'or']) > 0: |
| 784 | res.add('or') |
| 785 | |
| 786 | cond_units = sql['from']['conds'][::2] + sql['where'][::2] + sql['having'][::2] |
| 787 | # not keyword |
| 788 | if len([cond_unit for cond_unit in cond_units if cond_unit[0]]) > 0: |
| 789 | res.add('not') |
| 790 | |
| 791 | # in keyword |
| 792 | if len([cond_unit for cond_unit in cond_units if cond_unit[1] == WHERE_OPS.index('in')]) > 0: |
| 793 | res.add('in') |
| 794 | |
| 795 | # like keyword |
| 796 | if len([cond_unit for cond_unit in cond_units if cond_unit[1] == WHERE_OPS.index('like')]) > 0: |
| 797 | res.add('like') |
| 798 | |
| 799 | return res |
| 800 | |
| 801 | |
| 802 | def eval_keywords(pred, label): |