4 Replies Latest reply on Jul 4, 2014 1:57 AM by Ashish Sarin

    Reusing QueryService of Teiid Designer

    Ashish Sarin Newbie

      Hi,

       

      We are creating a web based client that will act as a replacement of Teiid Designer. As Teiid Designer is responsible for generating SQL queries based on the metadata, we thought that we'll reuse the query generation/parsing capability of Teiid Designer. Our web based client will use the query generation/parsing capability to generate SQLs and pass it to the Teiid runtime.

       

      As I was going through the source code, I saw that there is a QueryService class (located in org,teiid.runtime.client plugin project) that provides access to the QueryParser, Validator and classes like ProcedureService, that help in creating SQL queries based on metadata information.

       

      Now, I've the following questions:

      1. Can we take the org,teiid.runtime.client plugin and expose its QueryService as a RESTful web service to out web client. This doesn't seem to be a problem to me if I write code to directly instantiate the QueryService class. If I start from the TeiidRuntimeRegistry class (which eventually creates an instance of QueryService), the dependency on Eclipse plugin infrastructure acts as a bottleneck.

      2. If I directly create a QueryService instance, what are the things we need to take care to ensure that QueryService behaves correctly?

       

      I've written the following code to quickly test if QueryParser is correctly initialized. And, it looks like it is.

       

      import org.teiid.designer.query.IQueryParser;
      import org.teiid.designer.query.IQueryService;
      import org.teiid.designer.runtime.version.spi.TeiidServerVersion;
      import org.teiid.designer.udf.IFunctionLibrary.FunctionName;
      import org.teiid.runtime.client.query.QueryService;
      
      
      public class TestQueryService {
        public static void main(String args[]) {
        try {
            // TeiidRuntimeRegistry registry =
            // TeiidRuntimeRegistry.getInstance();
            IQueryService queryService = new QueryService(new TeiidServerVersion("8", "7", "0"));
      
            IQueryParser queryParser = queryService.getQueryParser();
            System.out.println(queryService.getReservedWords());
            System.out.println(queryService.getJDBCSQLTypeName(1));
            System.out.println(queryService.getNonReservedWords());
            System.out.println(queryParser.parseCommand("SELECT * FROM ABCD"));
            System.out.println(queryParser.parseDesignerCommand("SELECT * FROM ABCD"));
            System.out.println(queryService.createFunctionLibrary().getFunctionName(FunctionName.CONCAT));
        } catch (Exception e) {
                // TODO Auto-generated catch block
               e.printStackTrace();
        }
        }
      }
      

       

      thanks

      ashish

        • 1. Re: Reusing QueryService of Teiid Designer
          Ramesh Reddy Master

          I highly doubt you can get much further without getting dependency issues with Eclipse. My suggestion is to see the underlying calls in QueryService is using to Teiid, and try mimic that in your own code. Depending upon what you are doing this is can be big undertaking. Would love here more about the usecase.

           

          Ramesh..

          1 of 1 people found this helpful
          • 2. Re: Reusing QueryService of Teiid Designer
            Barry LaFond Master

            The org,teiid.runtime.client in Teiid Designer is designed to handle multiple Teiid runtime client versions and be backwards compatible (> Teiid 7.7 release) for query validation as well as artifact structure. This plugin is also based on Teiid source snapshots.

             

            The actual Teiid runtime is backwards compatible from an artifact standpoint (VDB).

             

            If your target Teiid runtime is more current (i.e. Teiid 8.4+) then it may make more sense to use the Teiid source as your starting point rather than Teiid Designer.

             

            BTW... in our Komodo initiative, we're attempting to create a runtime service that is NOT dependent on Eclipse.

             

            Barry

            Teiid Designer Project Lead

            1 of 1 people found this helpful
            • 3. Re: Reusing QueryService of Teiid Designer
              phantomjinx Newbie

              Hi,

               

              Off the top of my head here are some things to note:

              • The runtime client plugin has a dependency on the Designer spi plugin and uses a large number of interfaces from it so I would expect that to be in your classpath;
              • The QueryService is designed to be a one-stop accesspoint for client-side query/resolve/validation of teiid SQL syntax allowing compatibility for Teiid 7.7 - 8.7. So the version provided is fed all the way down into the guts of the SQL parsed tree. Thus, I would expect to ensure that the teiid version passed in matches that of your server;
              • The lib directory of the client plugin must be populated with dependent libraries using the build.xml and pom.xml files. If your lib directory is empty then expect runtime ClassNotFound related exceptions;
              • In order to resolve queries an implementation of IMetadataQueryInterface will be required. This provides the objects (taken from Designer models) that queries use for there criteria testing, eg. in WHERE clauses. This is not a trivial interface to implement!

               

              If you carefully consider those then you should be able to feed SQL into the QueryService and get a syntax tree as well as be able to resolve it and validate it.

               

              Hope that provides a little more insight.

               

              phantomjinx

              • 4. Re: Reusing QueryService of Teiid Designer
                Ashish Sarin Newbie

                Hi Ramesh/Barry/phantomjinx,

                 

                We are building a web client (instead of using the Eclipse based Teiid Designer) through which clients visual build their VDBs. As the SQL query generation and validation is required before the SQL query is saved as part of the VDB metadata, we want to reuse the Teiid Designer code for query generation and validation.

                 

                I was going through the source code of both Teiid Designer and Teiid runtime. I saw that it makes more sense to use Teiid runtime's SystemMetadata class as the starting point to generate/validate SQL queries. Teiid Designer code seems to be more tightly coupled with the use of INDEX files, and depends on particular packaging of the classes.

                 

                Please let me know your thoughts.

                 

                regards

                ashish