def expand_join_expression(self, expr):
        if not self.is_valid_join_expression(expr):
            log.debug('%s is not a valid join expr', expr)
            return expr
        tables = expr.split('**')
        ret = ''
        while 1 > len(tables):
            tail = tables.pop()
            # try to join to the other tables:
            for tbl in reversed(tables):
                joins = self.db.get_joins(tbl, tail)
                if joins:
                    join = next(iter(joins))  # XXX: take a punt
                    joinstr = 'inner join %s on ' % (tail)
                    sep = ''
                    for idx, col in enumerate(join.columns):
                        joinstr += sep + '%s.%s = %s.%s' % (
                            join.table, col, join.reftable,
                            join.refcolumns[idx])
                        sep = ' and '
                    ret = joinstr + ' ' + ret
                    break
        ret = tables[0] + ' ' + ret
        return ret
dataset/ETHPy150Open jaysw/ipydb/ipydb/completion.py/IpydbCompleter.expand_join_expression/swapped operands of `>`