Class: StructuredDataToSql::Json::TableProfile

Inherits:
Object
  • Object
show all
Defined in:
lib/structured_data_to_sql/json/schema_inferrer.rb

Overview

Column profiles for one table, in first-observation order.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table_rel, raw_dates: false) ⇒ TableProfile

Returns a new instance of TableProfile.



105
106
107
108
109
110
# File 'lib/structured_data_to_sql/json/schema_inferrer.rb', line 105

def initialize(table_rel, raw_dates: false)
  @table_rel = table_rel
  @raw_dates = raw_dates
  @columns = {}
  @row_count = 0
end

Instance Attribute Details

#row_countObject (readonly)

Returns the value of attribute row_count.



103
104
105
# File 'lib/structured_data_to_sql/json/schema_inferrer.rb', line 103

def row_count
  @row_count
end

#table_relObject (readonly)

Returns the value of attribute table_rel.



103
104
105
# File 'lib/structured_data_to_sql/json/schema_inferrer.rb', line 103

def table_rel
  @table_rel
end

Instance Method Details

#child?Boolean

Returns:

  • (Boolean)


121
122
123
# File 'lib/structured_data_to_sql/json/schema_inferrer.rb', line 121

def child?
  !@table_rel.empty?
end

#finalizeObject



125
126
127
# File 'lib/structured_data_to_sql/json/schema_inferrer.rb', line 125

def finalize
  @columns.map { |name, profile| profile.finalize(name, @row_count) }
end

#observe_row(columns) ⇒ Object



112
113
114
115
116
117
118
119
# File 'lib/structured_data_to_sql/json/schema_inferrer.rb', line 112

def observe_row(columns)
  @row_count += 1
  columns.each do |name, value|
    (@columns[name] ||= ColumnProfile.new(raw_dates: @raw_dates)).observe(
      value
    )
  end
end