Class: Cassandra::Aggregate

Inherits:
Object
  • Object
show all
Defined in:
lib/cassandra/aggregate.rb

Overview

Represents a cassandra user defined aggregate

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#argument_typesArray<Cassandra::Type> (readonly)

Returns aggregate argument types.

Returns:



32
33
34
# File 'lib/cassandra/aggregate.rb', line 32

def argument_types
  @argument_types
end

#final_functionCassandra::Function (readonly)

Returns the final function used by this aggregate.

Returns:



40
41
42
# File 'lib/cassandra/aggregate.rb', line 40

def final_function
  @final_function
end

#initial_stateObject? (readonly)

Returns the initial value of the aggregate state or nil.

Returns:

  • (Object, nil)

    the initial value of the aggregate state or nil



36
37
38
# File 'lib/cassandra/aggregate.rb', line 36

def initial_state
  @initial_state
end

#nameString (readonly)

Returns aggregate name.

Returns:

  • (String)

    aggregate name



28
29
30
# File 'lib/cassandra/aggregate.rb', line 28

def name
  @name
end

#state_functionCassandra::Function (readonly)

Returns the state function used by this aggregate.

Returns:



38
39
40
# File 'lib/cassandra/aggregate.rb', line 38

def state_function
  @state_function
end

#state_typeCassandra::Type (readonly)

Returns aggregate state type.

Returns:



34
35
36
# File 'lib/cassandra/aggregate.rb', line 34

def state_type
  @state_type
end

#typeCassandra::Type (readonly)

Returns aggregate return type.

Returns:



30
31
32
# File 'lib/cassandra/aggregate.rb', line 30

def type
  @type
end

Instance Method Details

#to_cqlString

Returns a cql representation of this aggregate.

Returns:

  • (String)

    a cql representation of this aggregate



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/cassandra/aggregate.rb', line 104

def to_cql
  cql = 'CREATE AGGREGATE simplex.average('
  first = true
  @argument_types.each do |type|
    if first
      first = false
    else
      cql << ', '
    end
    cql << type.to_s
  end
  cql << ')'
  cql << "\n  SFUNC #{@state_function.name}"
  cql << "\n  STYPE #{@state_type}"
  cql << "\n  FINALFUNC #{@final_function.name}" if @final_function
  cql << "\n  INITCOND #{@initial_state}"
  cql << ';'
end