Skip to content

Commit

Permalink
Merge pull request #13 from Multiwoven/fix/skip-cursor-field-empty-ee
Browse files Browse the repository at this point in the history
fix: skip cursor query builder for cursor empty
  • Loading branch information
afthabvp authored May 7, 2024
2 parents 4776be6 + c5afd78 commit d72d168
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion server/lib/reverse_etl/utils/batch_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def self.execute_in_batches(params)
params[:sync_config].limit = params[:batch_size]
params[:sync_config].offset = current_offset

if initial_sync_config.cursor_field
if initial_sync_config.cursor_field.present?
query_with_cursor = CursorQueryBuilder.build_cursor_query(initial_sync_config, last_cursor_field_value)
params[:sync_config] = build_cursor_sync_config(params[:sync_config], query_with_cursor)
end
Expand Down
38 changes: 38 additions & 0 deletions server/spec/lib/reverse_etl/utils/batch_query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,44 @@ module Utils # rubocop:disable Metrics/ModuleLength
expect(results.last.size).to eq(100)
end
end
context "when both cursor_field is empty" do
let(:existing_query) { "SELECT * FROM table" }
let(:source) { create(:connector, connector_type: "source", connector_name: "Snowflake") }
let(:destination) { create(:connector, connector_type: "destination") }
let!(:catalog) { create(:catalog, connector: destination) }
let(:model) { create(:model, connector: source, query: existing_query) }
let(:sync) do
create(:sync, model:, source:, destination:, cursor_field: "")
end
let(:record) do
Multiwoven::Integrations::Protocol::RecordMessage.new(data: { "id" => 1, "email" => "[email protected]",
"first_name" => "John",
"Last Name" => "Doe" },
emitted_at: DateTime.now.to_i).to_multiwoven_message
end
let(:record1) do
Multiwoven::Integrations::Protocol::RecordMessage.new(data: { "id" => 1, "email" => "[email protected]",
"first_name" => "John",
"Last Name" => "Doe" },
emitted_at: DateTime.now.to_i).to_multiwoven_message
end

it "executes batches and not call CursorQueryBuilder for cursor_field is empty" do
params = {
offset: 0,
limit: 100,
batch_size: 100,
sync_config: sync.to_protocol,
client:
}
allow(client).to receive(:read).and_return(*Array.new(1, [record]), [])
expect(CursorQueryBuilder).not_to receive(:build_cursor_query).with(sync.to_protocol, "")
results = []
BatchQuery.execute_in_batches(params) do |result, _current_offset, _last_cursor_field_value|
results << result
end
end
end
context "when both cursor_field is present" do
let(:existing_query) { "SELECT * FROM table" }
let(:source) { create(:connector, connector_type: "source", connector_name: "Snowflake") }
Expand Down

0 comments on commit d72d168

Please sign in to comment.