Class: Droonga::Catalog::Schema::Column

Inherits:
Object
  • Object
show all
Defined in:
lib/droonga/catalog/schema.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table, name, data) ⇒ Column

Returns a new instance of Column.



69
70
71
72
73
74
75
# File 'lib/droonga/catalog/schema.rb', line 69

def initialize(table, name, data)
  @table = table
  @name = name
  @data = data
  @vector_options = ColumnVectorOptions.new(vector_options_data)
  @index_options = ColumnIndexOptions.new(index_options_data)
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



68
69
70
# File 'lib/droonga/catalog/schema.rb', line 68

def data
  @data
end

#index_optionsObject (readonly)

Returns the value of attribute index_options.



68
69
70
# File 'lib/droonga/catalog/schema.rb', line 68

def index_options
  @index_options
end

#nameObject (readonly)

Returns the value of attribute name.



68
69
70
# File 'lib/droonga/catalog/schema.rb', line 68

def name
  @name
end

#tableObject (readonly)

Returns the value of attribute table.



68
69
70
# File 'lib/droonga/catalog/schema.rb', line 68

def table
  @table
end

#vector_optionsObject (readonly)

Returns the value of attribute vector_options.



68
69
70
# File 'lib/droonga/catalog/schema.rb', line 68

def vector_options
  @vector_options
end

Instance Method Details

#==(other) ⇒ Object



77
78
79
80
81
# File 'lib/droonga/catalog/schema.rb', line 77

def ==(other)
  self.class == other.class and
    name == other.name and
    data == other.data
end

#flagsObject



100
101
102
# File 'lib/droonga/catalog/schema.rb', line 100

def flags
  [type_flag] + vector_options.flags + index_options.flags
end

#to_column_create_bodyObject



116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/droonga/catalog/schema.rb', line 116

def to_column_create_body
  body = {
    "name"  => name,
    "table" => table,
    "flags" => flags.join("|"),
    "type"  => value_type_groonga
  }
  sources = index_options.sources
  if sources
    body["source"] = sources.join(",")
  end

  body
end

#typeObject



83
84
85
# File 'lib/droonga/catalog/schema.rb', line 83

def type
  @data["type"] || "Scalar"
end

#type_flagObject



87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/droonga/catalog/schema.rb', line 87

def type_flag
  case type
  when "Scalar"
    "COLUMN_SCALAR"
  when "Vector"
    "COLUMN_VECTOR"
  when "Index"
    "COLUMN_INDEX"
  else
    # TODO raise appropriate error
  end
end

#value_typeObject



104
105
106
# File 'lib/droonga/catalog/schema.rb', line 104

def value_type
  @data["valueType"]
end

#value_type_groongaObject



108
109
110
111
112
113
114
# File 'lib/droonga/catalog/schema.rb', line 108

def value_type_groonga
  if value_type == "Integer"
    "Int64"
  else
    value_type
  end
end