42
Let's talk about NoSQL Standard Otávio Santana @otaviojava [email protected] [email protected]

Let's talk about NoSQL Standard

Embed Size (px)

Citation preview

Page 2: Let's talk about NoSQL Standard

NoSQL

● Database● Doesn't use relationship● BASE● Five types

Page 3: Let's talk about NoSQL Standard

Key Value

● AmazonDynamo● AmazonS3● Redis● Scalaris● Voldemort ● Couchbase

valuekey

valuekey

valuekey

Page 4: Let's talk about NoSQL Standard

Document

● AmazonSimpleDb● ApacheCouchdb● MongoDb● Riak● Couchbase

Page 5: Let's talk about NoSQL Standard

Column

● Hbase● Cassandra● Scylla● Clouddata● SimpleDb● DynamoDB

Row-key Columns...

Apollo

Aphrodite

Ares

SunDuty

{Love, happy}Duty

WarDuty

Swordweapon

Color

Kratos

Dead Gods13

Page 6: Let's talk about NoSQL Standard

Graph

● Neo4j● InfoGrid● Sones● HyperGraphDB

Apollo Ares

Kratos

was dead was dead

Is brother

killed killed

Page 7: Let's talk about NoSQL Standard

Multi-model

● OrientDB● Couchbase● Elasticsearch● Cassandra

Page 8: Let's talk about NoSQL Standard

The Problem

Page 9: Let's talk about NoSQL Standard

The Problem

Page 10: Let's talk about NoSQL Standard

The Current solution

● Spring Data● Hibernate OGM● TopLink

Page 11: Let's talk about NoSQL Standard

The Perfect Solution

● Abstraction API● Communication API● No lock-in● Split problems

Page 12: Let's talk about NoSQL Standard

Apache Diana was Born (incubator)

● API Communication layer● Apache Project● Document, key-value, Column, Graph● Universal Adapter● Standard

Page 13: Let's talk about NoSQL Standard

What Diana is not

● A new API to replace JPA● A new API to abstraction layer● Just one API communication to solve all kind of NoSQL

database● Be responsible to do integrations with other technologies such

as CDI, EJB, Bean Validation, Spring, etc.

Page 14: Let's talk about NoSQL Standard

Diana Project

● Commons API● Document API● Graph API● Key-value API● Column API● Four TCKs

Page 15: Let's talk about NoSQL Standard

Diana Project

Page 16: Let's talk about NoSQL Standard

Why Diana?

● Goddess of the hunt, nature and moon

● Fought in Troy● brave warrior and hunter

Page 17: Let's talk about NoSQL Standard

Road Map

● Draft and code Proposal● Community Feedback● Involve NoSQL Vendors● Involve Solution Vendors● Apache Project● Development● JSR

Page 18: Let's talk about NoSQL Standard

Nomenclature

● Configuration● Factory● Manager● Entity● Value

Page 19: Let's talk about NoSQL Standard

Value

Value value = Value.of("123");Integer integerValue = value.get(Integer.class);List<Integer> list = value.getList(Integer.class);Set<Integer> set = value.getSet(Integer.class);Stream<Integer> stream = value.getStream(Integer.class);String cast = value.cast();//unsafe

Page 20: Let's talk about NoSQL Standard

Custom Value

public class MoneyWriter implements WriterField<Money, String> {

@Override public boolean isCompatible(Class clazz) { return false; }

@Override public String write(Money object) { return object.toString();

}}

public class MoneyReader implements ReaderField {

@Override public boolean isCompatible(Class clazz) { return Money.class.equals(clazz); }

@Override public <T> T read(Class<T> clazz, Object value) { return (T) Money.parse(value.toString()); }}

Page 21: Let's talk about NoSQL Standard

Entities

Money money = new Money();Value value = Value.of(money);DocumentCollectionEntity entity = DocumentCollectionEntity.of("collection");entity.add(Document.of("name", "Daniel Soro"));entity.add(Document.of("age", 26));entity.add(Document.of("salary", money));

