b4562327a4554689d8ab0906c605476ccf817336,language/xsp/data_preprocessing/abstract_sql.py,,_get_from_clause_for_tables,#Any#Any#,549

Before Change


def _get_from_clause_for_tables(table_names, fk_relations):
  Returns list of SqlSpan tuples for FROM clause.
  if not table_names:
    raise ParseError("No table names provided.")
  if len(table_names) == 1:
    return [make_sql_span(table_name=table_names[0])]

  // Map of (table_a, table_b) to (column_a, column_b)
  fk_relations_map = {}
  for relation in fk_relations:
    fk_relations_map[(relation.child_table,
                      relation.parent_table)] = (relation.child_column,
                                                 relation.parent_column)
    // Also add the reverse.
    fk_relations_map[(relation.parent_table,
                      relation.child_table)] = (relation.parent_column,
                                                relation.child_column)

  // Naively try every permutation of table_names until we get a hit.
  // TODO(petershaw): Could probably speed up this up quite a bit and provide
  // better error handling for ambiguous cases.

After Change


  sql_spans = []
  sql_spans.append(make_sql_span(table_name=visited_tables[0]))
  for i in range(len(visited_tables) - 1):
    table_a = visited_tables[i]
    table_b = visited_tables[i + 1]
    column_a, column_b = fk_relations[i]
    // join table_b on table_a.column_a = table_b.column_b
    sql_spans.append(make_sql_span(sql_token="join"))
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 4

Instances


Project Name: google-research/language
Commit Name: b4562327a4554689d8ab0906c605476ccf817336
Time: 2019-11-15
Author: kentonl@google.com
File Name: language/xsp/data_preprocessing/abstract_sql.py
Class Name:
Method Name: _get_from_clause_for_tables


Project Name: pantsbuild/pants
Commit Name: b538f8e02f54afe537e0b0cecdddcd63d8740daa
Time: 2020-01-31
Author: ericarellano@me.com
File Name: src/python/pants/engine/legacy/parser.py
Class Name: LegacyPythonCallbacksParser
Method Name: parse


Project Name: pantsbuild/pants
Commit Name: 65cd3bc9338aeb7efe02c13eea9e7b9def3435b9
Time: 2015-10-29
Author: benjyw@gmail.com
File Name: src/python/pants/option/parser.py
Class Name: Parser
Method Name: register