Session 6: ROracle. <Insert Picture Here> Mark Hornick, Director, Oracle Advanced Analytics Development Oracle Advanced Analytics



Similar documents
Package RSQLite. February 19, 2015

Computing with large data sets

Package RPostgreSQL. February 19, 2015

Using Databases in R

Package DBI. May 8, 2016

Querying Databases Using the DB Query and JDBC Query Nodes

SQL and programming languages

Package sjdbc. R topics documented: February 20, 2015

A basic create statement for a simple student table would look like the following.

Alteryx Predictive Analytics for Oracle R

MyOra 3.0. User Guide. SQL Tool for Oracle. Jayam Systems, LLC

Migrate Topaz databases from One Server to Another

SQL Programming. CS145 Lecture Notes #10. Motivation. Oracle PL/SQL. Basics. Example schema:

Simba Apache Cassandra ODBC Driver

Time Series Database Interface: R MySQL (TSMySQL)

database abstraction layer database abstraction layers in PHP Lukas Smith BackendMedia

Embedded SQL. Unit 5.1. Dr Gordon Russell, Napier University

Package TSfame. February 15, 2013

Database Access from a Programming Language: Database Access from a Programming Language

Database Access from a Programming Language:

INTRODUCTION: SQL SERVER ACCESS / LOGIN ACCOUNT INFO:

The Saves Package. an approximate benchmark of performance issues while loading datasets. Gergely Daróczi

A SQL Injection : Internal Investigation of Injection, Detection and Prevention of SQL Injection Attacks

DBX. SQL database extension for Splunk. Siegfried Puchbauer

The manual contains complete instructions on 'converting' your data to version 4.21.

14 Triggers / Embedded SQL

How to Install and Configure EBF15328 for MapR or with MapReduce v1

3.GETTING STARTED WITH ORACLE8i

Integrating VoltDB with Hadoop

SQL Injection. SQL Injection. CSCI 4971 Secure Software Principles. Rensselaer Polytechnic Institute. Spring

Course Objectives. Database Applications. External applications. Course Objectives Interfacing. Mixing two worlds. Two approaches

Virtual Private Database Features in Oracle 10g.

The full setup includes the server itself, the server control panel, Firebird Database Server, and three sample applications with source code.

MyOra 3.5. User Guide. SQL Tool for Oracle. Kris Murthy

Intellicus Enterprise Reporting and BI Platform

Package RCassandra. R topics documented: February 19, Version Title R/Cassandra interface

Voyager Reporting System (VRS) Installation Guide. Revised 5/09/06

SAP InfiniteInsight Explorer Analytical Data Management v7.0

JDBC. It is connected by the Native Module of dependent form of h/w like.dll or.so. ex) OCI driver for local connection to Oracle

Developing SQL and PL/SQL with JDeveloper

Toad for Oracle 8.6 SQL Tuning

Application note: Connecting the to a Database

Apache Derby Security. Jean T. Anderson

DB2 - DATABASE SECURITY

Chapter 2: Security in DB2

news from Tom Bacon about Monday's lecture

Configuring an Alternative Database for SAS Web Infrastructure Platform Services

Unit 10: Microsoft Access Queries

Package uptimerobot. October 22, 2015

In This Lecture. Security and Integrity. Database Security. DBMS Security Support. Privileges in SQL. Permissions and Privilege.

Objectives of SQL. Terminology for Relational Model. Introduction to SQL

Hacking and Protecting Oracle DB. Slavik Markovich CTO, Sentrigo

CS2506 Operating Systems II Lab 8, 8 th Tue/03 /2011 Java API

rm(list=ls()) library(sqldf) system.time({large = read.csv.sql("large.csv")}) # seconds, 4.23GB of memory used by R

The First Example of TimesTen with Oracle on Windows

ODBC Client Driver Help Kepware, Inc.

Using the SQL TAS v4

v4.8 Getting Started Guide: Using SpatialWare with MapInfo Professional for Microsoft SQL Server

Before you may use any database in Limnor, you need to create a database connection for it. Select Project menu, select Databases:

Nortel Networks Symposium Call Center Server Symposium Database Integration User s Guide

