HomeSoftware Heritage

cassandra.cql: Use static dataclasses instead of generating namedtuples on the…

Description

cassandra.cql: Use static dataclasses instead of generating namedtuples on the fly.

Before this commit, python-cassandra used the default row factory,
which creates anonymous named tuple on each query, which makes it
impossible to type CqlRunner properly.

This commit replaces the row factory with dict_factory, which creates
only dicts, and converts them to well-defined dataclasses.
Additionally, this stop leaking python-cassandra internals to
cassandra.storage.

This also has some great side-effects:

  • methods of CqlRunner are now consistent with each other (eg. _add_one methods used to be a mix of objects, dictionaries, and taking each value as argument)
  • it will allow me to deduplicate more codes in further commits (I already deduplicated insertions methods to use self._add_one, as it was meant on the initial write of this class)
  • CqlRunner no longer needs to define lists with column names, they are automatically detected from the dataclasses

Details

Provenance
vlorentzAuthored on Aug 10 2020, 9:33 PM
vlorentzPushed on Aug 12 2020, 10:13 AM
Differential Revision
D3756: cassandra.cql: Use static dataclasses instead of generating namedtuples on the fly.
Parents
rDSTO7d332f596764: algos/snapshot.py: add types.
Branches
Unknown
Tags
Unknown
Build Status
Buildable 14500
Build 22305: test-and-buildJenkins console · Jenkins