def table_exprs(self): '''Provides a list of all table_exprs that are declared within this FROM block. ''' table_exprs = \ TableExprList(join_clause.table_expr for join_clause in self.join_clauses) table_exprs.append(self.table_expr) return table_exprs
def describe_common_tables(cursors): '''Find and return a TableExprList containing Table objects that the given conns have in common. ''' common_table_names = None for cursor in cursors: table_names = set(cursor.list_table_names()) if common_table_names is None: common_table_names = table_names else: common_table_names &= table_names common_table_names = sorted(common_table_names) tables = TableExprList() for table_name in common_table_names: common_table = None mismatch = False for cursor in cursors: table = cursor.describe_table(table_name) if common_table is None: common_table = table continue if not table.cols: LOG.debug('%s has no remaining columns', table_name) mismatch = True break if len(common_table.cols) != len(table.cols): LOG.debug( 'Ignoring table %s.' ' It has a different number of columns across databases.', table_name) mismatch = True break if common_table.primary_key_names != table.primary_key_names: LOG.debug( 'Ignoring table {name} because of differing primary keys: ' '{common_table_keys} vs. {table_keys}'.format( name=table_name, common_table_keys=common_table.primary_key_names, table_keys=table.primary_key_names)) mismatch = True break for left, right in izip(common_table.cols, table.cols): if not left.name == right.name and left.type == right.type: LOG.debug( 'Ignoring table %s. It has different columns %s vs %s.' % (table_name, left, right)) mismatch = True break if mismatch: break if not mismatch: tables.append(common_table) return tables
def describe_common_tables(cursors): '''Find and return a TableExprList containing Table objects that the given conns have in common. ''' common_table_names = None for cursor in cursors: table_names = set(cursor.list_table_names()) if common_table_names is None: common_table_names = table_names else: common_table_names &= table_names common_table_names = sorted(common_table_names) tables = TableExprList() for table_name in common_table_names: common_table = None mismatch = False for cursor in cursors: table = cursor.describe_table(table_name) if common_table is None: common_table = table continue if not table.cols: LOG.debug('%s has no remaining columns', table_name) mismatch = True break if len(common_table.cols) != len(table.cols): LOG.debug('Ignoring table %s.' ' It has a different number of columns across databases.', table_name) mismatch = True break if common_table.primary_key_names != table.primary_key_names: LOG.debug( 'Ignoring table {name} because of differing primary keys: ' '{common_table_keys} vs. {table_keys}'.format( name=table_name, common_table_keys=common_table.primary_key_names, table_keys=table.primary_key_names)) mismatch = True break for left, right in izip(common_table.cols, table.cols): if not left.name == right.name and left.type == right.type: LOG.debug('Ignoring table %s. It has different columns %s vs %s.' % (table_name, left, right)) mismatch = True break if mismatch: break if not mismatch: tables.append(common_table) return tables