SlideShare a Scribd company logo
1 of 59
Arel: Ruby Relational Algebra
                             Bryan Helmkamp
                             CTO, Efficiency 2.0
                                @brynary




Arel   http://bit.ly/ggrc-arel               brynary   brynary.com
Slides                     Twitter         My blog
Arel    http://bit.ly/ggrc-arel         brynary       brynary.com
Agenda
       1. What is Arel?
       2. Relational Algebra 101
       3. Arel with ActiveRecord 3
       4. Arel under the Hood
       5. Future Possibilities


Arel         http://bit.ly/ggrc-arel        brynary   brynary.com
What is Arel?
                                           *




                                               * Mermaids do not query databases.
                                                        (Thanks, Carl)

Arel   http://bit.ly/ggrc-arel   brynary                      brynary.com
What is Arel?
       • An object-oriented interpretation of
           relational algebra in Ruby
       • Written by Nick Kallen (Twitter)
       • First commit: December 30, 2007
       • Not an ORM!
       •   http://magicscalingsprinkles.wordpress.com/2010/01/28/why-i-wrote-arel/




Arel            http://bit.ly/ggrc-arel                 brynary                      brynary.com
Arel   http://bit.ly/ggrc-arel   brynary   brynary.com
ActiveRecord 3

                                 Arel

          Algebra                       Engines


         AR Connection Adapters

                           SQL Database

Arel   http://bit.ly/ggrc-arel          brynary   brynary.com
Relational Algebra 101



Arel     http://bit.ly/ggrc-arel   brynary   brynary.com
What’s a Relation?
       {
id:
int,
name:
string,
city:
string
}

       {
1,






“Francis”,



“NYC”







}
       {
2,






“Trotter”,



“Philly”




}
       {
3,






“Gianni”,




“LA”








}
       {
4,






“Josh”,






“NYC”







}




Arel     http://bit.ly/ggrc-arel   brynary        brynary.com
Header
       {
id:
int,
name:
string,
city:
string
}

       {
1,






“Francis”,



“NYC”







}
       {
2,






“Trotter”,



“Philly”




}
       {
3,






“Gianni”,




“LA”








}
       {
4,






“Josh”,






“NYC”







}




Arel     http://bit.ly/ggrc-arel        brynary   brynary.com
Tuples
       {
id:
int,
name:
string,
city:
string
}

       {
1,






“Francis”,



“NYC”







}
       {
2,






“Trotter”,



“Philly”




}
       {
3,






“Gianni”,




“LA”








}
       {
4,






“Josh”,






“NYC”







}




Arel     http://bit.ly/ggrc-arel            brynary   brynary.com
Core Operations
       • Selection                    • Union
       • Projection                   • Intersection
       • Join                         • Difference


Arel        http://bit.ly/ggrc-arel      brynary       brynary.com
Core Operations
       •Selection                    • Union
       • Projection                  • Intersection
       • Join                        • Difference


Arel       http://bit.ly/ggrc-arel      brynary       brynary.com
Core Operations
       • Selection                  • Union
       •Projection                  • Intersection
       • Join                       • Difference


Arel      http://bit.ly/ggrc-arel      brynary       brynary.com
Core Operations
       • Selection                    • Union
       • Projection                   • Intersection
       •Join                          • Difference


Arel        http://bit.ly/ggrc-arel      brynary       brynary.com
Core Operations
       • Selection                    •Union
       • Projection                   •Intersection
       • Join                         •Difference


Arel        http://bit.ly/ggrc-arel     brynary       brynary.com
Closure!
 relation
=
Rubyist.scoped
 #
=>
ActiveRecord::Relation

 relation
=
relation.where(:city
=>
"nyc")
 #
=>
ActiveRecord::Relation

 relation
