Module: DWH::Functions::Arrays

Included in:
DWH::Functions
Defined in:
lib/dwh/functions/arrays.rb

Overview

Operations on array columns. Mostly used in where clauses

Instance Method Summary collapse

Instance Method Details

#array_exclude_list(exp, list) ⇒ Object

Generates sql test to see if any values from the passed in list is NOT in the array column/exp.

Parameters:

  • exp (String)
    • sql expression
  • list (String)
    • comma separated list

Raises:

  • UnsupportedCapability if the db doesn't support array functions.



23
24
25
26
27
# File 'lib/dwh/functions/arrays.rb', line 23

def array_exclude_list(exp, list)
  raise UnsupportedCapability unless supports_array_functions?

  gsk(:array_exclude_list).gsub(/@exp/i, exp).gsub(/@list/i, list)
end

#array_in_list(exp, list) ⇒ Object

Generates sql test to see if any values from the passed in list is in the array column/exp.

Parameters:

  • exp (String)
    • sql expression
  • list (String)
    • comma separated list

Raises:

  • UnsupportedCapability if the db doesn't support array functions.



11
12
13
14
15
# File 'lib/dwh/functions/arrays.rb', line 11

def array_in_list(exp, list)
  raise UnsupportedCapability unless supports_array_functions?

  gsk(:array_in_list).gsub(/@exp/i, exp).gsub(/@list/i, list)
end

#array_unnest_join(exp, table_alias) ⇒ Object

Explode an array. This should be used in a join expression.

Parameters:

  • exp (String)

    the column/expression that will be Explode

  • table_alias (String)

    the alias of the exploded array

Raises:

  • UnsupportedCapability if the db doesn't support array functions.



33
34
35
36
37
38
39
# File 'lib/dwh/functions/arrays.rb', line 33

def array_unnest_join(exp, table_alias)
  raise UnsupportedCapability unless supports_array_functions?

  gsk(:array_unnest_join)
    .gsub(/@exp/i, exp)
    .gsub(/@alias/i, table_alias)
end