Let's talk about NoSQL Standard

  • View
    30

  • Download
    1

Embed Size (px)

Transcript

  • Let's talk about NoSQL Standard

    Otvio Santana@otaviojavaotaviojava@java.netotaviojava@apache.org

    mailto:otaviojava@java.netmailto:otaviojava@java.netmailto:otaviojava@apache.orgmailto:otaviojava@apache.org

  • NoSQL

    Database Doesn't use relationship BASE Five types

  • Key Value

    AmazonDynamo AmazonS3 Redis Scalaris Voldemort Couchbase

    valuekey

    valuekey

    valuekey

  • Document

    AmazonSimpleDb ApacheCouchdb MongoDb Riak Couchbase

  • Column

    Hbase Cassandra Scylla Clouddata SimpleDb DynamoDB

    Row-key Columns...

    Apollo

    Aphrodite

    Ares

    SunDuty

    {Love, happy}Duty

    WarDuty

    Swordweapon

    Color

    Kratos

    Dead Gods13

  • Graph

    Neo4j InfoGrid Sones HyperGraphDB

    Apollo Ares

    Kratos

    was dead was dead

    Is brother

    killed killed

  • Multi-model

    OrientDB Couchbase Elasticsearch Cassandra

  • The Problem

  • The Problem

  • The Current solution

    Spring Data Hibernate OGM TopLink

  • The Perfect Solution

    Abstraction API Communication API No lock-in Split problems

  • Apache Diana was Born (incubator)

    API Communication layer Apache Project Document, key-value, Column, Graph Universal Adapter 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.

  • Diana Project

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

  • Diana Project

  • Why Diana?

    Goddess of the hunt, nature and moon

    Fought in Troy brave warrior and hunter

  • Road Map

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

  • Nomenclature

    Configuration Factory Manager Entity Value

  • Value

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

  • Custom Value

    public class MoneyWriter implements WriterField {

    @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 read(Class clazz, Object value) { return (T) Money.parse(value.toString()); }}

  • 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 documents = entity.getDocuments();Optional age = entity.find("age");

  • 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 documents = entity.getDocuments();Optional age = entity.find("age");

  • 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 columns = entity.getColumns();Optional notFound = entity.find("notFound");

  • Entities

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

  • Entities

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

  • 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 id = entitySaved.find("_id");query.addCondition(DocumentCondition.eq(id.get()));List documentsFound = collectionManager.find(query);DocumentCollectionEntity document = collectionManager.findOne(query);

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

  • 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 entities = columnEntityManager.find(query);ColumnFamilyEntity family = columnEntityManager.findOne(query);

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

  • Manager

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

  • Factory

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

  • Factory

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

  • 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();

  • Native Query

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

  • Native Query

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

  • 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;

  • 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;

  • 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;

  • 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;

  • 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