Class: Arrow::Aggregation

Inherits:
Object
  • Object
show all
Defined in:
lib/arrow/aggregation.rb

Class Method Summary collapse

Class Method Details

.try_convert(value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/arrow/aggregation.rb', line 22

def try_convert(value)
  case value
  when Hash
    function = value[:function]
    return nil if function.nil?
    function = function.to_s if function.is_a?(Symbol)
    return nil unless function.is_a?(String)
    # TODO: Improve this when we have non hash based aggregate function
    function = "hash_#{function}" unless function.start_with?("hash_")
    options = value[:options]
    input = value[:input]
    return nil if input.nil?
    output = value[:output]
    if output.nil?
      normalized_function = function.gsub(/\Ahash_/, "")
      output = "#{normalized_function}(#{input})"
    end
    new(function, options, input, output)
  else
    nil
  end
end