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