SlideShare una empresa de Scribd logo
1 de 15
Descargar para leer sin conexión
Szemelvények a
MonetDB.R
csomagból
Urbanics Gábor <urbanics@quanopt.com>

Villámelőadás – R meetup Budapest
1.

Quanopt Ltd.
Problémafelvetés
 Az R jó, de a memóriában kell lennie
mindennek  hamar elfogyhat
 Erre a legegyszerűbb megoldások
o File-backed csomagok használata, pl.
• bigmemory csomagcsalád, ff csomag

o Amennyire lehet, használjunk adatbázist
• Tárolás +
• Feldolgozás

2.

Quanopt Ltd.
MonetDB
ID
10
11
12
13

 Relációs

Day
Discount
4/4/98
0.195
9/4/98
0.065
1/2/98
0.175
7/2/98
0

 Oszlopszervezésű
o Vö. soronkénti

OID

ID

OID
10
11
12
13
14

100
101
102
103
104

Day
100
4/4/98
101
9/4/98
102
1/2/98
103
7/2/98
104
1/2/99

OID

Discount
100
0.195
101
0.065
102
0.175
103
0
104
0.065

3 db külön fájl a diszken
3.

Quanopt Ltd.
MonetDB – előnyök
 A teljes oszlopo(ka)t érintő lekérdezéseknél

lesz hatékony (IO hozzáférés jobb)
 Egy oszlopot egyszerű cache-elni
o Memory mapped file

 Oszloponként jobban tömöríthetőek az adatok
o kisebb tárhely 
o CPU-val fizetünk, a kevesebb IO-ért 

 Fürtbe is szervezhető
4.

Quanopt Ltd.
MonetDB – hátrányok
 Nem „silver-bullet”: mindenre nem lesz jó
 „Read-mostly” hozzáférésre javasolt
 Itt is a kód a legbiztosabb dokumentáció 

5.

Quanopt Ltd.
MonetDB és R integráció
 RODBC-n keresztül elérhető
o Ilyet láttunk már… ez nem segítene sokat

 MonetDB.R csomag
o MonetDB specifikus funkcionalitás R-ből
o Alapvető DB management (start/stop)

o Adatelérés (természetesen)

6.

Quanopt Ltd.
MonetDB.R csomag – DBI elérés
 DBI driver
o dbConnect
o dbSendUpdate, …
#
>
>
>

using DBI with MonetDB
conn <- dbConnect( MonetDB.R(), "monetdb://localhost/demo")
result <- dbGetQuery( conn, "SELECT count(*) from mytable;")
print(result)
L1
1 29722533
> str(result)
'data.frame': 1 obs. of 1 variable: $ L1: num 29722533

7.

Quanopt Ltd.
MonetDB.R csomag – monet.frame
 Egy data.frame szerű osztály
o Proxy objektum egy adatbázis táblához

 Egyszerű műveletek adatbázis oldalon
o Az R hívásokat SQL lekérdezésekké írja át

8.

Quanopt Ltd.
MonetDB.R csomag – monet.frame
> mframe <- monet.frame(conn, "demotable", debug=TRUE)
QQ: 'SELECT * FROM demotable‘
II: 'Re-Initializing column info.‘
II: 'Re-Initializing row count.‘

Listázza ki az SQL
lekérdezéseket!

> str(mframe)

MonetDB-backed data.frame surrogate 3 columns, 12500 rows
Query: SELECT * FROM demotable
Columns: col1 (numeric), col2 (numeric), col3 (numeric)

9.

Quanopt Ltd.
MonetDB.R csomag – monet.frame
> res <- (mframe$col1 + mframe$col2) / sqrt(cos(10*mframe$col3))
QQ: 'SELECT
QQ: 'SELECT
QQ: 'SELECT
QQ: 'SELECT
QQ: 'SELECT
QQ: 'SELECT
QQ: 'SELECT
QQ: 'SELECT
demotable'

col1 FROM demotable‘
Lusta állatfaj 
col2 FROM demotable‘
még csak előállítja
(col1)+(col2) FROM demotable‘
a lekérdezéseket,
col3 FROM demotable‘
de nem hajtja végre
10*(col3) FROM demotable‘
COS(10*(col3)) FROM demotable‘
SQRT(COS(10*(col3))) FROM demotable‘
((col1)+(col2))/(SQRT(COS(10*(col3)))) FROM

