Skip to main content

SQL on MongoDB using Teiid - Part 1

In this article series, I will showcase how you can use SQL based queries with MongoDB. In general there seems to be resurgence of SQL based access to all NoSQL based stores in the market space, take for example Hive, Impala, Spark, Apache Drill etc. The main reason for this shift is there are abundant amount of talent pool out there for SQL based developers, and even today (and years to come) our strong dependence on the relational stores for the enterprise data. I do not see either of them fading away any time soon. So utilizing the known skills on new types of data stores will save you lot of time and provide better integration with rest of your enterprise applications.

I know there are plenty of folks offering SQL based access to MongoDB, why you should choose Teiid?
  • Teiid provides full ANSI compatible SQL based access to MongoDB. This includes full SQL-92, and most SQL-99 and SQL-2003 support.
  • Provides JDBC/ODBC access to execute SQL queries.
  • Provides ODATA based access to MongoDB.
  • Provides framework to easily create custom REST based services over MongoDB or any other data source
  • Teiid is a data virtualization system, that means you can integrate data from MongoDB with other enterprise sources like Orcale, DB2, SQL Server etc.
  • Complex nested document support up to three+ levels of embedded documents. I have not seen any other project support more than one level of nested documents.
  • Supports full range of SELECT, INSERT, UPDATE and DELETE calls.
  • Array support, Blob Support, GEO functions support.  
  • A JBoss community Open Source project.
Depending upon your architecture and needs there are different ways you use Teiid with MongoDB
  • Standalone Teiid server
  • Embedded Teiid
  • Teiid Docker 
However, in all the above are only different deployment scenarios, as per defining your interaction with MongoDB in-terms of SQL is exactly same. In this article I will focus on Standalone Teiid Server. I will not go in any details about installation of Teiid or MongoDB. Also, I assume user already has familiarity with Teiid concepts, if not please read http://teiid.jboss.org/basics/ and go through a quick start example here https://docs.jboss.org/author/display/teiidexamples/Teiid+Quick+Starts

So, let's get started. 

  <resource-adapters>   
   <resource-adapter id="mongodb">   
    <module slot="main" id="org.jboss.teiid.resource-adapter.mongodb"/>   
    <transaction-support>NoTransaction</transaction-support>   
    <connection-definitions>   
     <connection-definition class-name="org.teiid.resource.adapter.mongodb.MongoDBManagedConnectionFactory"   
       jndi-name="java:/mongoDS"   
       enabled="true"   
       use-java-context="true"   
       pool-name="teiid-mongodb-ds">   
      <!-- MongoDB server list (host:port[;host:port...]) -->   
      <config-property name="RemoteServerList">localhost:27017</config-property>   
      <!-- Database Name in the MongoDB -->   
      <config-property name="Database">test</config-property>   
       <!--    
        Uncomment these properties to supply user name and password   
       <config-property name="Username">user</config-property>   
       <config-property name="Password">user</config-property>   
       -->    
     </connection-definition>   
    </connection-definitions>   
   </resource-adapter>   
  </resource-adapters>  

  • The above will create a JCA connection pool to the MongoDB. Save it and start the JBoss EAP.
  • Now it is time to create VDB. The following shows a very simple VDB

 <vdb name="nothwind" version="1">  
   <model name="northwind">  
     <source name="local" translator-name="mongodb" connection-jndi-name="java:/mongoDS"/>  
       <metadata type="DDL"><![CDATA[  
         CREATE FOREIGN TABLE Customer (  
           customer_id integer,  
           FirstName varchar(25),  
           LastName varchar(25)  
         ) OPTIONS(UPDATABLE 'TRUE');  
       ]]> </metadata>  
   </model>  
 <vdb>  

Now deploy this VDB using either web-console or CLI into Teiid. Make sure it is deployed in ACTIVE state. Now using any JDBC client like SquirreL, and issue SQL queries like


 INSERT INTO Customer(customer_id, FirstName, LastName) VALUES (1, 'John', 'Doe');  

This will produce a document like below in the MongoDB database.

 {  
  _id: ObjectID("509a8fb2f3f4948bd2f983a0"),  
  customer_id: 1,  
  FirstName: "John",  
  LastName: "Doe"  
 }  

If you issue a query like

 SELECT * FROM Customer  

you will see the result like

 customer_id  FirstName  LastName  
 1           John       Doe  

This is a illustration of what it takes to use SQL on MongoDB using Teiid. But we only scratched SQL capabilities. In the next article I will show case, how to create complex nested documents and resulting SQL/DDL for it.

Thanks

Ramesh..

Comments

  1. Part 2 - http://teiid.blogspot.com/2015/06/sql-on-mongodb-using-teiid-part-2.html

    ReplyDelete

Post a Comment

Popular posts from this blog

Teiid Platform Sizing Guidelines and Limitations

Users/customers always ask us about the sizing of their Data Virtaulization infrastructure based on Teiid or the JDV product from Redhat. Typically this is very involved question and not a very easy one answer in plain terms. This is due to fact that it involves taking into consideration questions like:
What kind of sources that user is working with? Relational, file, CRM, NoSQL etc.How many sources they are trying to integrate? 10, 20, 100?What are the volumes of data they are working with? 10K, 100K, 1M+?What are the query latency times from the sources? How you are using Teiid to implement the data integration/virtualization solution. What kind of queries that user is executing? Even small federated results may take a lot of server side processing - especially if the plan needs tweaking.Is materializing being used?Is query written in optimal way?and so on..Each and every one of the question affects the performance profoundly, and if you got mixture of those then it become that much…

Teiid Runtimes Explained

If you have been following Teiid lately we have been going through a whole lot of renovations. Yes, renovations or reorganization or refactoring or whatever you want to call it. Basically, we are making Teiid more modular with fewer dependencies that can be used by however your use case dictates rather than use it as one monolith application deployed into WildFly JEE Application Server. There is nothing wrong in using Teiid as server model, but with the proliferation of container-based workloads and cloud-based architectures, the previous server-based model does not work or simply won't scale. So, we needed to think of alternatives, thus Teiid team introduced a couple different versions modular Teiid what we are calling as "Teiid Runtimes".

Note that in these modular Teiid runtimes, not all the features you were used to using in Teiid Server model may not be there but you will have extensions to add in those that are most appropriate for your domain. If you are looking …