You are on page 1of 23

1

2014 Oracle Corporation

Proprietary and Confidential

Presenter: Anuj Sahni Title: Principal Product Manager


2

2014 Oracle Corporation

Proprietary and Confidential

The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracles products remains at the sole discretion of Oracle.

2014 Oracle Corporation

Proprietary and Confidential

Agenda
Introduce Table based data modeling feature
Discuss its benefits How to use it (DDL & DML)

How to approach data modeling (in real world situations)


Email Client App as driver Schema design & deployment Queries into Data access methods

Architecture

Demo

2014 Oracle Corporation

Proprietary and Confidential

What is Being Proposed?


Table Based Model On top of key/value model Allow choice of modeling constructs Introduces strongly typed fields APIs for table access Administrative CLI for table creation Secondary Indices Indexes rely on table model Allows composite index keys APIs for value and range access by secondary key
5

2014 Oracle Corporation

Proprietary and Confidential

Why Table Model ?


Simplify application data modeling Tables and well-defined data types are familiar concepts Allows thinking in data types vs raw byte values Transparently handles key structure and serialization Easily maps to/from JSON Data types and some structure are required for secondary indices

2014 Oracle Corporation

Proprietary and Confidential

Example 1 Key/Value Paradigm


Simple Data Model
Key Space : /user/userId Value : {
name" : User", "namespace" : "com.company. avro", "type" : "record", "fields": [ {"name": userId", "type": Integer", "default": 0}, {"name": firstName", "type": String", "default": ""}, {"name": lastName", "type": String", "default": ""} ] }
7

2014 Oracle Corporation

Proprietary and Confidential

Example 1 Table Paradigm


Simple Data Model
Table Name : User

Primary Key
userId firstName

Value
lastName

Major Key Denotes Shard


8

2014 Oracle Corporation

Proprietary and Confidential

Example 1 Simple Data Model


DDL
kv-> table create -name User -desc "A sample user table" User-> add-field -type Integer -name userId User-> add-field -type String -name firstame User-> add-field -type String -name lastName User-> primary-key -name userId User-> exit Table User built. kv-> plan add-table -name User wait kv-> plan add-index -name UserSecondary -table User -field firstName field lastName Create Table with id, firstName, lastName columns.

Add index on firstName, lastName columns.

2014 Oracle Corporation

Proprietary and Confidential

How to Describe It ?
DDL
kv-> show tables -name User { "type" : "table", name" : "User", "id" : "r", "description" : A sample user table, "shardKey" : [ "userId" ], "primaryKey" : [ "userId" ], "fields" : [

{ "name" : userId", "type" : "Integer" },


{ "name" : "firstName", "type" : "String" }, { "name" : "lastName", "type" : "String" } ]}
10

2014 Oracle Corporation

Proprietary and Confidential

How to View Data?


Data Shell
kvshell-> get table -name User { "userId" : 101, "firstName" : Adam, { "userId" : 102, "firstName" : Zill, { "userId" : 103, "firstName" : Nitin, 3 rows returned. kvshell-> get table -name User -field userId -value 101 "lastName" : Smith} "lastName" : Kapoor} "lastName" : Matson}

{ "userId" : 101, "firstName" : Adam,


1 row returned

"lastName" : Smith}

11

2014 Oracle Corporation

Proprietary and Confidential

Example 1 - How does DML looks like?


Search secondary index where firstName = Jane
1. 2. 3. 4. 5.

Create instance of table object we wish to read from Create instance of index object that we will search Set search key Call iterator to scan index Convert results to JSON object, take JSON object and convert back to Row

Table userTable = store.getTableAPI().getTable("User", null); Index index = userTable.getIndex("UserSecondary");

IndexKey indexKey = index.createIndexKey().put("firstName", "Jane"); Iterator<Row> results = apiImpl.tableIterator(indexKey);


while (results.hasNext()) { Row row = results.next(); /* Convert the row to a JSON object */ String jsonString = row.toJsonString(); /* Convert the JSON object back to a row */ Row myRow = userTable.createRowFromJSON(jsonString);

}
12

2014 Oracle Corporation

Proprietary and Confidential

Example 2 Major/Minor KV Paradigm


