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 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 table_exprs(self): """ Return a list of all table expressions that are declared by this query. This is abstract as the clauses that do this differ across query types. Since all supported queries may have a WITH clause, getting table expressions from the WITH clause is supported here. """ # This is an abstractproperty because it's only a *partial* implementation, however # for any statement or query that has a WITH clause, we can handle that here. table_exprs = TableExprList([]) if self.with_clause: table_exprs.extend(self.with_clause.table_exprs) 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 visible_table_exprs(self): '''Provides a list of all table_exprs that are declared within this FROM block and may be referenced in other clauses such as SELECT or WHERE. ''' return TableExprList(table_expr for table_expr in self.table_exprs if table_expr.is_visible)