Native APIs for Querying Couchbase Server with N1QL: Couchbase Connect

38
Native APIs for Querying Couchbase Server with N1QL Jeff Morris | Software Engineer, Couchbase Michael Nitschinger | Software Engineer, Couchbase

Transcript of Native APIs for Querying Couchbase Server with N1QL: Couchbase Connect

Page 1: Native APIs for Querying Couchbase Server with N1QL: Couchbase Connect

Native APIs for Querying Couchbase Server with N1QL

Jeff Morris | Software Engineer, CouchbaseMichael Nitschinger | Software Engineer, Couchbase

Page 2: Native APIs for Querying Couchbase Server with N1QL: Couchbase Connect

©2014 Couchbase, Inc. 2

Everything shown in this talk is a preview and subject to change before we ship official N1QL integration.

Take everything with a grain of salt and give us feedback to make it even better.

Disclaimer

Page 3: Native APIs for Querying Couchbase Server with N1QL: Couchbase Connect

Introduction

Page 4: Native APIs for Querying Couchbase Server with N1QL: Couchbase Connect

©2014 Couchbase, Inc. 4

Motivation

Querying is integral to Couchbase Server

SDKs need to provide first-class querying for Views N1QL

The 2.0 SDKs provide document oriented APIs and querying needsto blend together

Page 5: Native APIs for Querying Couchbase Server with N1QL: Couchbase Connect

©2014 Couchbase, Inc. 5

N1QL Overview

N1QL (“Nickel”) is the next generation query language for Couchbase Server

Designed to be similar to SQL First-Class JSON support

Currently in Developer Preview See http://query.couchbase.com

Supports SELECT, DML, DDL SDKs focus is on SELECT for now

Page 6: Native APIs for Querying Couchbase Server with N1QL: Couchbase Connect

©2014 Couchbase, Inc. 6

N1QL Primer: Select

Page 7: Native APIs for Querying Couchbase Server with N1QL: Couchbase Connect

©2014 Couchbase, Inc. 7

N1QL Primer: Joins

Page 8: Native APIs for Querying Couchbase Server with N1QL: Couchbase Connect

8

N1QL Primer: Popular Products in Category

©2014 Couchbase, Inc.

Page 9: Native APIs for Querying Couchbase Server with N1QL: Couchbase Connect

©2014 Couchbase, Inc. 9

2.0 Querying API

Provides consistent experience across Views N1QL

Blends into Document API

Sweet spot between Consistency across SDKs Language features

Page 10: Native APIs for Querying Couchbase Server with N1QL: Couchbase Connect

N1QL Querying in .NET

Page 11: Native APIs for Querying Couchbase Server with N1QL: Couchbase Connect

©2014 Couchbase, Inc. 11

Query Generators and Executers

• Ad-hoc queries• New LINQ Provider

Mapping results and Handling Errors

• Query Mapping• Query Results

N1QL Query Support in .NET SDK 2.0

Page 12: Native APIs for Querying Couchbase Server with N1QL: Couchbase Connect

©2014 Couchbase, Inc. 12

Part of the SDK 2.0 IBucket interface

Standard un-typed, string based queries

No syntactical help

Results can be mapped to POCOs or to a dynamic type

Supports all N1QL commands, keywords, etc

Errors are handled and propagated up to the caller

The current query interface for N1QL queries in Couchbase Server

Github Url: https://github.com/couchbase/couchbase-net-client

Ad-Hoc Queries

Page 13: Native APIs for Querying Couchbase Server with N1QL: Couchbase Connect

©2014 Couchbase, Inc. 13

Ad-hoc Query Example

Page 14: Native APIs for Querying Couchbase Server with N1QL: Couchbase Connect

©2014 Couchbase, Inc. 14

The QueryResult object

Page 15: Native APIs for Querying Couchbase Server with N1QL: Couchbase Connect

©2014 Couchbase, Inc. 15

Handling Errors

Page 16: Native APIs for Querying Couchbase Server with N1QL: Couchbase Connect

©2014 Couchbase, Inc. 16

Mapping to Types

Page 17: Native APIs for Querying Couchbase Server with N1QL: Couchbase Connect

