bi, integration, and apps on couchbase using simba odbc and jdbc
TRANSCRIPT
![Page 1: BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC](https://reader036.vdocuments.mx/reader036/viewer/2022062400/587bfbf41a28ab7c668b5987/html5/thumbnails/1.jpg)
Open ConnectivityBI, Integration, and Apps on Couchbase using ODBC
and JDBCJune, 2015
![Page 2: BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC](https://reader036.vdocuments.mx/reader036/viewer/2022062400/587bfbf41a28ab7c668b5987/html5/thumbnails/2.jpg)
• Who I am• Driver(s) Overview• Relational Model• Demos• ODBC in-depth• JDBC in-depth• QA
Contents
![Page 3: BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC](https://reader036.vdocuments.mx/reader036/viewer/2022062400/587bfbf41a28ab7c668b5987/html5/thumbnails/3.jpg)
• Worked in the data access space for eight years and counting• ODBC, OLEDB, JDBC, ADO.NET, ODBO, XMLA
• Core developer for the current generation of Simba’s data access technologies
• Collaborated at an Engineering Level with Simba ISV Customers to design and implement data drivers that are today being shipped world wide
Kyle at a glance
![Page 4: BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC](https://reader036.vdocuments.mx/reader036/viewer/2022062400/587bfbf41a28ab7c668b5987/html5/thumbnails/4.jpg)
• Simba connects people to data.• HQ’ed in Vancouver, BC.• 100ish employees.• Founded in 1991.• In 1992, Simba co-authored the original ODBC standard with Microsoft.• Simba produces the SimbaEngine® SDK and drivers for the leading
data sources on multiple platforms.
Simba Technologies at a glance
![Page 5: BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC](https://reader036.vdocuments.mx/reader036/viewer/2022062400/587bfbf41a28ab7c668b5987/html5/thumbnails/5.jpg)
Simba Technologies at a glance
![Page 6: BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC](https://reader036.vdocuments.mx/reader036/viewer/2022062400/587bfbf41a28ab7c668b5987/html5/thumbnails/6.jpg)
![Page 7: BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC](https://reader036.vdocuments.mx/reader036/viewer/2022062400/587bfbf41a28ab7c668b5987/html5/thumbnails/7.jpg)
• Partnership to create read/write ODBC and JDBC drivers• ODBC 3.80• JDBC 4.0 and 4.1
• Allow easy access to data within Couchbase from your favourite BI and ETL tools
Why is Simba here?
![Page 8: BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC](https://reader036.vdocuments.mx/reader036/viewer/2022062400/587bfbf41a28ab7c668b5987/html5/thumbnails/8.jpg)
What is an ODBC / JDBCDriver?N1QL mode to alloweasy and advancedanalytics
![Page 9: BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC](https://reader036.vdocuments.mx/reader036/viewer/2022062400/587bfbf41a28ab7c668b5987/html5/thumbnails/9.jpg)
• Couchbase is NoSQL• Dynamic schema, documents vary within a bucket
• ODBC and JDBC are SQL• Expect a fixed schema, each column is one type
• Must map from dynamic schema data to fixed schema data
Schema(less)
![Page 10: BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC](https://reader036.vdocuments.mx/reader036/viewer/2022062400/587bfbf41a28ab7c668b5987/html5/thumbnails/10.jpg)
• SQL• Catalog, Schema, Table
• Couchbase• Namespace, Keyspace
Schema => NamespaceTable => Keyspace (sort of)
Relational Mapping
http://www.prabathsl.com/2013/02/document-oriented-database_14.html
![Page 11: BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC](https://reader036.vdocuments.mx/reader036/viewer/2022062400/587bfbf41a28ab7c668b5987/html5/thumbnails/11.jpg)
Sample JSON Document:{“Id” : 1, “Name”: “Couchbase”, “Values” : [V1,V2]}
Simple Flattening
Id Name Values[0] Values[1]
1 Couchbase V1 V2
![Page 12: BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC](https://reader036.vdocuments.mx/reader036/viewer/2022062400/587bfbf41a28ab7c668b5987/html5/thumbnails/12.jpg)
Sample JSON Document:{“Id” : 1, “Name”: “Couchbase”, “Values” : [V1,V2]}
Parent
Child
Re-Normalization
Id Name1 Couchbase
Id Index Value
1 0 V1
1 1 V2
![Page 13: BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC](https://reader036.vdocuments.mx/reader036/viewer/2022062400/587bfbf41a28ab7c668b5987/html5/thumbnails/13.jpg)
Demos
![Page 14: BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC](https://reader036.vdocuments.mx/reader036/viewer/2022062400/587bfbf41a28ab7c668b5987/html5/thumbnails/14.jpg)
• C API• Versions: 2.x, 3.0, 3.52, 3.80, etc…• Non-Windows platforms are ODBC 3.52
• Driver Managers• Windows, iODBC, unixODBC, etc…
• All functions have return codes• SQL_SUCCESS, SQL_SUCCESS_WITH_INFO, SQL_ERROR, etc…
ODBC Technicals
![Page 15: BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC](https://reader036.vdocuments.mx/reader036/viewer/2022062400/587bfbf41a28ab7c668b5987/html5/thumbnails/15.jpg)
• SQLHENV, SQLHDBC, SQLHSTMT, SQLHDESC
• Relationship is one-to-many
ODBC: Handles
![Page 16: BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC](https://reader036.vdocuments.mx/reader036/viewer/2022062400/587bfbf41a28ab7c668b5987/html5/thumbnails/16.jpg)
• Allocate with SQLAllocHandle, free with SQLFreeHandle• Ensure you set the version of ODBC in use
SQLSetEnvAttr(hEnv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3_80, SQL_IS_INTEGER)
ODBC: Environment
![Page 17: BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC](https://reader036.vdocuments.mx/reader036/viewer/2022062400/587bfbf41a28ab7c668b5987/html5/thumbnails/17.jpg)
• Allocate with SQLAllocHandle, created from SQLHENV• Maintains the actual connection to Couchbase• Create child statement objects to do work• Disconnect with SQLDisconnect, free with SQLFreeHandle
ODBC: Connection
![Page 18: BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC](https://reader036.vdocuments.mx/reader036/viewer/2022062400/587bfbf41a28ab7c668b5987/html5/thumbnails/18.jpg)
Open a connection using SQLDriverConnectSQLDriverConnect(
hDbc, windowHandle, connStr, SQL_NTS, connStrLen&outStrLen,SQL_DRIVER_COMPLETE)
Last parameter allows driver to prompt for information if connStr doesn’t contain all necessary information.
ODBC: Connection
![Page 19: BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC](https://reader036.vdocuments.mx/reader036/viewer/2022062400/587bfbf41a28ab7c668b5987/html5/thumbnails/19.jpg)
• Specify a Driver or DSN• Driver: Must specify all options in connection string• DSN: Can specify options in connection string
Example:“DSN=Couchbase;UID=kylep;PWD=testPassword;”
ODBC: Connection String
![Page 20: BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC](https://reader036.vdocuments.mx/reader036/viewer/2022062400/587bfbf41a28ab7c668b5987/html5/thumbnails/20.jpg)
• Allocate with SQLAllocHandle, created from SQLHSTMT• Used for issuing queries, retrieving catalog metadata• Free with SQLFreeHandle
ODBC: Statement
![Page 21: BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC](https://reader036.vdocuments.mx/reader036/viewer/2022062400/587bfbf41a28ab7c668b5987/html5/thumbnails/21.jpg)
• Use SQLExecDirect for one-off queries• Use SQLPrepare and SQLExecute for repeated queries
SQLExecDirect(hStmt, “<query>”, SQL_NTS)
orSQLPrepare(hStmt, “<query>”, SQL_NTS)SQLExecute(hStmt)
ODBC: Querying
![Page 22: BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC](https://reader036.vdocuments.mx/reader036/viewer/2022062400/587bfbf41a28ab7c668b5987/html5/thumbnails/22.jpg)
• After execution, there is a cursor on the results, positioned before the first row
• Use SQLFetch to move the cursor• SQLGetData can be used to fetch cell by cell• SQLBindCol can also be used, much more efficient
ODBC: Results
![Page 23: BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC](https://reader036.vdocuments.mx/reader036/viewer/2022062400/587bfbf41a28ab7c668b5987/html5/thumbnails/23.jpg)
• Reuse connections so driver caches are effective
• Use SQLBindCol over SQLGetData
• Use array fetches with SQLBindCol
• Use SQLPrepare once, SQLExecute multiple times with parameters for loading data
• Use parameter arrays when binding parameters with SQLBindParameter
• Bind types to match reported parameter or column types
ODBC: Performance Tips
![Page 24: BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC](https://reader036.vdocuments.mx/reader036/viewer/2022062400/587bfbf41a28ab7c668b5987/html5/thumbnails/24.jpg)
SQLGetData vs. SQLBindCol
10 million rows, 3 columns of wide char, integer, decimal values
ODBC: Performance Tips
Method Time (s)SQLGetData 141.428SQLBindCol 6.102SQLBindCol (array[100]) 2.747
![Page 25: BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC](https://reader036.vdocuments.mx/reader036/viewer/2022062400/587bfbf41a28ab7c668b5987/html5/thumbnails/25.jpg)
• Is the Java version of ODBC• Versions: 3.0, 4.0, 4.1, etc…• JDBC version is tied to Java version
• Simba will supply JDBC 4.0 and 4.1 versions• There is a driver manager, but role is very limited• Errors are reported via exceptions, warnings via getWarnings()
JDBC Technicals
![Page 26: BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC](https://reader036.vdocuments.mx/reader036/viewer/2022062400/587bfbf41a28ab7c668b5987/html5/thumbnails/26.jpg)
• Relationship is again one-to-many
JDBC: Object Hierarchy
![Page 27: BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC](https://reader036.vdocuments.mx/reader036/viewer/2022062400/587bfbf41a28ab7c668b5987/html5/thumbnails/27.jpg)
• Never used directly by your code• Must be loaded by referencing using Class.forName()• FQCNs• com.simba.couchbase.jdbc4.Driver• com.simba.couchbase.jdbc41.Driver
• URL• “jdbc:couchbase://<host>:<port>/<schema>;UseN1QLMode=0/1”
JDBC: Driver
![Page 28: BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC](https://reader036.vdocuments.mx/reader036/viewer/2022062400/587bfbf41a28ab7c668b5987/html5/thumbnails/28.jpg)
• ExampleString url = “jdbc:couchbase://localhost:8093/default;”Class.forName(“com.simba.couchbase.jdbc4.Driver”);Connection con = DriverManager.getConnection(url);
• With JDBC 4.0 and later, Class.forName() can be omitted
JDBC: Driver
![Page 29: BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC](https://reader036.vdocuments.mx/reader036/viewer/2022062400/587bfbf41a28ab7c668b5987/html5/thumbnails/29.jpg)
• Used directly by your code• FQCNs• com.simba.couchbase.jdbc4.DataSource• com.simba.couchbase.jdbc41.DataSource
• Can be used to programmatically set connection properties by using functions instead of a connection string
• Allows use of advanced features such as PooledConnection• Used less often than Driver
JDBC: DataSource
![Page 30: BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC](https://reader036.vdocuments.mx/reader036/viewer/2022062400/587bfbf41a28ab7c668b5987/html5/thumbnails/30.jpg)
• Can create child statement objects for queries• Can create DatabaseMetaData objects for metadata via getMetaData()
• Common pitfalls• Not closing connections; use a finally block to ensure it is closed• Not checking warnings, ever; call getWarnings() regularly• Creating a new connection for every operation; reuse connections where
possible
JDBC: Connection
![Page 31: BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC](https://reader036.vdocuments.mx/reader036/viewer/2022062400/587bfbf41a28ab7c668b5987/html5/thumbnails/31.jpg)
• DatabaseMetaData• Created by Connection objects• Actually only one object per connection, cached and reused • Provides access to catalog metadata• getCatalogs(), getTables(), getColumns(), etc…
• Provides access to database metadata• getDatabaseProductVersion(), getIdentifierQuoteString(), etc…
JDBC: Database MetaData
![Page 32: BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC](https://reader036.vdocuments.mx/reader036/viewer/2022062400/587bfbf41a28ab7c668b5987/html5/thumbnails/32.jpg)
• Created by Connection objects• Three different types• Statement – for one-off querying• PreparedStatement – for queries with parameters• CallableStatement – for stored procedures with output
parameters*
• Statement objects will eventually dispose of themselves once out of scope, but best practice is to close() them when done
JDBC: Statement Objects
![Page 33: BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC](https://reader036.vdocuments.mx/reader036/viewer/2022062400/587bfbf41a28ab7c668b5987/html5/thumbnails/33.jpg)
• Cannot use parameters• Use execute(), executeQuery(), or executeUpdate() to
execute SQL or N1QL queries
JDBC: Statement
![Page 34: BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC](https://reader036.vdocuments.mx/reader036/viewer/2022062400/587bfbf41a28ab7c668b5987/html5/thumbnails/34.jpg)
execute() ExampleStatement stmt = conn.createStatement();try {
if (stmt.execute(“select * from beer-sample”)) {ResultSet rs = stmt.getResultSet();rs.close();
}}finally {
stmt.close();}
JDBC: Statement
![Page 35: BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC](https://reader036.vdocuments.mx/reader036/viewer/2022062400/587bfbf41a28ab7c668b5987/html5/thumbnails/35.jpg)
• For use with parameters• Can get metadata about results before execution with getResultSetMetaData()
• Can get metadata about parameters using getParameterMetaData()
• Use set*() functions to provide parameter values
JDBC: PreparedStatement
![Page 36: BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC](https://reader036.vdocuments.mx/reader036/viewer/2022062400/587bfbf41a28ab7c668b5987/html5/thumbnails/36.jpg)
• When loading data, use batches• Set all required parameters for one execution• Call addBatch() to add the current set of parameters• Call executeBatch() to execute all added batches at once
• Set parameters as reported types to avoid conversion overhead in the driver
• Reuse the statement for multiple executions
JDBC: PreparedStatement
![Page 37: BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC](https://reader036.vdocuments.mx/reader036/viewer/2022062400/587bfbf41a28ab7c668b5987/html5/thumbnails/37.jpg)
• Represents query results or catalog metadata• Describe the result set using getMetaData()• Move through result using next()• Can use isAfterLast(), isFirst(), isLast(), etc. to check cursor
position.
• Retrieve cell values using get*() methods• The driver supports all conversions between types listed by the JDBC spec• Try to retrieve as requested type to avoid conversion overhead• Remember to check wasNull() after calling get*() method
JDBC: ResultSet
![Page 38: BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC](https://reader036.vdocuments.mx/reader036/viewer/2022062400/587bfbf41a28ab7c668b5987/html5/thumbnails/38.jpg)
ResultSet ExampleResultSet rs = stmt.executeQuery(“<query>”);try { int numColumns = rs.getMetaData().getColumnCount();
while (rs.next()) { for (int i = 0; i < numColumns; ++i) { System.out.println(rs.getString(i)); }}
}finally {
rs.close();}
JDBC: ResultSet
![Page 39: BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC](https://reader036.vdocuments.mx/reader036/viewer/2022062400/587bfbf41a28ab7c668b5987/html5/thumbnails/39.jpg)
Q & A
![Page 40: BI, Integration, and Apps on Couchbase using Simba ODBC and JDBC](https://reader036.vdocuments.mx/reader036/viewer/2022062400/587bfbf41a28ab7c668b5987/html5/thumbnails/40.jpg)
simba.com