الانتقال إلى المحتوى الرئيسي

sumMapWithOverflow

أُضيفت في: v20.1.0 تُجمِّع مصفوفة value وفقًا للمفاتيح المحددة في مصفوفة key. وتُرجع Tuple من مصفوفتين: المفاتيح بترتيب مُرتَّب، والقيم المُجمَّعة للمفاتيح المقابلة. وتختلف عن الدالة sumMap في أنها تُجري الجمع مع تجاوز السعة، أي إنها تُرجع ناتج الجمع بنفس نوع بيانات الوسيط.
  • إن تمرير Tuple من مصفوفتَي المفاتيح والقيم مطابق لتمرير مصفوفة من المفاتيح ومصفوفة من القيم.
  • يجب أن يكون عدد العناصر في key وvalue متماثلًا في كل صف يُجرى عليه التجميع.
الصيغة
sumMapWithOverflow(key, value)
sumMapWithOverflow(Tuple(key, value))
الوسيطات
  • key — مصفوفة من المفاتيح. Array
  • value — مصفوفة من القيم. 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)) │
└─────────────────────┴────────────────────────────────────┴─────────────────────────────────┘
انظر أيضًا
آخر تعديل في ٢٥ يونيو ٢٠٢٦