lib/alephant/lookup/lookup_query.rb in alephant-lookup-2.0.2 vs lib/alephant/lookup/lookup_query.rb in alephant-lookup-2.1.0

- old
+ new

@@ -7,13 +7,15 @@ class LookupQuery include Logger attr_reader :table_name, :lookup_location def initialize(table_name, component_id, opts, batch_version) - @client = AWS::DynamoDB::Client::V20120810.new - @table_name = table_name - @lookup_location = LookupLocation.new(component_id, opts, batch_version) + options = {} + options[:endpoint] = ENV['AWS_DYNAMO_DB_ENDPOINT'] if ENV['AWS_DYNAMO_DB_ENDPOINT'] + @client = Aws::DynamoDB::Client.new(options) + @table_name = table_name + @lookup_location = LookupLocation.new(component_id, opts, batch_version) logger.info( "event" => "LookupQueryInitialized", "tableName" => table_name, "componentId" => component_id, @@ -38,31 +40,24 @@ end private def s3_location_from(result) - result[:count] == 1 ? result[:member].first["location"][:s] : nil + result.count == 1 ? result.items.first['location'] : nil end def to_q { :table_name => table_name, :consistent_read => true, - :select => "SPECIFIC_ATTRIBUTES", - :attributes_to_get => ["location"], - :key_conditions => { - "component_key" => { - :comparison_operator => "EQ", - :attribute_value_list => [ - { "s" => @lookup_location.component_key } - ], - }, - "batch_version" => { - :comparison_operator => "EQ", - :attribute_value_list => [ - { "n" => @lookup_location.batch_version.to_s } - ] - } + :projection_expression => '#loc', + :expression_attribute_names => { + '#loc' => 'location' + }, + :key_condition_expression => 'component_key = :component_key AND batch_version = :batch_version', + :expression_attribute_values => { + ':component_key' => @lookup_location.component_key, + ':batch_version' => @lookup_location.batch_version.to_i # @TODO: Verify if this is nil as this would be 0 } } end end end