sumMapWithOverflow
أُضيفت في: v20.1.0
تُجمِّع مصفوفة value وفقًا للمفاتيح المحددة في مصفوفة key. وتُرجع Tuple من مصفوفتين: المفاتيح بترتيب مُرتَّب، والقيم المُجمَّعة للمفاتيح المقابلة.
وتختلف عن الدالة sumMap في أنها تُجري الجمع مع تجاوز السعة، أي إنها تُرجع ناتج الجمع بنفس نوع بيانات الوسيط.
الصيغة
sumMapWithOverflow(key, value)
sumMapWithOverflow(Tuple(key, value))الوسيطات
القيمة المعادة
يعيد قيمة من النوع Tuple تتكوّن من مصفوفتين: المفاتيح بترتيب مرتب، والقيم المجمّعة للمفاتيح المقابلة. Tuple(Array, Array)
أمثلة
صياغة Array التي توضّح سلوك تجاوز السعة
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;┌────────────timeslot─┬─toTypeName(sumMap(statusMap.status, statusMap.requests))─┬─toTypeName(sumMapWithOverflow(statusMap.status, statusMap.requests))─┐
│ 2000-01-01 00:00:00 │ Tuple(Array(UInt8), Array(UInt64)) │ Tuple(Array(UInt8), Array(UInt8)) │
│ 2000-01-01 00:01:00 │ Tuple(Array(UInt8), Array(UInt64)) │ Tuple(Array(UInt8), Array(UInt8)) │
└─────────────────────┴──────────────────────────────────────────────────────────┴──────────────────────────────────────────────────────────────────────┘صياغة Tuple بالنتيجة نفسها
SELECT
timeslot,
toTypeName(sumMap(statusMapTuple)),
toTypeName(sumMapWithOverflow(statusMapTuple))
FROM sum_map
GROUP BY timeslot;┌────────────timeslot─┬─toTypeName(sumMap(statusMapTuple))─┬─toTypeName(sumMapWithOverflow(statusMapTuple))─┐
│ 2000-01-01 00:00:00 │ Tuple(Array(Int8), Array(Int64)) │ Tuple(Array(Int8), Array(Int8)) │
│ 2000-01-01 00:01:00 │ Tuple(Array(Int8), Array(Int64)) │ Tuple(Array(Int8), Array(Int8)) │
└─────────────────────┴────────────────────────────────────┴────────────────────────────────────────────────┘انظر أيضًا