From fedd6c60200ecc075de625e20d14b07e13eaa167 Mon Sep 17 00:00:00 2001 From: Christian Pedersen Date: Tue, 15 Dec 2020 09:41:16 +0100 Subject: [PATCH] Support FINAL on distributed tables Support the FINAL modifier on distributed collapsing- and replacingmergetree tables. --- src/infi/clickhouse_orm/query.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/infi/clickhouse_orm/query.py b/src/infi/clickhouse_orm/query.py index 92efec4..b912992 100644 --- a/src/infi/clickhouse_orm/query.py +++ b/src/infi/clickhouse_orm/query.py @@ -539,8 +539,20 @@ class QuerySet(object): Adds a FINAL modifier to table, meaning data will be collapsed to final version. Can be used with the `CollapsingMergeTree` and `ReplacingMergeTree` engines only. """ - from .engines import CollapsingMergeTree, ReplacingMergeTree - if not isinstance(self._model_cls.engine, (CollapsingMergeTree, ReplacingMergeTree)): + from .engines import CollapsingMergeTree, ReplacingMergeTree, Distributed + + _engine = self._model_cls.engine + + if isinstance(_engine, (Distributed)): + # find the "real" engine for the Distributed table + children = self._model_cls.mro() + for child in children: + # we asume the first that is not Distributed is the child. + if isinstance(child.engine, (Distributed)): continue + _engine = child.engine + break + + if not isinstance(_engine, (CollapsingMergeTree, ReplacingMergeTree)): raise TypeError('final() method can be used only with the CollapsingMergeTree and ReplacingMergeTree engines') qs = copy(self)