Class: Nfcollector::Partition

Inherits:
Object
  • Object
show all
Defined in:
lib/nfcollector/partition.rb

Direct Known Subclasses

CategoryPartition, WeblogPartition

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, account_id, headers) ⇒ Partition

Create a new partition with the given values

Parameters:

  • values (Array)


28
29
30
31
32
33
# File 'lib/nfcollector/partition.rb', line 28

def initialize(value, , headers)
  @value      = value
  @account_id = 
  @headers    = headers
  @rows       = []
end

Instance Attribute Details

#account_idObject (readonly)

Returns the value of attribute account_id.



7
8
9
# File 'lib/nfcollector/partition.rb', line 7

def 
  @account_id
end

#headersObject (readonly)

Returns the value of attribute headers.



6
7
8
# File 'lib/nfcollector/partition.rb', line 6

def headers
  @headers
end

#partition_idObject (readonly)

Returns the value of attribute partition_id.



5
6
7
# File 'lib/nfcollector/partition.rb', line 5

def partition_id
  @partition_id
end

#rowsObject (readonly)

Returns the value of attribute rows.



4
5
6
# File 'lib/nfcollector/partition.rb', line 4

def rows
  @rows
end

Class Method Details

.get_partitioner(account_id, partition_key_index, headers) ⇒ Object

Instantiates a partitioner that will generate partitions of this type

Parameters:

  • account_id (Integer, String)

    the account_id for which we are processing data

  • partition_key_index (Integer)

    the index in each row of the partition key

  • headers (Array)

    an array of headers for writing the data to file



16
17
18
19
20
# File 'lib/nfcollector/partition.rb', line 16

def self.get_partitioner(, partition_key_index, headers)
  Partitioner.new(self, , partition_key_index).tap do |part|
    part.set_headers!(headers)
  end
end

Instance Method Details

#add_row(row) ⇒ Object

Adds a row to the partition

Parameters:

  • row (MappedRow)


42
43
44
45
# File 'lib/nfcollector/partition.rb', line 42

def add_row(row)
  # TODO: Is there a cleaner way to do this??
  @rows << [ @account_id ] + row
end

#file_nameObject



57
58
59
# File 'lib/nfcollector/partition.rb', line 57

def file_name
  @file_name ||= File.expand_path("#{table_name}_#{randstr}.copy", Configuration.output_dir)
end

#keysHash

Returns a set of keys used to generate the table for this partition.

Returns:

  • (Hash)

    a set of keys used to generate the table for this partition

Raises:

  • (NotImplemented)


63
64
65
# File 'lib/nfcollector/partition.rb', line 63

def keys
  raise NotImplemented
end

#table_nameObject

Return the table name that should be used for the data in this partition

Parameters:

  • account_id (Integer, String)


51
52
53
54
55
# File 'lib/nfcollector/partition.rb', line 51

def table_name
  return @table_name if @table_name
  partition = ar_klass.partitions.find_or_create_for(keys)
  @table_name = partition.nil? ? ar_klass.table_name : partition.name
end