Oracle Enterprise Manager

Lecture 25: Database Notes

MyOra 4.5. User Guide. SQL Tool for Oracle. Kris Murthy

AWS Schema Conversion Tool. User Guide Version 1.0

Webapps Vulnerability Report

Exploits: XSS, SQLI, Buffer Overflow

1Z0-117 Oracle Database 11g Release 2: SQL Tuning. Oracle

Entity store. Microsoft Dynamics AX 2012 R3

SnapLogic Salesforce Snap Reference

Restore and Recovery Tasks. Copyright 2009, Oracle. All rights reserved.

Database Design. Marta Jakubowska-Sobczak IT/ADC based on slides prepared by Paula Figueiredo, IT/DB

Firebird. Embedded SQL Guide for RM/Cobol

RDS Migration Tool Customer FAQ Updated 7/23/2015

SQL Injection Vulnerabilities in Desktop Applications

Tutorial on Operations on Database using JDeveloper

Security Analysis. Spoofing Oracle Session Information

Services. Relational. Databases & JDBC. Today. Relational. Databases SQL JDBC. Next Time. Services. Relational. Databases & JDBC. Today.

Chapter 9 Java and SQL. Wang Yang wyang@njnet.edu.cn

Oracle Fusion Middleware

Using SAS ACCESS to retrieve and store data in relational database management systems

Using ODBC and other database interfaces

HansaWorld SQL Training Material

Oracle EBS Interface Connector User Guide V1.4

Session 1: Introduction to Oracle's R Technologies

4D v11 SQL Release 3 (11.3) ADDENDUM

Objectives. Oracle SQL and SQL*PLus. Database Objects. What is a Sequence?

PUBLIC Installation: SAP Mobile Platform Server for Linux

Using SQL Server Management Studio

Informatica Data Replication FAQs

Tutorial: How to Use SQL Server Management Studio from Home

Governance, Risk, and Compliance Controls Suite. Preventive Controls Governor Audit Rules User s Guide. Software Version

Websense SQL Queries. David Buyer June 2009

Installing SQL Express. For CribMaster 9.2 and Later

Programming Database lectures for mathema

Oracle E-Business Suite - Oracle Business Intelligence Enterprise Edition 11g Integration

Transcription:

<Insert Picture Here> Session 6: ROracle Mark Hornick, Director, Oracle Advanced Analytics Development Oracle Advanced Analytics

Topics What is ROracle? Using ROracle Summary 2

What is ROracle? 3

ROracle R package enabling connectivity to Oracle Database Open source Publically available on CRAN Execute SQL statements from R interface Oracle Database Interface (DBI) for R DBI compliant Oracle driver based on OCI Requirements Oracle Instant Client or Oracle Database Client Examples from ROracle package documentation http://cran.r-project.org/web/packages/roracle/roracle.pdf 4

ROracle Oracle Database DBI & SQL R package enabling connectivity to Oracle Database Open source, publicly available on CRAN, free to R community Execute SQL statements from R interface Oracle Database Interface (DBI) for R based on OCI for high performance Supports Oracle R Enterprise database connectivity 5

Comparison reading database table to R data.frame ROracle Up to 79X faster than RJDBC Up to 2.5X faster than RODBC Scales across NUMBER, VARCHAR2, TIMESTAMP data types See https://blogs.oracle.com/r/entry/r_to_oracle_database_connectivity 6

Comparison writing database table from R data.frame ROracle 61X faster for 10 cols x 10K rows than RODBC 630X faster on 10 cols x 10K rows than RJDBC Scales across the remaining data types 7

ROracle 1-1.11 Enhancements Performance enhancements for RAW data types and large result sets Cache resultset in memory before transferring to R to avoid unnecessary alloc and free using allocvector when result exceeds bulk_read rows Added session mode to connect as SYSDBA or using external authentication bug 17383542: Enhanced dbwritetable() & dbremovetable() to work on global schema 8

Using ROracle 9

