Module: DWH::Behaviors

Included in:
Adapters::Adapter
Defined in:
lib/dwh/behaviors.rb

Overview

The Behaviors module will help us write SQL queries that are optimized for the target database. These are setup primarily for the purposes of Strata. However, any sql writer can use this to write better sql.

For exmaple temp_table_type will tell us what the preferred temporary table strategy should be. intermediate_measure_filter? will let us know if an aggregation should be filtered in a CTE, final pass, or both.

Instance Method Summary collapse

Instance Method Details

#apply_advanced_filtering_on_array_projections?Boolean

When an array dimension is projected and it is filtered in the where clause, some db's like Druid needs a having clause to ensure the projected set matches the filtered set.

Returns:

  • (Boolean)


32
33
34
# File 'lib/dwh/behaviors.rb', line 32

def apply_advanced_filtering_on_array_projections?
  settings[:apply_advanced_filtering_on_array_projections]
end

#cross_universe_measure_filtering_strategyObject

Whether to apply a measure filter to intermediate stages and final pass when appropriate. This is the case of multi universe query with measure filter. Default behavior is to apply the filter in the intermediate stage and final pass.



55
56
57
# File 'lib/dwh/behaviors.rb', line 55

def cross_universe_measure_filtering_strategy
  settings[:cross_universe_measure_filtering_strategy]
end

#extend_ending_date_to_last_hour_of_day?Boolean

In druid when you do specific time range you need to apply the last hour of the day to the date value to get all inclusive data for that date.

Returns:

  • (Boolean)


14
15
16
# File 'lib/dwh/behaviors.rb', line 14

def extend_ending_date_to_last_hour_of_day?
  settings[:extend_ending_date_to_last_hour_of_day]
end

#final_measure_filter?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/dwh/behaviors.rb', line 63

def final_measure_filter?
  %w[both final].include?(settings[:cross_universe_measure_filtering_strategy])
end

#final_pass_measure_join_typeObject

When measures from multiple fact universes are combined they need to be merged in a Merge stage SQL statement. The components is typically combined by Full Outer Join but could be modified as needed.



40
41
42
# File 'lib/dwh/behaviors.rb', line 40

def final_pass_measure_join_type
  settings[:final_pass_measure_join_type]
end

#greedy_apply_date_filtersObject

When a filter on a Date time field can be applied to multiple tables in the join tree should we apply to all of them or just the first one.



47
48
49
# File 'lib/dwh/behaviors.rb', line 47

def greedy_apply_date_filters
  settings[:greedy_apply_date_filters]
end

#intermediate_measure_filter?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/dwh/behaviors.rb', line 59

def intermediate_measure_filter?
  %w[both intermediate].include?(settings[:cross_universe_measure_filtering_strategy])
end

#temp_table_prefixObject



24
25
26
# File 'lib/dwh/behaviors.rb', line 24

def temp_table_prefix
  settings[:temp_table_prefix]
end

#temp_table_typeObject

Defines how intermediate queries should be handled. Could be one off cte, subquery, temp (future view, permanent)



20
21
22
# File 'lib/dwh/behaviors.rb', line 20

def temp_table_type
  settings[:temp_table_type]
end