Repository: duckdb/duckdb
File: src/function/scalar/list/list_intersect.cpp (C++)

Code before:

		if (l_format.validity.RowIsValid(l_idx) && r_format.validity.RowIsValid(r_idx)) {
			const auto &l_list = l_entries[l_idx];
			const auto &r_list = r_entries[r_idx];
			max_result_length += MinValue(l_list.length, r_list.length);
		}
	}
	return max_result_length;
}

static void ListIntersectFunction(DataChunk &args, ExpressionState &state, Vector &result) {
	auto row_count = args.size();

	// Handle NULL return type case
	if (result.GetType() == LogicalType::SQLNULL) {
		result.SetVectorType(VectorType::CONSTANT_VECTOR);
		ConstantVector::SetNull(result, true);
		return;
	}

	auto &l_vec = args.data[0];
	auto &r_vec = args.data[1];

	if (l_vec.GetType().id() != LogicalTypeId::LIST || r_vec.GetType().id() != LogicalTypeId::LIST) {
		throw InvalidInputException("list_intersect requires two LIST arguments");
	}

	const auto l_size = ListVector::GetListSize(l_vec);
	const auto r_size = ListVector::GetListSize(r_vec);

	auto &l_child = ListVector::GetEntry(l_vec);
	auto &r_child = ListVector::GetEntry(r_vec);

	const auto current_left_child_type = l_child.GetType();

	UnifiedVectorFormat l_format;
	UnifiedVectorFormat r_format;

	l_vec.ToUnifiedFormat(row_count, l_format);
	r_vec.ToUnifiedFormat(row_count, r_format);

	const auto l_entries = UnifiedVectorFormat::GetData<list_entry_t>(l_format);
	const auto r_entries = UnifiedVectorFormat::GetData<list_entry_t>(r_format);

	UnifiedVectorFormat l_child_format;
	UnifiedVectorFormat r_child_format;

	l_child.ToUnifiedFormat(l_size, l_child_format);
	r_child.ToUnifiedFormat(r_size, r_child_format);

	Vector l_sortkey_vec(LogicalType::BLOB, l_size);

Review comment (suggestion):
I don't think we can hit this code path given that we define our input parameters as `LogicalType::LIST(LogicalType::TEMPLATE("T"))`. We can likely remove it, or, if not, add a test for it.

Code after:

		if (l_format.validity.RowIsValid(l_idx) && r_format.validity.RowIsValid(r_idx)) {
			const auto &l_list = l_entries[l_idx];
			const auto &r_list = r_entries[r_idx];
			max_result_length += MinValue(l_list.length, r_list.length);
		}
	}
	return max_result_length;
}

static void ListIntersectFunction(DataChunk &args, ExpressionState &state, Vector &result) {
	auto row_count = args.size();

	// Handle NULL return type case
	if (result.GetType() == LogicalType::SQLNULL) {
		result.SetVectorType(VectorType::CONSTANT_VECTOR);
		ConstantVector::SetNull(result, true);
		return;
	}

	auto &l_vec = args.data[0];
	auto &r_vec = args.data[1];

	const auto l_size = ListVector::GetListSize(l_vec);
	const auto r_size = ListVector::GetListSize(r_vec);

	auto &l_child = ListVector::GetEntry(l_vec);
	auto &r_child = ListVector::GetEntry(r_vec);

	const auto current_left_child_type = l_child.GetType();

	UnifiedVectorFormat l_format;
	UnifiedVectorFormat r_format;

	l_vec.ToUnifiedFormat(row_count, l_format);
	r_vec.ToUnifiedFormat(row_count, r_format);

	const auto l_entries = UnifiedVectorFormat::GetData<list_entry_t>(l_format);
	const auto r_entries = UnifiedVectorFormat::GetData<list_entry_t>(r_format);

	UnifiedVectorFormat l_child_format;
	UnifiedVectorFormat r_child_format;

	l_child.ToUnifiedFormat(l_size, l_child_format);
	r_child.ToUnifiedFormat(r_size, r_child_format);

	Vector l_sortkey_vec(LogicalType::BLOB, l_size);
	Vector r_sortkey_vec(LogicalType::BLOB, r_size);

	const OrderModifiers order_modifiers(OrderType::ASCENDING, OrderByNullType::NULLS_LAST);