10.

Quanopt Ltd.
MonetDB.R csomag – monet.frame
> head(res)

QQ: 'SELECT ((col1)+(col2))/(SQRT(COS(10*(col3)))) FROM
demotable LIMIT 6 OFFSET 0‘
II: 'Re-Initializing column info.‘
EX: 'SELECT ((col1)+(col2))/(SQRT(COS(10*(col3)))) FROM
demotable LIMIT 6 OFFSET 0‘

1
2
3
4
5
6

sql_div_sql_add_col1
4.661327
NA
NA
6.260829
6.640108
-21.836528

11.

Quanopt Ltd.
MonetDB.R csomag – monet.frame
 Számos R függvény és operátor SQL oldali
implementációja szerepel a csomagban
o Subset, ”[” operátor
o Aritmetikai műveletek: +, -, *, /, ^, %%, %/%
o Logikai operátorok: &, |, !
o min, max, mean, sd, var, median, quantile,
tabulate
o abs, sign, sqrt, floor, ceiling, trunc, round, signif
o exp, log, expm1, log1p, cos, sin, tan, acos, asin,
atan, cosh, sinh, tanh, acosh,asinh, atanh

12.

Quanopt Ltd.
MonetDB.R csomag – hátrányok
 Az ötlet (R  SQL átírás) jó, de
o Az implementációban vannak azért hibák
(pl. „limit” nevű változót ne használjunk )
o Az műveletek elemkészlete korlátozott

 Teljesen transzparens nem lesz 

13.

Quanopt Ltd.
MonetDB.R csomag – hátrányok
 Tetszőleges meglévő függvényt nem
fogunk tudni használni 
> ggplot(data=mframe, aes(x=col1)) + geom_histogram()

Error: ggplot2 doesn't know how to deal with data of class
monet.frame

 Természetesen mi írhatunk olyan saját függvényt, ami
támogatja…

14.

Quanopt Ltd.
MonetDB.R – hasonló megoldások
 Oracle R Enterprise
o R függvények végrehajtása Oracle
adatbázisokon

 IBM Netezza R csomagok
o nzR, nzA, nzMatrix

 Teradata
o teradataR csomag

15.

Quanopt Ltd.

Más contenido relacionado

Destacado

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 

Destacado (20)

Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 

Szemelvények a MonetDB.R csomagból

  • 1. Szemelvények a MonetDB.R csomagból Urbanics Gábor <urbanics@quanopt.com> Villámelőadás – R meetup Budapest 1. Quanopt Ltd.
  • 2. Problémafelvetés  Az R jó, de a memóriában kell lennie mindennek  hamar elfogyhat  Erre a legegyszerűbb megoldások o File-backed csomagok használata, pl. • bigmemory csomagcsalád, ff csomag o Amennyire lehet, használjunk adatbázist • Tárolás + • Feldolgozás 2. Quanopt Ltd.
  • 3. MonetDB ID 10 11 12 13  Relációs Day Discount 4/4/98 0.195 9/4/98 0.065 1/2/98 0.175 7/2/98 0  Oszlopszervezésű o Vö. soronkénti OID ID OID 10 11 12 13 14 100 101 102 103 104 Day 100 4/4/98 101 9/4/98 102 1/2/98 103 7/2/98 104 1/2/99 OID Discount 100 0.195 101 0.065 102 0.175 103 0 104 0.065 3 db külön fájl a diszken 3. Quanopt Ltd.
  • 4. MonetDB – előnyök  A teljes oszlopo(ka)t érintő lekérdezéseknél lesz hatékony (IO hozzáférés jobb)  Egy oszlopot egyszerű cache-elni o Memory mapped file  Oszloponként jobban tömöríthetőek az adatok o kisebb tárhely  o CPU-val fizetünk, a kevesebb IO-ért   Fürtbe is szervezhető 4. Quanopt Ltd.
  • 5. MonetDB – hátrányok  Nem „silver-bullet”: mindenre nem lesz jó  „Read-mostly” hozzáférésre javasolt  Itt is a kód a legbiztosabb dokumentáció  5. Quanopt Ltd.
  • 6. MonetDB és R integráció  RODBC-n keresztül elérhető o Ilyet láttunk már… ez nem segítene sokat  MonetDB.R csomag o MonetDB specifikus funkcionalitás R-ből o Alapvető DB management (start/stop) o Adatelérés (természetesen) 6. Quanopt Ltd.
  • 7. MonetDB.R csomag – DBI elérés  DBI driver o dbConnect o dbSendUpdate, … # > > > using DBI with MonetDB conn <- dbConnect( MonetDB.R(), "monetdb://localhost/demo") result <- dbGetQuery( conn, "SELECT count(*) from mytable;") print(result) L1 1 29722533 > str(result) 'data.frame': 1 obs. of 1 variable: $ L1: num 29722533 7. Quanopt Ltd.
  • 8. MonetDB.R csomag – monet.frame  Egy data.frame szerű osztály o Proxy objektum egy adatbázis táblához  Egyszerű műveletek adatbázis oldalon o Az R hívásokat SQL lekérdezésekké írja át 8. Quanopt Ltd.
  • 9. MonetDB.R csomag – monet.frame > mframe <- monet.frame(conn, "demotable", debug=TRUE) QQ: 'SELECT * FROM demotable‘ II: 'Re-Initializing column info.‘ II: 'Re-Initializing row count.‘ Listázza ki az SQL lekérdezéseket! > str(mframe) MonetDB-backed data.frame surrogate 3 columns, 12500 rows Query: SELECT * FROM demotable Columns: col1 (numeric), col2 (numeric), col3 (numeric) 9. Quanopt Ltd.
  • 10. MonetDB.R csomag – monet.frame > res <- (mframe$col1 + mframe$col2) / sqrt(cos(10*mframe$col3)) QQ: 'SELECT QQ: 'SELECT QQ: 'SELECT QQ: 'SELECT QQ: 'SELECT QQ: 'SELECT QQ: 'SELECT QQ: 'SELECT demotable' col1 FROM demotable‘ Lusta állatfaj  col2 FROM demotable‘ még csak előállítja (col1)+(col2) FROM demotable‘ a lekérdezéseket, col3 FROM demotable‘ de nem hajtja végre 10*(col3) FROM demotable‘ COS(10*(col3)) FROM demotable‘ SQRT(COS(10*(col3))) FROM demotable‘ ((col1)+(col2))/(SQRT(COS(10*(col3)))) FROM 10. Quanopt Ltd.
  • 11. MonetDB.R csomag – monet.frame > head(res) QQ: 'SELECT ((col1)+(col2))/(SQRT(COS(10*(col3)))) FROM demotable LIMIT 6 OFFSET 0‘ II: 'Re-Initializing column info.‘ EX: 'SELECT ((col1)+(col2))/(SQRT(COS(10*(col3)))) FROM demotable LIMIT 6 OFFSET 0‘ 1 2 3 4 5 6 sql_div_sql_add_col1 4.661327 NA NA 6.260829 6.640108 -21.836528 11. Quanopt Ltd.
  • 12. MonetDB.R csomag – monet.frame  Számos R függvény és operátor SQL oldali implementációja szerepel a csomagban o Subset, ”[” operátor o Aritmetikai műveletek: +, -, *, /, ^, %%, %/% o Logikai operátorok: &, |, ! o min, max, mean, sd, var, median, quantile, tabulate o abs, sign, sqrt, floor, ceiling, trunc, round, signif o exp, log, expm1, log1p, cos, sin, tan, acos, asin, atan, cosh, sinh, tanh, acosh,asinh, atanh 12. Quanopt Ltd.
  • 13. MonetDB.R csomag – hátrányok  Az ötlet (R  SQL átírás) jó, de o Az implementációban vannak azért hibák (pl. „limit” nevű változót ne használjunk ) o Az műveletek elemkészlete korlátozott  Teljesen transzparens nem lesz  13. Quanopt Ltd.
  • 14. MonetDB.R csomag – hátrányok  Tetszőleges meglévő függvényt nem fogunk tudni használni  > ggplot(data=mframe, aes(x=col1)) + geom_histogram() Error: ggplot2 doesn't know how to deal with data of class monet.frame  Természetesen mi írhatunk olyan saját függvényt, ami támogatja… 14. Quanopt Ltd.
  • 15. MonetDB.R – hasonló megoldások  Oracle R Enterprise o R függvények végrehajtása Oracle adatbázisokon  IBM Netezza R csomagok o nzR, nzA, nzMatrix  Teradata o teradataR csomag 15. Quanopt Ltd.