Class: BigqueryMigration::TableData

Inherits:
Object
  • Object
show all
Defined in:
lib/bigquery_migration/table_data.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(columns, rows) ⇒ TableData

Returns a new instance of TableData.



12
13
14
15
# File 'lib/bigquery_migration/table_data.rb', line 12

def initialize(columns, rows)
  @columns = columns || raise(Error, '`columns` is required.')
  @rows = rows || raise(Error, '`rows` is required.')
end

Instance Attribute Details

#columnsObject (readonly)

Returns the value of attribute columns.



6
7
8
# File 'lib/bigquery_migration/table_data.rb', line 6

def columns
  @columns
end

#rowsObject (readonly)

Returns the value of attribute rows.



6
7
8
# File 'lib/bigquery_migration/table_data.rb', line 6

def rows
  @rows
end

Instance Method Details

#loggerObject



8
9
10
# File 'lib/bigquery_migration/table_data.rb', line 8

def logger
  BigqueryMigration.logger
end

#valuesObject

format list_table_data response rows which is like

[

{ f: [
  { v: "foo" },
  { v: "1" },
  { v: [] },
  { v: "1.1" },
  { v: "true" },
  { v: "1.444435200E9" }
] },
{ f: [
  { v: "foo" },
  { v: "2" },
  { v: [
    { v: "foo" },
    { v: "bar" }
  ] },
  { v: "2.2" },
  { v: "false" },
  { v: "1.444435200E9" }
] }

]

into

[

# first row
[
  [ "foo", "1", nil, "1.1", "true", "1.444435200E9" ]
],
# second row
[
  [ "foo", "2", "foo", "2.2", "false", "1.444435200E9" ],
  [ nil, nil, "bar", nil, nil, nil ],
],

]



54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/bigquery_migration/table_data.rb', line 54

def values
  values = @rows.map do |row|
    repeated_count = repeated_count(columns: @columns, rows: row)
    formatted_row = []
    repeated_count.times do |count|
      formatted_row << format_row(columns: @columns, rows: row, count: count)
    end
    formatted_row
  end
  # flattern if there is no repeated column for backward compatibility
  values.map(&:length).max > 1 ? values : values.flatten(1)
end