Class: Groonga::Command::Load

Inherits:
Base
  • Object
show all
Defined in:
lib/groonga/command/load.rb

Defined Under Namespace

Classes: ArrowTableBuilder

Instance Attribute Summary collapse

Attributes inherited from Base

#arguments, #command_name, #original_format, #original_source, #path_prefix

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#==, #[], #[]=, #command_format?, #key?, #name, #output_type, #request_id, #to_command_format, #to_elasticsearch_format, #to_s, #to_uri_format, #uri_format?

Constructor Details

#initialize(*argumetns) ⇒ Load

Returns a new instance of Load.



52
53
54
55
56
57
# File 'lib/groonga/command/load.rb', line 52

def initialize(*argumetns)
  super
  @table = nil
  @values = nil
  @columns = nil
end

Instance Attribute Details

#columnsObject



70
71
72
# File 'lib/groonga/command/load.rb', line 70

def columns
  @columns ||= parse_columns(self[:columns])
end

#tableString

Returns The table name to be loaded.

Returns:

  • (String)

    The table name to be loaded.

Since:

  • 1.3.5



62
63
64
# File 'lib/groonga/command/load.rb', line 62

def table
  @table ||= self[:table]
end

#valuesObject



66
67
68
# File 'lib/groonga/command/load.rb', line 66

def values
  @values ||= parse_values(self[:values])
end

Class Method Details

.command_nameObject



30
31
32
# File 'lib/groonga/command/load.rb', line 30

def command_name
  "load"
end

.parameter_namesObject



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/groonga/command/load.rb', line 34

def parameter_names
  [
    :values,
    :table,
    :columns,
    :ifexists,
    :input_type,
    :each,
    :output_ids,
  ]
end

Instance Method Details

#build_arrow_tableArrow::Table?

Builds Arrow::Table for data of this load command.

This requires red-arrow gem. If red-arrow gem isn't available, NotImplementedError is raised.

Returns:

  • (Arrow::Table, nil)

    Arrow::Table if there is one or more records, nil otherwise.

Since:

  • 1.4.6



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/groonga/command/load.rb', line 83

def build_arrow_table
  unless defined?(::Arrow)
    raise NotImplementedError, "red-arrow is required"
  end
  source_lines = (original_source || "").lines
  if source_lines.size >= 2
    if /\s--columns\s/ =~ source_lines.first
      target_columns = columns
    else
      target_columns = nil
    end
    target_values = JSON.parse(source_lines[1..-1].join(""))
  else
    target_columns = columns
    target_values = values
  end
  builder = ArrowTableBuilder.new(target_columns, target_values)
  builder.build
end

#output_ids?Boolean

Returns true if output_ids value is "yes".

Returns:

  • (Boolean)

    true if output_ids value is "yes".

Since:

  • 1.3.0



106
107
108
109
110
# File 'lib/groonga/command/load.rb', line 106

def output_ids?
  boolean_value(:output_ids,
                default: false,
                invalid: false)
end