Module: ActiveRecord::ConnectionAdapters::PinotAdapter::TableStructure

Defined in:
lib/active_record/connection_adapters/pinot_adapter/table_structure.rb

Class Method Summary collapse

Class Method Details

.from_schema(schema) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/active_record/connection_adapters/pinot_adapter/table_structure.rb', line 5

def self.from_schema(schema)
  fields = []
  schema["dimensionFieldSpecs"].each do |f|
    fields << {
      "name" => f["name"],
      "type" => f["dataType"],
      "pinot_type" => "dimension"
    }
  end
  schema["metricFieldSpecs"] ||= []
  schema["metricFieldSpecs"].each do |f|
    fields << {
      "name" => f["name"],
      "type" => f["dataType"],
      "pinot_type" => "metric"
    }
  end
  schema["dateTimeFieldSpecs"].each do |f|
    fields << {
      "name" => f.delete("name"),
      "type" => f.delete("dataType"),
      "pinot_type" => "dateTime",
      "metadata" => f
    }
  end
  # normalize values
  fields.each do |f|
    f["type"] = normalize_type(f["type"])
  end
  # set primary keys
  primary_key_columns = schema["primaryKeyColumns"] || []
  primary_key_columns.each do |pk|
    pk_fields = fields.select { |x| x["name"] == pk }
    pk_fields.each { |field| field["pk"] = 1 }
  end
  fields
end

.normalize_type(type) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/active_record/connection_adapters/pinot_adapter/table_structure.rb', line 43

def self.normalize_type(type)
  case type
  when "INT" then "integer"
  when "STRING" then "varchar"
  else
    type
  end
end