Skip to content

Commit e5955a0

Browse files
vdittgenxjunior
andauthored
[Nexus][ORA-950] Improve params handling on Nitro queries (#345)
Improve the way TrinoAdapter accepts query condition keys. Today it requires a Sequel obj as key: conditions = { Sequel[:trx_month] => start_date..end_date } Update to support string keys in Nitro: conditions = { "trx_month" => start_date..end_date } [Runway story](https://runway.powerhrg.com/backlog_items/ORA-950) --------- Co-authored-by: Carlos Palhares <[email protected]>
1 parent f87205b commit e5955a0

File tree

6 files changed

+25
-4
lines changed

6 files changed

+25
-4
lines changed

packages/data_conduit/Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ PATH
1111
PATH
1212
remote: .
1313
specs:
14-
data_conduit (0.1.1)
14+
data_conduit (0.1.2)
1515
activesupport (~> 7.0)
1616
rest-client (~> 2.1)
1717
securerandom (~> 0.2.2)

packages/data_conduit/bin/console

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# frozen_string_literal: true
33

44
require "bundler/setup"
5-
require "trino/connector"
65

76
require "irb"
87
IRB.start(__FILE__)

packages/data_conduit/docs/CHANGELOG

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## [0.1.2] - 2025-05-30
2+
3+
- Improve conditions key handling for the TrinoAdapter [#345](https://github.com/powerhome/power-tools/pull/345)
4+
15
## [0.1.1] - 2025-05-13
26

37
- Improve config params handling

packages/data_conduit/lib/data_conduit/adapters/trino_repository.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,19 @@ def build_query
6565
raise ArgumentError, "Conditions must be provided as a Hash for safe query building"
6666
end
6767

68-
dataset = dataset.where(conditions)
68+
converted_conditions = convert_string_keys(conditions)
69+
dataset = dataset.where(converted_conditions)
6970
end
7071

7172
dataset.sql
7273
end
7374

75+
def convert_string_keys(conditions_hash)
76+
conditions_hash.transform_keys do |key|
77+
key.is_a?(String) || key.is_a?(Symbol) ? Sequel[key.to_sym] : key
78+
end
79+
end
80+
7481
def process_response(initial_response)
7582
result_data = []
7683
result_columns = nil
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module DataConduit
4-
VERSION = "0.1.1"
4+
VERSION = "0.1.2"
55
end

packages/data_conduit/spec/data_conduit/adapters/trino_repository_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,17 @@
6565
end
6666
end
6767

68+
describe "#build_query" do
69+
context "when the condition key is a String" do
70+
let(:conditions) { { "status" => "active" } }
71+
72+
it "converts the key and still builds the correct SQL" do
73+
sql = repository.send(:build_query)
74+
expect(sql).to eq("SELECT * FROM #{table_name} WHERE (status = 'active')")
75+
end
76+
end
77+
end
78+
6879
describe "#query" do
6980
let(:query_url) { "#{server}/v1/statement" }
7081
let(:next_url) { "#{server}/v1/statement/20240101_1" }

0 commit comments

Comments
 (0)