zoukankan      html  css  js  c++  java
  • clikhouse报错:DB::Exception: Storage MergeTree requires 3 to 4 parameters:

    Received exception from server (version 20.2.1):
    Code: 42. DB::Exception: Received from localhost:9000. DB::Exception: Storage MergeTree requires 3 to 4 parameters:
    name of column with date,
    [sampling element of primary key],
    primary key expression,
    index granularity

    MergeTree is a family of storage engines.

    MergeTrees are different in two ways:
    - they may be replicated and non-replicated;
    - they may do different actions on merge: nothing; sign collapse; sum; apply aggregete functions.

    So we have 14 combinations:
    MergeTree, CollapsingMergeTree, SummingMergeTree, AggregatingMergeTree, ReplacingMergeTree, GraphiteMergeTree, VersionedCollapsingMergeTree
    ReplicatedMergeTree, ReplicatedCollapsingMergeTree, ReplicatedSummingMergeTree, ReplicatedAggregatingMergeTree, ReplicatedReplacingMergeTree, ReplicatedGraphiteMergeTree, ReplicatedVersionedCollapsingMergeTree

    In most of cases, you need MergeTree or ReplicatedMergeTree.

    For replicated merge trees, you need to supply a path in ZooKeeper and a replica name as the first two parameters.
    Path in ZooKeeper is like '/clickhouse/tables/01/' where /clickhouse/tables/ is a common prefix and 01 is a shard name.
    Replica name is like 'mtstat01-1' - it may be the hostname or any suitable string identifying replica.
    You may use macro substitutions for these parameters. It's like ReplicatedMergeTree('/clickhouse/tables/{shard}/', '{replica}'...
    Look at the <macros> section in server configuration file.

    Next parameter (which is the first for unreplicated tables and the third for replicated tables) is the name of date column.
    Date column must exist in the table and have type Date (not DateTime).
    It is used for internal data partitioning and works like some kind of index.

    If your source data doesn't have a column of type Date, but has a DateTime column, you may add values for Date column while loading,
    or you may INSERT your source data to a table of type Log and then transform it with INSERT INTO t SELECT toDate(time) AS date, * FROM ...
    If your source data doesn't have any date or time, you may just pass any constant for a date column while loading.

    Next parameter is optional sampling expression. Sampling expression is used to implement SAMPLE clause in query for approximate query execution.
    If you don't need approximate query execution, simply omit this parameter.
    Sample expression must be one of the elements of the primary key tuple. For example, if your primary key is (CounterID, EventDate, intHash64(UserID)), your sampling expression might be intHash64(UserID).

    Next parameter is the primary key tuple. It's like (CounterID, EventDate, intHash64(UserID)) - a list of column names or functional expressions in round brackets. If your primary key has just one element, you may omit round brackets.

    Careful choice of the primary key is extremely important for processing short-time queries.

    Next parameter is index (primary key) granularity. Good value is 8192. You have no reasons to use any other value.

    For the Collapsing mode, the last parameter is the name of a sign column - a special column that is used to 'collapse' rows with the same primary key while merging.

    For the Summing mode, the optional last parameter is a list of columns to sum while merging. This list is passed in round brackets, like (PageViews, Cost).
    If this parameter is omitted, the storage will sum all numeric columns except columns participating in the primary key.

    For the Replacing mode, the optional last parameter is the name of a 'version' column. While merging, for all rows with the same primary key, only one row is selected: the last row, if the version column was not specified, or the last row with the maximum version value, if specified.

    For VersionedCollapsing mode, the last 2 parameters are the name of a sign column and the name of a 'version' column. Version column must be in primary key. While merging, a pair of rows with the same primary key and different sign may collapse.

    Examples:

    MergeTree(EventDate, (CounterID, EventDate), 8192)

    MergeTree(EventDate, intHash32(UserID), (CounterID, EventDate, intHash32(UserID), EventTime), 8192)

    CollapsingMergeTree(StartDate, intHash32(UserID), (CounterID, StartDate, intHash32(UserID), VisitID), 8192, Sign)

    SummingMergeTree(EventDate, (OrderID, EventDate, BannerID, PhraseID, ContextType, RegionID, PageID, IsFlat, TypeID, ResourceNo), 8192)

    SummingMergeTree(EventDate, (OrderID, EventDate, BannerID, PhraseID, ContextType, RegionID, PageID, IsFlat, TypeID, ResourceNo), 8192, (Shows, Clicks, Cost, CostCur, ShowsSumPosition, ClicksSumPosition, SessionNum, SessionLen, SessionCost, GoalsNum, SessionDepth))

    ReplicatedMergeTree('/clickhouse/tables/{layer}-{shard}/hits', '{replica}', EventDate, intHash32(UserID), (CounterID, EventDate, intHash32(UserID), EventTime), 8192)

    For further info please read the documentation: https://clickhouse.yandex/
    .

    0 rows in set. Elapsed: 0.174 sec.

    缺少参数 必须有分区参数:

  • 相关阅读:
    念大学有用么摘抄
    天行健,君子以自强不息;地势坤,君子以厚德载物。
    加快播放视频的播放速度
    微信语音通话中无法播放聊天对话框中的视频
    劝学
    在这个世界上就是物竞天择,适者生存。弱肉强食,优胜劣汰?
    英语名言名句集锦
    贵州理科状元邹基伟:不放过上课的每一秒
    带宽的理解
    第二章 Python运行程序
  • 原文地址:https://www.cnblogs.com/wqbin/p/13889733.html
Copyright © 2011-2022 走看看