@@ -640,6 +640,13 @@ ColumnPtr FunctionArrayIntersect<Mode>::execute(const UnpackedArrays & arrays, M
640640 // We have NULL in output only once if it should be there
641641 bool null_added = false ;
642642 bool use_null_map;
643+ const auto & arg = arrays.args [0 ];
644+ size_t off;
645+ // const array has only one row
646+ if (arg.is_const )
647+ off = (*arg.offsets )[0 ];
648+ else
649+ off = (*arg.offsets )[row];
643650
644651 if constexpr (std::is_same_v<Mode, ArrayModeUnion>)
645652 {
@@ -657,12 +664,6 @@ ColumnPtr FunctionArrayIntersect<Mode>::execute(const UnpackedArrays & arrays, M
657664 null_map.push_back (1 );
658665 null_added = true ;
659666 }
660- const auto & arg = arrays.args [0 ];
661- // const array has only one row
662- if (arg.is_const )
663- prev_off[0 ] = 0 ;
664- else
665- prev_off[0 ] = (*arg.offsets )[row];
666667 }
667668 else if constexpr (std::is_same_v<Mode, ArrayModeSymmetricDifference>)
668669 {
@@ -684,13 +685,6 @@ ColumnPtr FunctionArrayIntersect<Mode>::execute(const UnpackedArrays & arrays, M
684685 else if constexpr (std::is_same_v<Mode, ArrayModeIntersect>)
685686 {
686687 use_null_map = all_nullable;
687- const auto & arg = arrays.args [0 ];
688- size_t off;
689- // const array has only one row
690- if (arg.is_const )
691- off = (*arg.offsets )[0 ];
692- else
693- off = (*arg.offsets )[row];
694688
695689 for (auto i : collections::range (prev_off[0 ], off))
696690 {
@@ -719,9 +713,6 @@ ColumnPtr FunctionArrayIntersect<Mode>::execute(const UnpackedArrays & arrays, M
719713 const char * data = nullptr ;
720714 pair = map.find (columns[0 ]->serializeValueIntoArena (i, arena, data));
721715 }
722- prev_off[0 ] = off;
723- if (arg.is_const )
724- prev_off[0 ] = 0 ;
725716
726717 if (!current_has_nullable)
727718 all_has_nullable = false ;
@@ -732,6 +723,10 @@ ColumnPtr FunctionArrayIntersect<Mode>::execute(const UnpackedArrays & arrays, M
732723 insertElement<Map, ColumnType, is_numeric_column>(pair, result_offset, result_data, null_map, use_null_map);
733724 }
734725 }
726+ // Now we update the offsets for the first array
727+ prev_off[0 ] = off;
728+ if (arg.is_const )
729+ prev_off[0 ] = 0 ;
735730
736731 result_offsets.getElement (row) = result_offset;
737732 }
0 commit comments