if _is_literal(item):
prev_len = len(example.gold_sql_query.actions)
_add_simple_value(item, example, anonymize_values)
if len(example.gold_sql_query.actions) == prev_len:
raise ValueError(
"Gold query did not change length when adding simple value!")
continue
After Change
def _parse_identifier(sql, example, anonymize_values):
Parse the part relative to an Identifier in the SQL query.
successful_copy = True
for item in sql:
if item.ttype == sqlparse.tokens.Text.Whitespace:
continue
if _is_identifier(item):
successful_copy = _parse_identifier(item, example,
anonymize_values) and successful_copy
continue
if _is_order(item):
_add_simple_step(item, example)
continue
if (_is_table_alias(item) or (_is_punctuation(item) and item.value == ".")):
_add_simple_step(item, example)
continue
if _is_keyword(item) and item.value in ("as",):
_add_simple_step(item, example)
continue
if _is_name(item):
entity = _find_simple_entity(item.value, example)
if entity is not None:
schema_copy_action = None
if isinstance(entity, DatabaseTable):
schema_copy_action = SchemaEntityCopy(copied_table=entity)
elif isinstance(entity, TableColumn):
schema_copy_action = SchemaEntityCopy(copied_column=entity)
else:
raise ValueError("Type of entity is unexpected: " + str(type(entity)))
copy_action = SQLAction(entity_copy=schema_copy_action)
example.gold_sql_query.actions.append(copy_action)
else:
try:
_resolve_reference(item, example)
except AttributeError as e:
// Generally this means the reference wasn"t found i.e., in WikiSQL, a
// value didn"t have quotes, so just add it as a value
print(e)
successful_copy = _add_simple_value(
item, example, anonymize_values) and successful_copy
continue
if _is_literal(item):
prev_len = len(example.gold_sql_query.actions)
successful_copy = _add_simple_value(item, example,
anonymize_values) and successful_copy
if len(example.gold_sql_query.actions) == prev_len:
raise ValueError(
"Gold query did not change length when adding simple value!")
continue
_debug_state(item, example)
raise ParseError("Incomplete _parse_identifier")
return successful_copy
def _parse_operation(sql, example, anonymize_values):
Parse the part relative to an Operation in the SQL query.