-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clickhouse ReplicatedMergeTree family support added (#36)
* Added engine type support (#1) * Add support for engine types * added cluster name to table creation args * Removed unsupported engines * Added comments to create empty table function * moved table path, replica & cluster name to config * variables added to config * Add engine type support (#2) * Add support for engine types * added cluster name to table creation args * Removed unsupported engines * Added comments to create empty table function * moved table path, replica & cluster name to config * variables added to config * Moved engine type to config * add cluster support to alter table command --------- Co-authored-by: RamlahAziz <ramlah.aziz2012@gmail.com>
- Loading branch information
1 parent
aae7305
commit 1796ead
Showing
3 changed files
with
90 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
from clickhouse_sqlalchemy import engines | ||
from enum import Enum | ||
|
||
|
||
class SupportedEngines(str, Enum): | ||
MERGE_TREE = "MergeTree" | ||
REPLACING_MERGE_TREE = "ReplacingMergeTree" | ||
SUMMING_MERGE_TREE = "SummingMergeTree" | ||
AGGREGATING_MERGE_TREE = "AggregatingMergeTree" | ||
REPLICATED_MERGE_TREE = "ReplicatedMergeTree" | ||
REPLICATED_REPLACING_MERGE_TREE = "ReplicatedReplacingMergeTree" | ||
REPLICATED_SUMMING_MERGE_TREE = "ReplicatedSummingMergeTree" | ||
REPLICATED_AGGREGATING_MERGE_TREE = "ReplicatedAggregatingMergeTree" | ||
|
||
|
||
ENGINE_MAPPING = { | ||
SupportedEngines.MERGE_TREE: engines.MergeTree, | ||
SupportedEngines.REPLACING_MERGE_TREE: engines.ReplacingMergeTree, | ||
SupportedEngines.SUMMING_MERGE_TREE: engines.SummingMergeTree, | ||
SupportedEngines.AGGREGATING_MERGE_TREE: engines.AggregatingMergeTree, | ||
SupportedEngines.REPLICATED_MERGE_TREE: engines.ReplicatedMergeTree, | ||
SupportedEngines.REPLICATED_REPLACING_MERGE_TREE: engines.ReplicatedReplacingMergeTree, | ||
SupportedEngines.REPLICATED_SUMMING_MERGE_TREE: engines.ReplicatedSummingMergeTree, | ||
SupportedEngines.REPLICATED_AGGREGATING_MERGE_TREE: engines.ReplicatedAggregatingMergeTree, | ||
} | ||
|
||
|
||
def is_supported_engine(engine_type): | ||
return engine_type in SupportedEngines.__members__.values() | ||
|
||
|
||
def get_engine_class(engine_type): | ||
return ENGINE_MAPPING.get(engine_type) | ||
|
||
|
||
def create_engine_wrapper(engine_type, primary_keys, config: dict | None = None): | ||
# check if engine type is in supported engines | ||
if is_supported_engine(engine_type) is False: | ||
raise ValueError(f"Engine type {engine_type} is not supported.") | ||
|
||
engine_args = {"primary_key": primary_keys} | ||
if config is not None: | ||
if engine_type in ( | ||
SupportedEngines.REPLICATED_MERGE_TREE, | ||
SupportedEngines.REPLICATED_REPLACING_MERGE_TREE, | ||
SupportedEngines.REPLICATED_SUMMING_MERGE_TREE, | ||
SupportedEngines.REPLICATED_AGGREGATING_MERGE_TREE, | ||
): | ||
if config.get("table_path"): | ||
engine_args["table_path"] = config.get("table_path") | ||
if config.get("replica_name"): | ||
engine_args["replica_name"] = config.get("replica_name") | ||
|
||
engine_class = get_engine_class(engine_type) | ||
|
||
return engine_class(**engine_args) |