ffaad7649566c35b015694219f73aba8b6705902,src/fonduer/utils/utils_udf.py,,add_keys,#Any#Any#Any#,129

Before Change


        existing_keys = set(k.name for k in session.query(key_table).all())
        new_keys = set(keys).difference(existing_keys)
        // Bulk insert all new feature keys
        if new_keys:
            try:
                session.execute(
                    key_table.__table__.insert(), [{"name": key} for key in new_keys]
                )
                session.commit()
                return
            except Exception:
                continue
        else:
            // All keys have been inserted already
            return

After Change



    // Rather than deal with concurrency of querying first then inserting only
    // new keys, insert with on_conflict_do_nothing.
    stmt = insert(key_table.__table__).values([{"name": key} for key in keys])
    stmt = stmt.on_conflict_do_nothing(constraint=key_table.__table__.primary_key)
    session.execute(stmt)
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 4

Non-data size: 4

Instances


Project Name: HazyResearch/fonduer
Commit Name: ffaad7649566c35b015694219f73aba8b6705902
Time: 2018-09-01
Author: lwhsiao@stanford.edu
File Name: src/fonduer/utils/utils_udf.py
Class Name:
Method Name: add_keys


Project Name: numerai/submission-criteria
Commit Name: 3bf5f2de89807642dcd1e030e45226ff3944779b
Time: 2017-11-10
Author: xander@numer.ai
File Name: common.py
Class Name:
Method Name: get_filename


Project Name: pantsbuild/pants
Commit Name: 1e3f7071cf4095abfface461164703106563c459
Time: 2016-02-22
Author: stuhood@gmail.com
File Name: src/python/pants/engine/exp/mapper.py
Class Name: AddressMapper
Method Name: resolve


Project Name: commonsense/conceptnet5
Commit Name: e809acfe2fc641630dd978b12576e35af1acc87e
Time: 2019-03-26
Author: rspeer@luminoso.com
File Name: conceptnet5/db/query.py
Class Name: AssertionFinder
Method Name: query