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 58 58: def from(*source, &block) 59: virtual_row_columns(source, block) 60: 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? 61: return super(*source, &nil) if !lateral || lateral.empty? 62: 63: ds = from(*source) 64: lateral.each do |l| 65: l = if l.is_a?(Sequel::SQL::AliasedExpression) 66: l.expression.clone(:lateral=>nil).as(l.alias) 67: else 68: l.clone(:lateral=>nil) 69: end 70: ds = ds.cross_apply(l) 71: end 72: ds 73: 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 37 37: def join_table(type, table, expr=nil, *) 38: if table.is_a?(Dataset) && table.opts[:lateral] 39: table = table.clone(:lateral=>nil) 40: case type 41: when :inner 42: type = :cross_apply 43: table = table.where(expr) 44: expr = nil 45: when :cross 46: type = :cross_apply 47: when :left, :left_outer 48: type = :outer_apply 49: table = table.where(expr) 50: expr = nil 51: end 52: end 53: super 54: end