Example rolling back transactions drv <- dbdriver("oracle") # Create the connection string host <- "adc2100958" port <- 1521 sid <- "orff" connect.string <- paste( "(DESCRIPTION=", "(ADDRESS=(PROTOCOL=tcp)(HOST=", host, ")(PORT=", port, "))", "(CONNECT_DATA=(SID=", sid, ")))", sep = "") con <- dbconnect(drv, username = "scott", password = "tiger",dbname=connect.string) 10

Example rolling back transactions dbreadtable(con, "EMP") rs <- dbsendquery(con, "delete from emp where deptno = 10") dbreadtable(con, "EMP") if(dbgetinfo(rs, what = "rowsaffected") > 1){ warning("dubious deletion -- rolling back transaction") dbrollback(con) } dbreadtable(con, "EMP") 11

Example username/password authentication ## create an Oracle instance and create one connection drv <- dbdriver("oracle") ## use username/password authentication if using local database con <- dbconnect(drv, username = "scott", password = "tiger") ## run a SQL statement by first creating a resultset object rs <- dbsendquery(con, "select * from emp where deptno = 10") ## fetch records from the resultset into a data.frame data <- fetch(rs) ## extract all rows dim(data) data 12

Example connect to TimeTen IMDB instance ## create an Oracle instance and create one connection. drv <- dbdriver("oracle") ## connect to a TimesTen IMDB instance using the easy connect ## naming method where SampleDb is a direct driver TimesTen DSN con <- dbconnect(drv, username ="scott", password="tiger", dbname = "localhost/sampledb:timesten_direct") ## run an SQL statement by creating first a resultset object rs <- dbsendquery(con, "select * from dual") ## we now fetch records from the resultset into a data.frame data <- fetch(rs) ## extract all rows dim(data) 14

Example connect to an extproc for use within ERE ## connect to an extproc (this assumes that driver has already ## been initialized in the embedded code by passing an external ## pointer representing extproc context) con <- dbconnect(extproc()) ## run a SQL statement by first creating a resultset object rs <- dbsendquery(con, "select * from dual") ## we now fetch records from the resultset into a data.frame data <- fetch(rs) ## extract all rows dim(data) 15

Example unload driver # create an Oracle instance drv <- dbdriver("oracle") con <- dbconnect(drv, "scott", "tiger", dbname=connect.string) res <- dbsendquery(con, "select * from emp") fetch(res, n = 5) fetch(res) # free resources occupied by result set dbclearresult(res) dbunloaddriver(drv) 16

Example getinfo methods drv <- dbdriver("oracle") con <- dbconnect(drv, "scott", "tiger", dbname=connect.string) rs <- dbsendquery(con, "select * from emp") dbgetstatement(rs) dbhascompleted(rs) dbgetinfo(rs) # DBIDriver info names(dbgetinfo(drv)) # DBIConnection info names(dbgetinfo(con)) # DBIResult info names(dbgetinfo(rs)) 17

Example getinfo methods drv <- dbdriver("oracle") con1 <- dbconnect(drv, "scott", "tiger", dbname=connect.string) res1 <- dbsendquery(con1, "select * from emp where deptno = 10") res2 <- dbsendquery(con1, "select * from emp where deptno = 20") con2 <- dbconnect(drv, "scott", "tiger") res3 <- dbsendquery(con2, "select * from dept") ## get all active statements for(con in dblistconnections(drv)) for (res in dblistresults(con)) print(dbgetstatement(res)) 18

Example read/write table methods con <- dbconnect(oracle(), "scott", "tiger", dbname=connect.string) if (dbexiststable(con, "FOO", "SCOTT")) dbremovetable(con, "FOO") foo <- dbreadtable(con, "EMP") row.names(foo) <- foo$empno foo <- foo[,-1] dbwritetable(con, "FOO", foo, row.names = TRUE) dbwritetable(con, "FOO", foo, row.names = TRUE, overwrite = TRUE) dbreadtable(con, "FOO", row.names = 1) dbgetquery(con, "delete from foo") dbwritetable(con, "FOO", foo, row.names = TRUE, append = TRUE) dbreadtable(con, "FOO", row.names = 1) dbremovetable(con, "FOO") dblisttables(con) dblistfields(con, "EMP") if (dbexiststable(con, "RORACLE_TEST", "SCOTT")) dbremovetable(con, "RORACLE_TEST") 19

