Project

General

Profile

« Previous | Next » 

Revision 2811

sql.py: put_table(): Fixed bug where distinct_on included columns that were not in the input table, and were thus incorrectly taken from the LEFT JOINed output table

View differences:

lib/sql.py
1185 1185
    
1186 1186
    limit_ref = [None]
1187 1187
    conds = set()
1188
    distinct_on = []
1188
    distinct_on = sql_gen.ColDict(db, out_table)
1189 1189
    def mk_main_select(joins, cols):
1190
        return mk_select(db, joins, cols, conds, distinct_on,
1190
        distinct_on_cols = [c.to_Col() for c in distinct_on.values()]
1191
        return mk_select(db, joins, cols, conds, distinct_on_cols,
1191 1192
            limit=limit_ref[0], start=0)
1192 1193
    
1193 1194
    exc_strs = set()
......
1243 1244
        insert_joins = input_joins[:] # don't modify original!
1244 1245
        insert_args = dict(recover=True, cacheable=False)
1245 1246
        if has_joins:
1246
            distinct_on = [v.to_Col() for v in join_cols.values()]
1247 1247
            insert_joins.append(sql_gen.Join(out_table, join_cols,
1248 1248
                sql_gen.filter_out))
1249 1249
        else:
......
1259 1259
            log_exc(e)
1260 1260
            
1261 1261
            old_join_cols = join_cols.copy()
1262
            distinct_on.update(util.dict_subset(mapping, e.cols))
1262 1263
            join_cols.update(util.dict_subset_right_join(mapping, e.cols))
1263 1264
            log_debug('Ignoring existing rows, comparing on these columns:\n'
1264 1265
                +strings.as_inline_table(join_cols, ustr=col_ustr))

Also available in: Unified diff