Sha256: d164017cb5f2d45e4c2286e7d66d5ca29b7c779335c99746e9d4bb84d9e5d77f

Contents?: true

Size: 695 Bytes

Versions: 18

Compression:

Stored size: 695 Bytes

Contents

module Chicago
  module ETL
    class EtlBatchIdDatasetFilter
      def initialize(etl_batch_id)
        @etl_batch_id = etl_batch_id
      end

      # Returns a new dataset, filtered by all tables where the etl
      # batch id matches.
      def filter(dataset)
        dataset.filter(conditions(filterable_tables(dataset)))
      end

      private

      def filterable_tables(dataset)
        dataset.dependant_tables.select {|t|
          dataset.db.schema(t).map(&:first).include?(:etl_batch_id)
        }
      end

      def conditions(tables)
        tables.
          map {|t| {:etl_batch_id.qualify(t) => @etl_batch_id} }.
          inject {|a,b| a | b}
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
chicago-etl-0.3.0 spec/etl/etl_batch_id_dataset_filter.rb
chicago-etl-0.2.7 spec/etl/etl_batch_id_dataset_filter.rb
chicago-etl-0.2.5 spec/etl/etl_batch_id_dataset_filter.rb
chicago-etl-0.2.4 spec/etl/etl_batch_id_dataset_filter.rb
chicago-etl-0.2.3 spec/etl/etl_batch_id_dataset_filter.rb
chicago-etl-0.2.2 spec/etl/etl_batch_id_dataset_filter.rb
chicago-etl-0.2.1 spec/etl/etl_batch_id_dataset_filter.rb
chicago-etl-0.2.0 spec/etl/etl_batch_id_dataset_filter.rb
chicago-etl-0.1.4 spec/etl/etl_batch_id_dataset_filter.rb
chicago-etl-0.1.3 spec/etl/etl_batch_id_dataset_filter.rb
chicago-etl-0.1.2 spec/etl/etl_batch_id_dataset_filter.rb
chicago-etl-0.1.1 spec/etl/etl_batch_id_dataset_filter.rb
chicago-etl-0.1.0 spec/etl/etl_batch_id_dataset_filter.rb
chicago-etl-0.0.13 spec/etl/etl_batch_id_dataset_filter.rb
chicago-etl-0.0.12 spec/etl/etl_batch_id_dataset_filter.rb
chicago-etl-0.0.11 spec/etl/etl_batch_id_dataset_filter.rb
chicago-etl-0.0.10 spec/etl/etl_batch_id_dataset_filter.rb
chicago-etl-0.0.9 spec/etl/etl_batch_id_dataset_filter.rb