The DistributedModel is used when working with ClickHouse Distributed engines. Since distributed tables do not store data themselves, they must be linked to a storage model.
Automatic Fix: If your DistributedModel does not explicitly define a storage table, you can call fix_engine() to automatically find the first non-distributed model in the superclass hierarchy and set it as the engine's storage table.
Explicit Configuration: Alternatively, you can explicitly pass the storage model to the Distributed engine during definition.
class Foo(Model):
id = UInt8Field(1)
# Option 1: Automatic fix
class FooDistributed(Foo, DistributedModel):
engine = Distributed('my_cluster')
FooDistributed.engine.table
# None
FooDistributed.fix_engine()
FooDistributed.engine.table
# <class '__main__.Foo'>
# Option 2: Explicit definition
class FooDistributedVerbose(Foo, DistributedModel):
engine = Distributed('my_cluster', Foo)