Example read/write table methods # example of POSIXct usage # A table is created using: createtab <- "create table RORACLE_TEST(row_num number, id1 date, id2 timestamp, id3 timestamp with time zone, id4 timestamp with local time zone )" dbgetquery(con, createtab) # Insert statement insstr <- "insert into RORACLE_TEST values(:1, :2, :3, :4, :5)"; # Select statement selstr <- "select * from RORACLE_TEST"; # Insert time stamp without time values in POSIXct form x <- 1; y <- "2012-06-05"; y <- as.posixct(y); dbgetquery(con, insstr, data.frame(x, y, y, y, y)); 20

Example read/write table methods # Insert date & times tamp with time values in POSIXct form x <- 2; y <- "2012-01-05 07:15:02"; y <- as.posixct(y); z <- "2012-01-05 07:15:03.123"; z <- as.posixct(z); dbgetquery(con, insstr, data.frame(x, y, z, z, z)); # Insert list of date objects in POSIXct form x <- c(3, 4, 5, 6); y <- c('2012-01-05', '2011-01-05', '2014-01-05', '2020-01-05'); y <- as.posixct(y); dbgetquery(con, insstr, data.frame(x, y, y, y, y)); dbcommit (con) # Selecting data and displaying it res <- dbgetquery(con, selstr) res[,1] res[,2] res[,3] res[,4] res[,5] 21

Example send query methods drv <- dbdriver("oracle") con <- dbconnect(drv, "scott", "tiger") res <- dbsendquery(con, "select * from emp where deptno = :1", data = data.frame(deptno = 10)) data <- fetch(res, n = -1) res2 <- dbsendquery(con, "select * from emp where deptno = :1", data = data.frame(deptno = 10), prefetch=true, bulk_read=2l) data1 <- fetch(res2, n = -1) res3 <- dbsendquery(con, "select * from emp where deptno = :1", data = data.frame(deptno = 10), bulk_read=10l) data2 <- fetch(res3, n = -1) res4 <- dbsendquery(con, "select * from emp where ename = :1", data = data.frame(ename = 'SMITH')) data3 <- fetch(res4, n = -1) 22

Example Oracle method ## create a Oracle instance and create one connection. ora <- Oracle() ## or dbdriver("oracle") con <- dbconnect(ora, username = "scott", password = "tiger", dbname = "inst1") ## if you are connecting to a local database con <- dbconnect(ora, username = "scott", password = "tiger") ## execute a statement and fetch output in chunks <= 5000 rows at a time rs <- dbsendquery(con, "select * from emp where deptno = 10") while (!dbhascompleted(rs)) { df <- fetch(rs, n = 5000) ## process df } dbclearresult(rs) ## done with this query 23

Example Oracle method ## execute and fetch a statement with bind data df <- dbgetquery(con, "select * from emp where deptno = :1", data = data.frame(depno = 10)) ## create a copy of emp table dbgetquery(con, "create table foo as select * from emp") ## execute and bind an INSERT statement my.data = data.frame(empno = c(8001, 8002), ename = c('mukhin', 'ABOYOUN')) more.data = data.frame(empno = c(8003), ename = c('james')) rs <- dbsendquery(con, "insert into foo (empno, ename) values (:1, :2)",data = my.data) ## execute with more data execute(rs, data = more.data) df <- dbgetquery(con, "select * from foo") dbclearresult(rs) ## done with this query dbcommit(con) ## ok, everything looks fine summary(ora) ## a concise description of the driver dbdisconnect(con) ## done with this connection 24

Summary R package enabling connectivity to Oracle Database Open source Publically available on CRAN Execute SQL statements from R interface Oracle Database Interface (DBI) for R DBI compliant Oracle driver based on OCI Requirements Oracle Instant Client or Oracle Database Client 25

Resources Book: Using R to Unlock the Value of Big Data Blog: https://blogs.oracle.com/r/ Forum: https://forums.oracle.com/forums/forum.jspa?forumid=1397 Oracle R Distribution ROracle Oracle R Enterprise Oracle R Connector for Hadoop http://oracle.com/goto/r 26

27

28