15.07.2016 Views

MARKLOGIC SERVER

Inside-MarkLogic-Server

Inside-MarkLogic-Server

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

SQL/ODBC ACCESS FOR BUSINESS INTELLIGENCE<br />

You might be surprised that MarkLogic offers a SQL/ODBC interface. After all, the<br />

"S" in SQL stands for Structured, so how does that work against a document-oriented<br />

database? And why do it, anyway?<br />

The purpose of the SQL system is to provide a read-only view of the database<br />

suitable for driving a Business Intelligence (BI) tool—such as IBM Cognos, Tableau, or<br />

MicroStrategy—that expects databases to adhere to the relational model. The "tables"<br />

accessed in MarkLogic are fully synthetic; everything remains as documents. The tables<br />

are constructed as "views" placed atop range indexes. If, for example, your database<br />

stores financial trades with configured range indexes on the date, counterparty, and<br />

value elements, then you can have those values as your columns. There's a special<br />

column (whose name matches the name of the view) that represents the full document<br />

data. It's possible to use that special column to specify constraints against the full<br />

document data via the SQL MATCH operator. This feature looks small but has big<br />

implications because it lets you limit the retrieved rows based on any part of the<br />

backing document, even parts that aren't exposed in the SQL view.<br />

Everything executes out of memory. The system is similar in some ways to columnar<br />

databases in that columns are stored together rather than rows, and the tuples are<br />

created as part of the query using an n-way co-occurrence. The SQL version is<br />

SQL92 as implemented in SQLite with the addition of SET, SHOW, and DESCRIBE<br />

statements.<br />

MarkLogic exposes SQL via ODBC, a standard C-based API for accessing relational<br />

databases. (For testing you can use the XQuery xdmp:sql() function or an MLSQL<br />

command-line tool.) The ODBC driver is based on the open source PostgreSQL<br />

ODBC driver.<br />

Doing data modeling for a relational view on top of a document back-end requires<br />

some consideration. If a document has multiple values for a single range index (which<br />

isn't possible in normal relational modeling), it has to be represented as a cross-product<br />

across multiple rows. If a range index value is missing or invalid, there's a configuration<br />

option for how to handle that. If the view defines the column as "nullable," then the<br />

given column value is shown as null. If it's not "nullable," the document doesn't match<br />

the required constraints and produces no rows.<br />

For more information, see the SQL Data Modeling Guide.<br />

QUERY CONSOLE FOR REMOTE CODING<br />

Not actually a protocol unto itself, but still widely used by programmers wanting raw<br />

access to MarkLogic, is the Query Console web-based code execution environment. A<br />

web application included with the server, it's fundamentally just a set of XQuery and<br />

65

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!