=
relation.joins("JOIN
cities
ON
cities.id
=
city_id")
 #
=>
ActiveRecord::Relation

 relation
=
relation.limit(1)
 #
=>
ActiveRecord::Relation

 relation.to_sql
 #
=>
SELECT
*
FROM
rubyists
 




JOIN
cities
ON
cities.id
=
city_id
 




WHERE
(city_id
=
1)
LIMIT
1

Arel         http://bit.ly/ggrc-arel     brynary         brynary.com
Arel with ActiveRecord
                     (“What’s in it for me today?”)




Arel      http://bit.ly/ggrc-arel           brynary   brynary.com
Original: Hash queries

  Rubyist.find(:all,
:conditions
=>
{
  

:city
=>
"NYC",
  

:thirsty
=>
true
  })




Arel    http://bit.ly/ggrc-arel   brynary   brynary.com
Rails 2.1: Named scopes
       class
Rubyist
<
ActiveRecord::Base
       

named_scope
:nycrb,
:conditions
=>
{
       



:city
=>
"NYC"
       

}
       end

       Rubyist.nycrb.class
       #
=>
ActiveRecord::NamedScope::Scope



Arel       http://bit.ly/ggrc-arel   brynary    brynary.com
Rails 3.0: Relations

  Rubyist.where(:city
=>
"NYC")


  Rubyist.where(:city
=>
"NYC").class
  #
=>
ActiveRecord::Relation



Arel    http://bit.ly/ggrc-arel   brynary   brynary.com
Chainable and Reusable

         Rubyist.where(:city
=>
"NYC").
         

where(:thirsty
=>
true)



       nycrb
=
Rubyist.where(:city
=>
"NYC")
       nycrb.order("id
DESC").limit(10)




Arel      http://bit.ly/ggrc-arel   brynary    brynary.com
Lazy
       #
Controller
       class
RubyistsController
       

def
nycrb
       



@nycrb
=
Rubyist.where(:city
=>
"NYC")
       

end
       end


       <!‐‐
View
‐‐>
       <ul>
       

<%
@nycrb.each
do
|user|
%>
       



<li><%=
user.name
%></li>
       

<%
end
%>
       </ul>

Arel        http://bit.ly/ggrc-arel          brynary   brynary.com
Lazy
       #
Controller
       class
RubyistsController
       

def
nycrb
       



@nycrb
=
Rubyist.where(:city
=>
"NYC")
       

end
       end                        Query does not run yet


       <!‐‐
View
‐‐>
       <ul>
       

<%
@nycrb.each
do
|user|
%>
       



<li><%=
user.name
%></li>
       

<%
end
%>
       </ul>

Arel        http://bit.ly/ggrc-arel          brynary   brynary.com
Lazy
       #
Controller
       class
RubyistsController
       

def
nycrb
       



@nycrb
=
Rubyist.where(:city
=>
"NYC")
       

end
       end

                   SELECT
*
FROM
users
WHERE
city
=
'NYC'
       <!‐‐
View
‐‐>
       <ul>
       

<%
@nycrb.each
do
|user|
%>
       



<li><%=
user.name
%></li>
       

<%
end
%>
       </ul>

Arel        http://bit.ly/ggrc-arel          brynary   brynary.com
Lazy
       #
Controller
       class
RubyistsController
       

def
nycrb
       



@nycrb
=
Rubyist.where(:city
=>
"NYC")
       

end
       end

       <!‐‐
View
‐‐>
       <ul>
       

<%
cache("nycrb_people")
do
%>
       



<%
@nycrb.each
do
|user|
%>
       





<li><%=
user.name
%></li>
       



<%
end
%>
       

<%
end
%>
       </ul>
Arel        http://bit.ly/ggrc-arel          brynary   brynary.com
Lazy
       #
Controller
       class
RubyistsController
       

def
nycrb
       



@nycrb
=
Rubyist.where(:city
=>
"NYC")
       

end
       end

       <!‐‐
View
‐‐>      Cache hit
       <ul>
       

<%
cache("nycrb_people")
do
%>
       



<%
@nycrb.each
do
|user|
%>
       





<li><%=
user.name
%></li>
       



<%
end
%>
       

<%
end
%>
       </ul>
Arel        http://bit.ly/ggrc-arel          brynary   brynary.com
Lazy
       #
Controller
       class
RubyistsController
       

def
nycrb
       



@nycrb
=
Rubyist.where(:city
=>
"NYC")
       

end
       end

       <!‐‐
View
‐‐>
       <ul>                             Block is not run
       

<%
cache("nycrb_people")
do
%>
       



<%
@nycrb.each
do
|user|
%>
       





<li><%=
user.name
%></li>
       



<%
end
%>
       

<%
end
%>
       </ul>
Arel        http://bit.ly/ggrc-arel          brynary   brynary.com
Lazy
       #
Controller
       class
RubyistsController
       

def
nycrb
       



@nycrb
=
Rubyist.where(:city
=>
"NYC")
       

end
       end

       <!‐‐
View
‐‐>
       <ul>                            SELECT never run
       

<%
cache("nycrb_people")
do
%>
       



<%
@nycrb.each
do
|user|
%>
       





<li><%=
user.name
%></li>
       



<%
end
%>
       

<%
end
%>
       </ul>
Arel        http://bit.ly/ggrc-arel          brynary   brynary.com
New Finder Methods
       •   where                             •   offset

       •   having                            •   joins

       •   select                            •   includes

       •   group                             •   lock

       •   order                             •   readonly

       •   limit                             •   from



Arel               http://bit.ly/ggrc-arel         brynary   brynary.com
Quacks like ActiveRecord::Base
       •   new(attributes)               •   delete(id_or_array)

       •   create(attributes)            •   delete_all

       •   create!(attributes)           •   update(ids, updates)

       •   find(id_or_array)              •   update_all(updates)

       •   destroy(id_or_array)          •   exists?

       •   destroy_all



Arel           http://bit.ly/ggrc-arel         brynary              brynary.com
Example

   class
Rubyist
   

scope
:nycrb,
where(:city
=>
"NYC")
   end




Arel      http://bit.ly/ggrc-arel     brynary   brynary.com
Example

 class
Rubyist
 

self.scope(:nycrb,
self.where(:city
=>
"NYC"))
 end




Arel      http://bit.ly/ggrc-arel     brynary   brynary.com
Example

       Rubyist.scope
:nycrb,

       

Rubyist.where(:city
=>
"NYC")




Arel       http://bit.ly/ggrc-arel     brynary   brynary.com
Example

nycrb
=
Rubyist.where(:city
=>
"NYC")
Rubyist.scope
:nycrb,
nycrb




Arel   http://bit.ly/ggrc-arel     brynary   brynary.com
def
self.scope(name,
scope_options
=
{},
&block)


name
=
name.to_sym


valid_scope_name?(name)



extension
=
Module.new(&block)
if
block_given?



scopes[name]
=
lambda
do
|*args|




options
=
scope_options.is_a?(Proc)
?
scope_options.call(*args)
:
scope_options





relation
=
if
options.is_a?(Hash)






scoped.apply_finder_options(options)




elsif
options






scoped.merge(options)




else






scoped




end





extension
?
relation.extending(extension)
:
relation


end



singleton_class.send(:redefine_method,
name,
&scopes[name])
end



Arel              http://bit.ly/ggrc-arel          brynary               brynary.com
def
self.scope(name,
scope_options
=
{})
 

name
=
name.to_sym
 

valid_scope_name?(name)

 

scopes[name]
=
lambda
do
|*args|
 



if
scope_options.is_a?(Hash)
 





scoped.apply_finder_options(scope_options)
 



elsif
scope_options
 





scoped.merge(scope_options)
 



else
 





scoped
 



end
 

end

 

singleton_class.send(:redefine_method,
name,
&scopes[name])
 end



Arel         http://bit.ly/ggrc-arel   brynary          brynary.com
def
self.scope(name,
scope_options
=
{})
 

name
=
name.to_sym
 

valid_scope_name?(name)

 

scopes[name]
=
lambda
do
|*args|
 



scoped.merge(scope_options)
 

end

 

singleton_class.send(:redefine_method,
name,
&scopes[name])
 end




Arel         http://bit.ly/ggrc-arel   brynary          brynary.com
def
self.scope(name,
scope_options
=
{})
 

name
=
name.to_sym
 

valid_scope_name?(name)

 

scopes[name]
=
lambda
do
|*args|
 



scoped.merge(scope_options)
 

end

 

singleton_class.send(:redefine_method,
name,
&scopes[name])
 end




Arel         http://bit.ly/ggrc-arel   brynary          brynary.com
def
self.scope(name,
scope_options
=
{})
 

name
=
name.to_sym
 

valid_scope_name?(name)

 

scopes[name]
=
lambda
do
|*args|
 



scoped.merge(scope_options)
 

end

 

singleton_class.send(:redefine_method,
name,
&scopes[name])
 end




Arel         http://bit.ly/ggrc-arel   brynary          brynary.com
class
Rubyist
       

def
self.nycrb
       



where(:city
=>
"NYC")
       

end
       end




Arel     http://bit.ly/ggrc-arel   brynary   brynary.com
Arel Under the Hood




Arel     http://bit.ly/ggrc-arel   brynary   brynary.com
Arel Objects
   City.arel_table
   #
=>
<Arel::Table>

   City.arel_table[:population]
   #
=>
<Arel::Sql::Attributes::Integer
population>

   City.arel_table[:population].gt(750_000)
   #=>
<Arel::Predicates::GreaterThan>




Arel        http://bit.ly/ggrc-arel   brynary    brynary.com
Exposing the Attributes

       class
ActiveRecord::Base
       

def
self.[](column_name)
       



arel_table[column_name]
       

end
       end



Arel      http://bit.ly/ggrc-arel   brynary   brynary.com
Arel Predicates

  City.where(City[:population].gt(750_000))




Arel     http://bit.ly/ggrc-arel   brynary   brynary.com
Arel Operators
       • eq                           • matches
       • not_eq                       • not_matches
       • lt                           • in
       • lteq                         • not_in
       • gt                           • *_any
       • gteq                         • *_all
Arel        http://bit.ly/ggrc-arel       brynary     brynary.com
Compound Predicates
   hometown

=
City[:name].eq("Detroit")
   big






=
City[:population].gt(750_000)
   awesome


=
City[:awesome].eq(true)

   City.where(hometown.or(big.and(awesome))).to_sql
   #
=>
SELECT
*
FROM
cities
   




WHERE
name
=
'Detroit'
   







OR
(population
>
750000
AND
awesome
=
't')




Arel        http://bit.ly/ggrc-arel   brynary    brynary.com
Future
       Possibilities
                 `
       ActiveRecord 3.1? 4.0?




Arel          http://bit.ly/ggrc-arel   brynary   brynary.com
Map any relation to a class
       class
Signup
<
ActiveRecord::Base
       

users
=
Arel::Table.new(:users)
       

emails
=
Arel::Table.new(:emails)

       

set_relation
users_table.
       



join(emails).
       



on(users[:email_id].eq(emails[:id]))
       end




Arel        http://bit.ly/ggrc-arel   brynary   brynary.com
May any relation as an association
       class
User
       

orders
=
Arel::Table.new(:orders)

       

last_orders_by_user
=
orders.
       



group(orders[:user_id]).
       



project(orders[:id].maximum.as(:id))

       

has_one
:last_order,
orders.
       



where(orders[:id].in(last_orders_by_user[:id]))
       end

       User.includes(:last_order).each
do
|user|
       

#
...
       end
Arel            http://bit.ly/ggrc-arel   brynary     brynary.com
Custom Engines



Arel   http://bit.ly/ggrc-arel   brynary   brynary.com
ActiveRecord 3

                                 Arel

          Algebra                       Engines


         AR Connection Adapters

                           SQL Database

Arel   http://bit.ly/ggrc-arel          brynary   brynary.com
ActiveRecord 3

                                 Arel

          Algebra                       Engines


         AR Connection Adapters

                           SQL Database

Arel   http://bit.ly/ggrc-arel          brynary   brynary.com
ActiveRecord 3

                                 Arel

          Algebra                       Engines


         AR Connection Adapters

                           SQL Database

Arel   http://bit.ly/ggrc-arel          brynary   brynary.com
ActiveRecord 3

                                 Arel
                                               Engines
          Algebra                       SQL             Memory




         AR Connection Adapters

                           SQL Database

Arel   http://bit.ly/ggrc-arel                brynary            brynary.com




class
Arel::Sql::Engine






def
initialize(ar
=
nil)








@ar
=
ar






end







def
connection








@ar
?
@ar.connection
:
nil






end







def
create(relation)








#
...








connection.insert(relation.to_sql(false),
nil,
relation.primary_key)






end







def
read(relation)








rows
=
connection.select_rows(relation.to_sql)








Array.new(rows,
relation.attributes)






end







def
update(relation)








connection.update(relation.to_sql)






end







def
delete(relation)








connection.delete(relation.to_sql)






end




end
 Arel              http://bit.ly/ggrc-arel          brynary               brynary.com
Possible Arel Engines

       • NoSQL (e.g. Redis, CouchDB)
       • Memcache
       • Web service APIs (e.g. AWS, Twitter)
       • File system

Arel        http://bit.ly/ggrc-arel   brynary   brynary.com
Cross-Engine Joins



Arel   http://bit.ly/ggrc-arel   brynary   brynary.com
Thank You



Arel   http://bit.ly/ggrc-arel   brynary   brynary.com

More Related Content

Similar to Arel: Introduction to the Ruby Relational Algebra Library

Griffith uni
Griffith uniGriffith uni
Griffith uninigel99
 
Ruby on Rails : 簡介與入門
Ruby on Rails : 簡介與入門Ruby on Rails : 簡介與入門
Ruby on Rails : 簡介與入門Wen-Tien Chang
 
The Architecture of PicCollage Server
The Architecture of PicCollage ServerThe Architecture of PicCollage Server
The Architecture of PicCollage ServerLin Jen-Shin
 
Connecting the Worlds of Java and Ruby with JRuby
Connecting the Worlds of Java and Ruby with JRubyConnecting the Worlds of Java and Ruby with JRuby
Connecting the Worlds of Java and Ruby with JRubyNick Sieger
 
Ecossistema Ruby - versão SCTI UNF 2013
Ecossistema Ruby - versão SCTI UNF 2013Ecossistema Ruby - versão SCTI UNF 2013
Ecossistema Ruby - versão SCTI UNF 2013Fabio Akita
 
Jasig rubyon rails
Jasig rubyon railsJasig rubyon rails
Jasig rubyon rails_zaMmer_
 
Jasig rubyon rails
Jasig rubyon railsJasig rubyon rails
Jasig rubyon rails_zaMmer_
 
PTW Rails Bootcamp
PTW Rails BootcampPTW Rails Bootcamp
PTW Rails BootcampMat Schaffer
 
O que tem de novo no Ruby 2.0?
O que tem de novo no Ruby 2.0?O que tem de novo no Ruby 2.0?
O que tem de novo no Ruby 2.0?Fabio Akita
 
Processing Large Graphs
Processing Large GraphsProcessing Large Graphs
Processing Large GraphsNishant Gandhi
 
Adding Riak to your NoSQL Bag of Tricks
Adding Riak to your NoSQL Bag of TricksAdding Riak to your NoSQL Bag of Tricks
Adding Riak to your NoSQL Bag of Trickssiculars
 
Innovation and Security in Ruby on Rails
Innovation and Security in Ruby on RailsInnovation and Security in Ruby on Rails
Innovation and Security in Ruby on Railstielefeld
 
Lessons Learnt From Working With Rails
Lessons Learnt From Working With RailsLessons Learnt From Working With Rails
Lessons Learnt From Working With Railsmartinbtt
 
Stack Overflow Austin - jQuery for Developers
Stack Overflow Austin - jQuery for DevelopersStack Overflow Austin - jQuery for Developers
Stack Overflow Austin - jQuery for DevelopersJonathan Sharp
 
Socket applications
Socket applicationsSocket applications
Socket applicationsJoão Moura
 
wwc start-launched
wwc start-launchedwwc start-launched
wwc start-launchedMat Schaffer
 

Similar to Arel: Introduction to the Ruby Relational Algebra Library (20)

Griffith uni
Griffith uniGriffith uni
Griffith uni
 
Ruby on Rails : 簡介與入門
Ruby on Rails : 簡介與入門Ruby on Rails : 簡介與入門
Ruby on Rails : 簡介與入門
 
The Architecture of PicCollage Server
The Architecture of PicCollage ServerThe Architecture of PicCollage Server
The Architecture of PicCollage Server
 
Connecting the Worlds of Java and Ruby with JRuby
Connecting the Worlds of Java and Ruby with JRubyConnecting the Worlds of Java and Ruby with JRuby
Connecting the Worlds of Java and Ruby with JRuby
 
Ecossistema Ruby - versão SCTI UNF 2013
Ecossistema Ruby - versão SCTI UNF 2013Ecossistema Ruby - versão SCTI UNF 2013
Ecossistema Ruby - versão SCTI UNF 2013
 
Jasig rubyon rails
Jasig rubyon railsJasig rubyon rails
Jasig rubyon rails
 
Jasig rubyon rails
Jasig rubyon railsJasig rubyon rails
Jasig rubyon rails
 
PTW Rails Bootcamp
PTW Rails BootcampPTW Rails Bootcamp
PTW Rails Bootcamp
 
O que tem de novo no Ruby 2.0?
O que tem de novo no Ruby 2.0?O que tem de novo no Ruby 2.0?
O que tem de novo no Ruby 2.0?
 
Processing Large Graphs
Processing Large GraphsProcessing Large Graphs
Processing Large Graphs
 
Adding Riak to your NoSQL Bag of Tricks
Adding Riak to your NoSQL Bag of TricksAdding Riak to your NoSQL Bag of Tricks
Adding Riak to your NoSQL Bag of Tricks
 
Supa fast Ruby + Rails
Supa fast Ruby + RailsSupa fast Ruby + Rails
Supa fast Ruby + Rails
 
Rails 4.0
Rails 4.0Rails 4.0
Rails 4.0
 
Innovation and Security in Ruby on Rails
Innovation and Security in Ruby on RailsInnovation and Security in Ruby on Rails
Innovation and Security in Ruby on Rails
 
Lessons Learnt From Working With Rails
Lessons Learnt From Working With RailsLessons Learnt From Working With Rails
Lessons Learnt From Working With Rails
 
Stack Overflow Austin - jQuery for Developers
Stack Overflow Austin - jQuery for DevelopersStack Overflow Austin - jQuery for Developers
Stack Overflow Austin - jQuery for Developers
 
Bhavesh ro r
Bhavesh ro rBhavesh ro r
Bhavesh ro r
 
Rack
RackRack
Rack
 
Socket applications
Socket applicationsSocket applications
Socket applications
 
wwc start-launched
wwc start-launchedwwc start-launched
wwc start-launched
 

Recently uploaded

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 

Recently uploaded (20)

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 

Arel: Introduction to the Ruby Relational Algebra Library

Editor's Notes

  1. How many people have heard of Arel?
  2. Lots of contributors!!!
  3. Math concept. Offshoot of set theory. E.F. Codd in 1970 You use relation algebra when you use SQL.
  4. Header with columns and types.
  5. A set of tuples. Not SQL specific. ...But: think about tables, views, query results ...in AR: classes, associations
  6. Selection: WHERE (restrict a set)
  7. Projection: Limit the columns (SELECT ...)
  8. Like SQL
  9. Set operations
  10. Operations on relations yield new relations. Implemented in code as the composite pattern. Note: This works because relations are immutable, which is cool.
  11. Cleaned up ActiveRecord. Nice new Syntax for you.
  12. Query runs on iteration
  13. Cleans up everything quite nicely
  14. Caution! Not supported by Rails. Don&amp;#x2019;t report bugs ;-) Subject to Arel API changes
  15. Contrived example. Consider your code that builds queries based on data.
  16. AR becomes a Data Mapper
  17. Arel is split into Algebra and Engines
  18. Arel supports multiple engines
  19. Each engine defines CRUD operations
  20. Write an ActiveRecord relation that pulls IDs from Redis and records from a table