News

New Couchbase N1QL Language Allows SQL Queries over JSON Data

Couchbase Inc., long the champion of its "world's highest-performing NoSQL distributed database platform," has apparently decided that this SQL stuff isn't so bad after all, having announced a new language called N1QL that allows SQL queries over JSON data stored in its document-oriented database.

N1QL is pronounced "nickel" and plays on the database normalization term "non-first normal form" to stand for "Non-first Normal Form Query Language." Couchbase yesterday announced that N1QL, unveiled in February, is a primary component of its new Couchbase Server 4.0, just released in beta.

"N1QL is based on SQL," Couchbase said. "It has familiar data definition language (DDL), data manipulation language (DML) and query language statements, yet it works on NoSQL database features such as key-value stores, multi-value attributes and nested objects. If you know SQL, you can easily learn N1QL -- in fact, you're already more than halfway there."

Couchbase exec Cihan Biyikoglu explained in a blog post that the company added the "SQL gene" to Couchbase Server because the long-lived SQL is the most powerful language used for querying data. He said it's already a familiar tool used by many data developers and has become the de-facto standard for queries among disparate tools and platforms in the relational database ecosystem ("It may be the only thing both you and your computer-scientist parent have in common.").

A Complex Example Query in the Online, Interactive Tutorial
[Click on image for larger view.] A Complex Example Query in the Online, Interactive Tutorial (source: Couchbase Inc.)

While SQL has traditionally been used to query data stored in relational database management systems (RDBMS) according to a rigid schema of inter-related tables that contain rows and columns, Couchbase has developed N1QL to query data stored as JSON, popularized in Web development as a companion tool to JavaScript (JSON stands for JavaScript Object Notation) to transmit data as attribute-value pairs between servers and clients.

"Relational SQL operates over tables and columns and needs a strict schema," Biyikoglu said. "With N1QL, all queries are executed over JSON data in Couchbase Server. You don't have to deal with a strict tables and columns structure or worry about changing schema as your data model evolves.

"N1QL will adapt to the schema the JSON documents present as they get created and updated in your Couchbase Server bucket. Unlike SQL in relational databases, attributes like quantity or price ... can be missing. You can express your query either to disqualify documents that do not contain the attribute or you can query the attribute only when it exists."

To let developers play around with N1QL without having to install Couchbase Server, the company has provided an online, interactive query language tutorial where queries can be run against an example database. Developers can also use the company's "Getting Started" guide. For developers who want to jump right in with the software, Couchbase Server with N1QL can be downloaded here.

"Couchbase Server with N1QL will change the game for direct access to data within NoSQL, and without moving the data first," the company quoted Frank Bien, CEO of customer company Looker Data Sciences Inc., as saying. "N1QL makes operational analytics and insights possible for the enterprise to access and transform data by querying Couchbase Server through a familiar SQL interface -- this eliminates one of the major barriers to using NoSQL for mission-critical applications."

The new query language is the latest example of JSON moving beyond its Web roots into the world of databases, further evidenced by JSON support being highlighted by Microsoft as an important feature of its upcoming SQL Server 2016 release.

In addition to the new query language, the company detailed numerous other updates to its beta Couchbase Server 4.0, including multi-dimensional scaling. That allows developers to decompose a database into separate services for querying, indexing and storage. Those services can run on different nodes, avoiding resource contention and allowing for hardware optimization, and individual services can be scaled as needed.

"Couchbase has redefined the way enterprises scale distributed databases with the option of multi-dimensional scaling," exec Ilam Siva said in a blog post. "It not only separates and isolates but also scales services individually -- query, index, and data -- to improve application performance and increase resource utilization. Couchbase Server 4.0 is the first and only distributed database capable of scaling with the speed and precision required by enterprise applications with variable workloads."

Couchbase Server 4.0 also comes with Global Secondary Indexing, which facilitates faster N1QL queries in Big Data scenarios by leveraging secondary index fields without having to use MapReduce; ForestDB, a new-age storage engine optimized for multi-core processors and solid-state drives; simplified security compliance to meet regulatory standards and rules; and cross-datacenter replication filtering, a way to make data available to separate geographic locations with low latency.

About the Author

David Ramel is an editor and writer for Converge360.