String name = entity.getName();List<Document> documents = entity.getDocuments();Optional<Document> age = entity.find("age");

Page 22: Let's talk about NoSQL Standard

Entities

Money money = new Money();Value value = Value.of(money);DocumentCollectionEntity entity = DocumentCollectionEntity.of("collection");entity.add(Document.of("name", "Daniel Soro"));entity.add(Document.of("age", 26));entity.add(Document.of("salary", money));entity.add(Document.of("subdocument", Document.of("sub", Arrays.asList(1, 2, 3))));

String name = entity.getName();List<Document> documents = entity.getDocuments();Optional<Document> age = entity.find("age");

Page 23: Let's talk about NoSQL Standard

EntitiesMoney money = new Money();Value value = Value.of(money);

ColumnFamilyEntity entity = ColumnFamilyEntity.of("family");Column id = Column.of("id", 10L);entity.add(id);entity.add(Column.of("version", 0.001));entity.add(Column.of("name", "Diana"));entity.add(Column.of("options", Arrays.asList(1, 2, 3)));entity.add(Column.of("pay", value));

String name = entity.getName();List<Column> columns = entity.getColumns();Optional<Column> notFound = entity.find("notFound");

Page 24: Let's talk about NoSQL Standard

Entities

Value value = Value.of(new Money());KeyValue<String> keyValue = KeyValue.of("key", value);String key = keyValue.getKey();Value value1 = keyValue.getValue();

Page 25: Let's talk about NoSQL Standard

Entities

Value value = Value.of(new Money());KeyValue<String> keyValue = KeyValue.of("key", value);String key = keyValue.getKey();Value value1 = keyValue.getValue();

Page 26: Let's talk about NoSQL Standard

ManagerDocumentCollectionEntity entitySaved = collectionManager.save(entity);collectionManager.save(entity, TTL.ofHours(2));collectionManager.saveAsync(entity);collectionManager.saveAsync(entity, TTL.ofDays(3));collectionManager.saveAsync(entity, System.out::print);

DocumentQuery query = DocumentQuery.of("collection");Optional<Document> id = entitySaved.find("_id");query.addCondition(DocumentCondition.eq(id.get()));List<DocumentCollectionEntity> documentsFound = collectionManager.find(query);DocumentCollectionEntity document = collectionManager.findOne(query);

collectionManager.delete(query);collectionManager.deleteAsync(query);collectionManager.deleteAsync(query, System.out::print);

Page 27: Let's talk about NoSQL Standard

Manager

columnEntityManager.save(entity);columnEntityManager.saveAsync(entity);columnEntityManager.saveAsync(entity, TTL.ofDays(3));columnEntityManager.saveAsync(entity, System.out::print);

ColumnQuery query = ColumnQuery.of("family");query.addCondition(ColumnCondition.eq(id));List<ColumnFamilyEntity> entities = columnEntityManager.find(query);ColumnFamilyEntity family = columnEntityManager.findOne(query);

columnEntityManager.delete(query);columnEntityManager.deleteAsync(query);columnEntityManager.deleteAsync(query, System.out::print);

Page 28: Let's talk about NoSQL Standard

Manager

KeyValue<String> keyValue = KeyValue.of("myKey", Value.of("value"));bucket.put("key", "value");bucket.put(keyValue);bucket.put(keyValue, TTL.ofMicros(12));Optional<Value> value = bucket.get("key");

Page 29: Let's talk about NoSQL Standard

Factory

BucketManager bucket = managerFactory.getBucketManager("bucket");List<String> list = managerFactory.getList("bucketList", String.class);Set<String> set = managerFactory.getSet("bucketSet", String.class);Map<String, Integer> map = managerFactory.getMap("bucketList", String.class, Integer.class);Queue<String> queue = managerFactory.getQueue("queueList", String.class);

Page 30: Let's talk about NoSQL Standard

Factory

ColumnFamilyManager columnEntityManager = columnManagerFactory.getColumnEntityManager("space");DocumentCollectionManager collection = documentManagerFactory.getDocumentEntityManager("collection");

