diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-12-16 15:21:55 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-12-16 15:21:55 +0300 |
commit | 5ac6436c4c2673e78252509c85fe000935d9f3a3 (patch) | |
tree | b6206e60f1c8caf5c9e5955ce1047700072760cc /spec/lib | |
parent | 554bb1eb1f1aa5aa45b5e4a1ee1557da0ccc59c0 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/click_house/iterator_spec.rb | 43 | ||||
-rw-r--r-- | spec/lib/peek/views/click_house_spec.rb | 6 |
2 files changed, 45 insertions, 4 deletions
diff --git a/spec/lib/click_house/iterator_spec.rb b/spec/lib/click_house/iterator_spec.rb new file mode 100644 index 00000000000..fd054c0afe5 --- /dev/null +++ b/spec/lib/click_house/iterator_spec.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe ClickHouse::Iterator, :click_house, feature_category: :database do + let(:query_builder) { ClickHouse::QueryBuilder.new('event_authors') } + let(:connection) { ClickHouse::Connection.new(:main) } + let(:iterator) { described_class.new(query_builder: query_builder, connection: connection) } + + before do + connection.execute('INSERT INTO event_authors (author_id) SELECT number + 1 FROM numbers(10)') + end + + def collect_ids_with_batch_size(of) + [].tap do |ids| + iterator.each_batch(column: :author_id, of: of) do |scope| + query = scope.select(Arel.sql('DISTINCT author_id')).to_sql + ids.concat(connection.select(query).pluck('author_id')) + end + end + end + + it 'iterates correctly' do + expected_values = (1..10).to_a + + expect(collect_ids_with_batch_size(3)).to match_array(expected_values) + expect(collect_ids_with_batch_size(5)).to match_array(expected_values) + expect(collect_ids_with_batch_size(10)).to match_array(expected_values) + expect(collect_ids_with_batch_size(15)).to match_array(expected_values) + end + + context 'when there are no records for the given query' do + let(:query_builder) do + ClickHouse::QueryBuilder + .new('event_authors') + .where(author_id: 0) + end + + it 'returns no data' do + expect(collect_ids_with_batch_size(3)).to match_array([]) + end + end +end diff --git a/spec/lib/peek/views/click_house_spec.rb b/spec/lib/peek/views/click_house_spec.rb index 1ff49afd728..f7cecbaac88 100644 --- a/spec/lib/peek/views/click_house_spec.rb +++ b/spec/lib/peek/views/click_house_spec.rb @@ -34,13 +34,11 @@ RSpec.describe Peek::Views::ClickHouse, :click_house, :request_store, feature_ca }), a_hash_including({ sql: 'INSERT INTO events (id) VALUES (1)', - database: 'database: main', - statistics: include('written_rows=>"1"') + database: 'database: main' }), a_hash_including({ sql: 'INSERT INTO events (id) FORMAT CSV', - database: 'database: main', - statistics: include('written_rows=>"2"') + database: 'database: main' }) ]) end |