Class: ConceptQL::Operators::TrimDateStart
- Inherits:
-
TemporalOperator
- Object
- Operator
- BinaryOperatorOperator
- TemporalOperator
- ConceptQL::Operators::TrimDateStart
- Defined in:
- lib/conceptql/operators/trim_date_start.rb
Overview
Trims the start_date of the LHS set of results by the RHS’s latest end_date (per person) If a the RHS contains an end_date that comes after the LHS’s end_date that LHS result is completely discarded.
If there is no RHS result for an LHS result, the LHS result is passed thru unaffected.
If the RHS result’s end_date is earlier than the LHS start_date, the LHS result is passed thru unaffected.
Instance Attribute Summary
Attributes inherited from BinaryOperatorOperator
Attributes inherited from Operator
#arguments, #errors, #nodifier, #options, #upstreams, #values
Instance Method Summary collapse
Methods inherited from TemporalOperator
#add_occurrences_condition, #add_option_conditions, #add_within_condition, #inclusive?, #left_stream, #right_stream, #within_check_after?, #within_check_before?, #within_column, within_skip
Methods inherited from BinaryOperatorOperator
#code_list, #display_name, #upstreams
Methods inherited from Operator
#annotate, #cast_column, #code_list, codes_should_match, #columns, #create_upstreams, #data_model, #database_type, default_query_columns, #domains, #dup_values, #dynamic_columns, #evaluate, inherited, #initialize, #inspect, #label, new, #operator_name, #optimized, query_columns, register, require_column, #required_columns, #scope, #select_it, #setup_select, #sql, #stream, #to_op, #unionable?, #upstreams_valid?, #valid?
Methods included from Metadatable
#allows_many_upstreams, #allows_one_upstream, #argument, #auto_label, #basic_type, #category, #derive_metadata_from_validations, #desc, #domains, #get_desc, #humanized_class_name, #inherited, #just_class_name, #no_desc, #option, #predominant_domains, #pref_name, #preferred_name, #reset_categories, #standard_description, #to_metadata, #validate_at_least_one_upstream_to_metadata, #validate_at_most_one_upstream_to_metadata, #validate_no_arguments_to_metadata, #validate_no_upstreams_to_metadata, #validate_one_upstream_to_metadata, #validate_required_options_to_metadata, #warn_about_missing_metadata
Constructor Details
This class inherits a constructor from ConceptQL::Operators::Operator
Instance Method Details
#query(db) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/conceptql/operators/trim_date_start.rb', line 34 def query(db) grouped_right = db.from(right_stream(db)).select_group(:person_id).select_append(Sequel.as(Sequel.function(:max, :end_date), :end_date)) where_criteria = Sequel.expr { l__end_date >= r__end_date } where_criteria = where_criteria.|(r__end_date: nil) # If the RHS's min start date is less than the LHS start date, # the entire LHS date range is truncated, which implies the row itself # is ineligible to pass thru ds = db.from(left_stream(db)) .join(Sequel.as(grouped_right, :r), l__person_id: :r__person_id) .where(where_criteria) .select(*new_columns) .select_append(Sequel.as(Sequel.function(:greatest, :l__start_date, :r__end_date), :start_date)) ds = add_option_conditions(ds) ds.from_self end |