メインコンテンツへスキップ

sumMapWithOverflow

導入バージョン: v20.1.0 key 配列で指定されたキーに従って value 配列の値を合計します。返されるのは 2 つの配列からなるタプルで、キーはソート順、値は対応するキーごとに合計されたものです。 sumMap 関数との違いは、オーバーフローありで加算を行う点です。つまり、加算結果も引数のData typeと同じData typeで返されます。
  • キー配列と値配列のタプルを渡すことは、キーの配列と値の配列を別々に渡すのと同じです。
  • 集計対象となる各行では、keyvalue の要素数が同じである必要があります。
構文
sumMapWithOverflow(key, value)
sumMapWithOverflow(Tuple(key, value))
引数
  • key — キーの Array。Array
  • value — 値の Array。Array
戻り値 2 つの Array からなる Tuple を返します。ソート順のキーと、対応するキーごとに合計された値です。Tuple(Array, Array) オーバーフローの挙動を示す Array の構文
Query
CREATE TABLE sum_map(
    date Date,
    timeslot DateTime,
    statusMap Nested(
        status UInt8,
        requests UInt8
    ),
    statusMapTuple Tuple(Array(Int8), Array(Int8))
) ENGINE = Memory;

INSERT INTO sum_map VALUES
    ('2000-01-01', '2000-01-01 00:00:00', [1, 2, 3], [10, 10, 10], ([1, 2, 3], [10, 10, 10])),
    ('2000-01-01', '2000-01-01 00:00:00', [3, 4, 5], [10, 10, 10], ([3, 4, 5], [10, 10, 10])),
    ('2000-01-01', '2000-01-01 00:01:00', [4, 5, 6], [10, 10, 10], ([4, 5, 6], [10, 10, 10])),
    ('2000-01-01', '2000-01-01 00:01:00', [6, 7, 8], [10, 10, 10], ([6, 7, 8], [10, 10, 10]));

SELECT
    timeslot,
    toTypeName(sumMap(statusMap.status, statusMap.requests)),
    toTypeName(sumMapWithOverflow(statusMap.status, statusMap.requests))
FROM sum_map
GROUP BY timeslot;
Response
┌────────────timeslot─┬─toTypeName(sumMap⋯usMap.requests))─┬─toTypeName(sumMa⋯usMap.requests))─┐
│ 2000-01-01 00:01:00 │ Tuple(Array(UInt8), Array(UInt64)) │ Tuple(Array(UInt8), Array(UInt8)) │
│ 2000-01-01 00:00:00 │ Tuple(Array(UInt8), Array(UInt64)) │ Tuple(Array(UInt8), Array(UInt8)) │
└─────────────────────┴────────────────────────────────────┴───────────────────────────────────┘
同じ結果を返すTuple構文
Query
SELECT
    timeslot,
    toTypeName(sumMap(statusMapTuple)),
    toTypeName(sumMapWithOverflow(statusMapTuple))
FROM sum_map
GROUP BY timeslot;
Response
┌────────────timeslot─┬─toTypeName(sumMap(statusMapTuple))─┬─toTypeName(sumM⋯tatusMapTuple))─┐
│ 2000-01-01 00:01:00 │ Tuple(Array(Int8), Array(Int64))   │ Tuple(Array(Int8), Array(Int8)) │
│ 2000-01-01 00:00:00 │ Tuple(Array(Int8), Array(Int64))   │ Tuple(Array(Int8), Array(Int8)) │
└─────────────────────┴────────────────────────────────────┴─────────────────────────────────┘
関連項目
最終更新日 2026年6月10日