Module | Sequel::MSSQL::EmulateLateralWithApply |
In: |
lib/sequel/extensions/mssql_emulate_lateral_with_apply.rb
|
When a FROM entry uses a LATERAL subquery, convert that entry into a CROSS APPLY.
# File lib/sequel/extensions/mssql_emulate_lateral_with_apply.rb, line 54 54: def from(*source, &block) 55: virtual_row_columns(source, block) 56: lateral, source = source.partition{|t| t.is_a?(Sequel::Dataset) && t.opts[:lateral] || (t.is_a?(Sequel::SQL::AliasedExpression) && t.expression.is_a?(Sequel::Dataset) && t.expression.opts[:lateral])} unless source.empty? 57: return super(*source, &nil) if !lateral || lateral.empty? 58: 59: ds = from(*source) 60: lateral.each do |l| 61: l = if l.is_a?(Sequel::SQL::AliasedExpression) 62: l.expression.clone(:lateral=>nil).as(l.alias) 63: else 64: l.clone(:lateral=>nil) 65: end 66: ds = ds.cross_apply(l) 67: end 68: ds 69: end
If the table is a dataset that uses LATERAL, convert it to a CROSS APPLY if it is a INNER or CROSS JOIN, and an OUTER APPLY if it is a LEFT JOIN.
# File lib/sequel/extensions/mssql_emulate_lateral_with_apply.rb, line 33 33: def join_table(type, table, expr=nil, *) 34: if table.is_a?(Dataset) && table.opts[:lateral] 35: table = table.clone(:lateral=>nil) 36: case type 37: when :inner 38: type = :cross_apply 39: table = table.where(expr) 40: expr = nil 41: when :cross 42: type = :cross_apply 43: when :left, :left_outer 44: type = :outer_apply 45: table = table.where(expr) 46: expr = nil 47: end 48: end 49: super 50: end