©2014 Couchbase, Inc. 17

An extension of the Couchbase .NET SDK 2.0 Open Source Apache 2.0 License

Pull requests kindly accepted! Github url: https://github.com/couchbaselabs/Linq2Couchbase Brings familiar LINQ syntax to N1QL and Couchbase Server Currently supports a minimal subset of the N1QL language (this will

soon change) Errors are un-handled Results are mapped to POCOs The “future” query interface for N1QL and Couchbase Server in .NET

Linq2Couchbase

Page 18: Native APIs for Querying Couchbase Server with N1QL: Couchbase Connect

©2014 Couchbase, Inc. 18

Basic Queries

Page 19: Native APIs for Querying Couchbase Server with N1QL: Couchbase Connect

©2014 Couchbase, Inc. 19

Basic Queries: Projections to Anonymous Types

Page 20: Native APIs for Querying Couchbase Server with N1QL: Couchbase Connect

©2014 Couchbase, Inc. 20

Basic Queries: “where” clause

Page 21: Native APIs for Querying Couchbase Server with N1QL: Couchbase Connect

©2014 Couchbase, Inc. 21

Basic Queries: limit and range queries

Page 22: Native APIs for Querying Couchbase Server with N1QL: Couchbase Connect

22

Expect a GA released with N1QL GA

Eventually a “full-featured” LINQ provider

Anything that is not supported by the LINQ provider can be done via

IBucket.Query<T>(string query)

Linq2Couchbase: Future Support

©2014 Couchbase, Inc.

Page 23: Native APIs for Querying Couchbase Server with N1QL: Couchbase Connect

.NET Demo

Page 24: Native APIs for Querying Couchbase Server with N1QL: Couchbase Connect

N1QL Querying in Java

Page 25: Native APIs for Querying Couchbase Server with N1QL: Couchbase Connect

©2014 Couchbase, Inc. 25

Java SDK API

Access types Asynchronous (Reactive) using Rx Observables Synchronous

Utilizes a JSON streaming parser and pushes chunks as they arriveWorks on a per-bucket basis

Page 26: Native APIs for Querying Couchbase Server with N1QL: Couchbase Connect

©2014 Couchbase, Inc. 26

The Result of a Query

Page 27: Native APIs for Querying Couchbase Server with N1QL: Couchbase Connect

©2014 Couchbase, Inc. 27

The Row

Page 28: Native APIs for Querying Couchbase Server with N1QL: Couchbase Connect

©2014 Couchbase, Inc. 28

Synchronous Querying

Page 29: Native APIs for Querying Couchbase Server with N1QL: Couchbase Connect

©2014 Couchbase, Inc. 29

Synchronous Querying

Page 30: Native APIs for Querying Couchbase Server with N1QL: Couchbase Connect

©2014 Couchbase, Inc. 30

Asynchronous Querying

Page 31: Native APIs for Querying Couchbase Server with N1QL: Couchbase Connect

©2014 Couchbase, Inc. 31

N1QL DSL

The SDK ships with a N1QL DSL syntax aware (based on the EBNF) strongly typed

Should be used in favor of the raw string Makes developing N1QL queries a breeze Built-in IDE autocomplete awareness

Heavily inspired by jOOQ (http://www.jooq.org/)

Page 32: Native APIs for Querying Couchbase Server with N1QL: Couchbase Connect

©2014 Couchbase, Inc. 32

IDE Support

Page 33: Native APIs for Querying Couchbase Server with N1QL: Couchbase Connect

©2014 Couchbase, Inc. 33

IDE Support

Page 34: Native APIs for Querying Couchbase Server with N1QL: Couchbase Connect

©2014 Couchbase, Inc. 34

IDE Support

Page 35: Native APIs for Querying Couchbase Server with N1QL: Couchbase Connect

©2014 Couchbase, Inc. 35

Examples

Page 36: Native APIs for Querying Couchbase Server with N1QL: Couchbase Connect

©2014 Couchbase, Inc. 36

Examples

Page 37: Native APIs for Querying Couchbase Server with N1QL: Couchbase Connect

Java Demo

Page 38: Native APIs for Querying Couchbase Server with N1QL: Couchbase Connect

QA