User mailbox data
Key Space : Value : { /user/id/-/folder/inbox/arrival date /user/id/-/folder/deleted/arrival date

name" : "Email", "namespace" : "com.companyX.email.avro", "type" : "record", "fields": [ {"name": "from", "type": "string", "default": ""}, {"name": "to", "type": "string", "default": ""}, {"name": "sender", "type": "string", "default": ""}, {"name": "cc", "type": "string", "default": ""}, {"name": "subject", "type": "string", "default": ""}, {name: msgBody, type: string, default: }

]}
13

2014 Oracle Corporation

Proprietary and Confidential

Example 2 Modeled as Nested Tables


User mailbox data
Parent Table Name: User UserID

Primary Key Major Key

Child Table Name: Folder

Major Key Inherited from parent table

Primary Key
UserID Folder Name Arrival Date From To

Value
Sender CC Subject Msg Body

14

2014 Oracle Corporation

Proprietary and Confidential

Example 2 - Nested Table (DDL)


Create Table with id, firstName, lastName
kv-> table create name User.Folder -desc Mail folders" folder-> add-field type String name folderName folder-> add-field type Date name arrivalDate folder-> add-field -type String -name from folder-> add-field -type String -name to folder-> add-field -type String -name sender folder-> add-field -type String -name cc folder-> add-field -type String -name subject folder-> add-field type String name msgBody folder-> primary-key name folderName name arrivalDate folders-> exit Table User.folder built.
plan add-index -name userFolderMessage -table User.folder -field userId -field folderName

15

2014 Oracle Corporation

Proprietary and Confidential

Example 2 - Nested Table (DML)


Search secondary index where folder name = INBOX for userId=21
1. 2. 3. 4. 5.

Get a handle to the child table, through its parent table Create instance of index object and set fields we want to search on Set search key, restrict on inbox folder Call iterator to scan index Convert results to JSON object, take JSON object and convert back to Row

TableAPI ampImpl = store.getTableAPI(); Table userTable = apiImpl.getTable("User.Folder); Index index = userTable.getIndex(userFolderMessage "); IndexKey indexKey = index.createIndexKey(); indexKey.put(userId", 21"); indexKey.put(folderName", inbox"); Iterator<Row> results = apiImpl.tableIterator(indexKey, null, null); while (results.hasNext()) { Row row = results.next(); /* Convert the row to a JSON object if desired */ String jsonString = row.toJsonString(); }
16

2014 Oracle Corporation

Proprietary and Confidential

How to Approach Data Modeling


Email Sample App.

Process is not much different from RDBMS


Business requirements Entities & Relationships Query access patterns (CRUD, range, ACID)
send receive

Sender
SENT

Email
INBOX

Recipients

17

2014 Oracle Corporation

Proprietary and Confidential

Email Example RDBMS Schema


ER Diagram

18

2014 Oracle Corporation

Proprietary and Confidential

Email Example NoSQL Schema

19

2014 Oracle Corporation

Proprietary and Confidential

Architecture
Scalable, Available
NoSQL DB Driver Application

Shard 1

Load Balancer

Shard 2

NoSQL DB Driver

Application

Shard N

Email Client

App. Tier

Storage Tier
20

2014 Oracle Corporation

Proprietary and Confidential

Data Access Layer


Email Client
UserDAO
User Creation User Login - addUser(userTO) - getUser(email, password) - addDefaultFolder(userId)

FolderDAO
Add default folders

MessageDAO
Add email message addMessage(messageTO)

UserFolderMessageDAO
Add messages to designated folders addMessage(userId, folderId, messageId)

21

2014 Oracle Corporation

Proprietary and Confidential

Join NoSQL Database Community


Oracle.com/BigData Twitter https://twitter.com/#!/OracleNoSQL LinkedIn http://www.linkedin.com/groups?gid=4147754 Oracles NoSQL DB blog https://blogs.oracle.com/nosql Oracle Technology Network http://bit.ly/1f0d8wU Developer Webcast Series http://bit.ly/1doV2jl
22

2014 Oracle Corporation

Proprietary and Confidential

23

2014 Oracle Corporation

Proprietary and Confidential

You might also like