From 65231038e87b38154dfc938a1b150fc559bbdc46 Mon Sep 17 00:00:00 2001 From: Gabriel Date: Thu, 16 Apr 2026 12:08:20 -0300 Subject: [PATCH] fix(Record): use wildcard for missing partition keys in where() When where() is called without specifying all partition_keys, the path now uses 'key=*' wildcards instead of empty values like 'key='. Closes #1 --- Gemfile.lock | 2 +- lib/data_drain/record.rb | 5 ++++- spec/data_drain/record_spec.rb | 18 ++++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 30696cd..0128d06 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - data_drain (0.5.0) + data_drain (0.5.1) activemodel (>= 6.0) aws-sdk-glue (~> 1.0) aws-sdk-s3 (~> 1.114) diff --git a/lib/data_drain/record.rb b/lib/data_drain/record.rb index 0f65ad7..b36ace5 100644 --- a/lib/data_drain/record.rb +++ b/lib/data_drain/record.rb @@ -131,7 +131,10 @@ class << self # @param partitions [Hash] # @return [String] def build_query_path(partitions) - partition_path = partition_keys.map { |k| "#{k}=#{partitions[k.to_sym] || partitions[k.to_s]}" }.join("/") + partition_path = partition_keys.map do |k| + val = partitions.key?(k.to_sym) ? partitions[k.to_sym] : partitions[k.to_s] + val.nil? || val.to_s.empty? ? "#{k}=*" : "#{k}=#{val}" + end.join("/") DataDrain::Storage.adapter.build_path(bucket, folder_name, partition_path) end diff --git a/spec/data_drain/record_spec.rb b/spec/data_drain/record_spec.rb index 8b8c8af..78a5721 100644 --- a/spec/data_drain/record_spec.rb +++ b/spec/data_drain/record_spec.rb @@ -206,5 +206,23 @@ expect(path).to include("year=2026") expect(path).to include("month=3") end + + it "usa wildcard cuando falta una partition key" do + path = record_class.send(:build_query_path, { year: 2026 }) + expect(path).to include("year=2026") + expect(path).to include("month=*") + end + + it "usa wildcards para todas las partition keys faltantes" do + path = record_class.send(:build_query_path, {}) + expect(path).to include("year=*") + expect(path).to include("month=*") + end + + it "trata valor cero (falsy) como valor legitimo, no como ausente" do + path = record_class.send(:build_query_path, { year: 2026, month: 0 }) + expect(path).to include("year=2026") + expect(path).to include("month=0") + end end end