Page 31: Let's talk about NoSQL Standard

Configuration

ColumnConfiguration columnConfiguration = new ColumnDriver();DocumentConfiguration documentConfiguration = new DocumentDriver();KeyValueConfiguration keyValueConfiguration = new KeyValueDriver();

ColumnFamilyManagerFactory columnFactory = columnConfiguration.getManagerFactory();DocumentCollectionManagerFactory documentFactory = documentConfiguration.getManagerFactory();BucketManagerFactory keyFactory = keyValueConfiguration.getManagerFactory();

Page 32: Let's talk about NoSQL Standard

Native Query

columnEntityManager.nativeQueryAsync(query, System.out::println);List<ColumnFamilyEntity> entities = columnEntityManager.nativeQuery(query);PreparedStatement preparedStatement = columnEntityManager.nativeQueryPrepare(query);preparedStatement.bind(1,2,3);preparedStatement.executeQuery();preparedStatement.executeQueryAsync(System.out::println);

Page 33: Let's talk about NoSQL Standard

Native Query

collectionManager.nativeQueryAsync(query, System.out::println);List<DocumentCollectionEntity> entities = collectionManager.nativeQuery(query);PreparedStatement preparedStatement = collectionManager.nativeQueryPrepare(query);preparedStatement.bind(1,2,3);preparedStatement.executeQuery();preparedStatement.executeQueryAsync(System.out::println);

Page 34: Let's talk about NoSQL Standard

Diana Query Language

Select

select * from bucket;

select key1, key2 from bucket;

Insert

INSERT INTO bucket VALUES (key, value);

INSERT INTO bucket VALUES (key, value) ttl 20 (seconds, minutes, hours, days);

Delete

DELETE FROM bucket WHERE id =value;

Page 35: Let's talk about NoSQL Standard

Diana Query Language

Insert

INSERT INTO collection (column1,column2,column3,...)

VALUES (value1,value2,value3,...);

INSERT INTO collection (column1,column2,column3,...)

VALUES (value1,value2,value3,...) (value1,value2,value3,...);

INSERT INTO collection (column1,column2,column3,...)

VALUES (value1,value2,value3,...) ttl 20 (seconds, minutes, hours, days);

INSERT INTO collection (column1,column2,column3,...)

VALUES (value1,value2,value3,...) ttl 20 (seconds, minutes, hours, days) async;

Page 36: Let's talk about NoSQL Standard

Diana Query Language

Select

select * from collection;

select field, field2 from collection;

select field, field2 from collection where id = 2;

select field, field2 from collection where id >= 2 or field >3;

Delete

DELETE FROM collection WHERE id =value;

DELETE field, field2 FROM collection WHERE id =value;

Page 37: Let's talk about NoSQL Standard

Diana Query LanguageInsert

INSERT INTO family (column1,column2,column3,...)

VALUES (value1,value2,value3,...);

INSERT INTO family (column1,column2,column3,...)

VALUES (value1,value2,value3,...) (value1,value2,value3,...);

INSERT INTO family (column1,column2,column3,...)

VALUES (value1,value2,value3,...) ttl 20 (seconds, minutes, hours, days);

INSERT INTO family (column1,column2,column3,...)

VALUES (value1,value2,value3,...) ttl 20 (seconds, minutes, hours, days) async;

Page 38: Let's talk about NoSQL Standard

Diana Query Language

Select

select * from family;

select field, field2 from family;

select field, field2 from family where id = 2;

select field, field2 from family where id >= 2 and index >3;

Delete

DELETE FROM family WHERE id =value;

DELETE field, field2 FROM family WHERE id =value;

Page 39: Let's talk about NoSQL Standard

Site

https://jnosql.github.io/diana-site/

Page 40: Let's talk about NoSQL Standard

Code

https://github.com/JNOSQL

Page 41: Let's talk about NoSQL Standard

Apache Proposal

https://wiki.apache.org/incubator/DianaProposal