12 Replies Latest reply on Oct 31, 2013 5:36 AM by rakeshsagar

    NullPointerException in SortUtility

    rakeshsagar

      Hi,

       

      We are getting NullPointerException when executing the following query:

      We are using teiid 8.5 with the patch applied for the JIRA [TEIID-2672] java.lang.AssertionError: Assertion failed in SourceState - JBoss Issue Tracker

       

      select kc_datasources.DATASOURCE_NAME, kc_datasources.DATASOURCE_KEY, kc_datasources.DATASOURCE_INDEX_LOCATION FROM (

      SELECT DATASOURCE_NAME, DATASOURCE_KEY, DATASOURCE_INDEX_LOCATION,'in_platform' as ORDER_POS from chorus_platform_chorus_metadata.kc_datasource

      union

      SELECT DATASOURCE_NAME, DATASOURCE_KEY, DATASOURCE_INDEX_LOCATION,'others' as ORDER_POS from dbmzdb2_chorus_metadata.kc_datasource

      )  AS kc_datasources ORDER BY kc_datasources.ORDER_POS,kc_datasources.DATASOURCE_NAME ASC

       

      Both the data sources are file data sources.

       

      Caused by: org.teiid.core.TeiidException

        at org.teiid.client.ResultsMessage.setException(ResultsMessage.java:194)

        at org.teiid.dqp.internal.process.RequestWorkItem.sendError(RequestWorkItem.java:958)

        at org.teiid.dqp.internal.process.RequestWorkItem.close(RequestWorkItem.java:543)

        at org.teiid.dqp.internal.process.RequestWorkItem.process(RequestWorkItem.java:346)

        at org.teiid.dqp.internal.process.AbstractWorkItem.run(AbstractWorkItem.java:51)

        at org.teiid.dqp.internal.process.RequestWorkItem.run(RequestWorkItem.java:248)

        at org.teiid.dqp.internal.process.DQPCore.executeRequest(DQPCore.java:307)

        at sun.reflect.GeneratedMethodAccessor119.invoke(Unknown Source)

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

        at java.lang.reflect.Method.invoke(Method.java:607)

        at org.teiid.logging.LogManager$LoggingProxy.invoke(LogManager.java:121)

        at org.teiid.jboss.TransportService$2.invoke(TransportService.java:234)

        at com.sun.proxy.$Proxy19.executeRequest(Unknown Source)

        at sun.reflect.GeneratedMethodAccessor119.invoke(Unknown Source)

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

        at java.lang.reflect.Method.invoke(Method.java:607)

        at org.teiid.transport.LocalServerConnection$1$1.call(LocalServerConnection.java:137)

        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)

        at java.util.concurrent.FutureTask.run(FutureTask.java:166)

        at org.teiid.dqp.internal.process.DQPWorkContext.runInContext(DQPWorkContext.java:269)

        at org.teiid.dqp.internal.process.DQPWorkContext.runInContext(DQPWorkContext.java:253)

        at org.teiid.transport.LocalServerConnection$1.invoke(LocalServerConnection.java:135)

        at com.sun.proxy.$Proxy19.executeRequest(Unknown Source)

        at org.teiid.jdbc.StatementImpl.execute(StatementImpl.java:634)

        at org.teiid.jdbc.StatementImpl.executeSql(StatementImpl.java:509)

        ... 59 more

      Caused by: java.lang.NullPointerException

        at org.teiid.query.processor.relational.SortUtility.initialSort(SortUtility.java:303)

        at org.teiid.query.processor.relational.SortUtility.sort(SortUtility.java:190)

        at org.teiid.query.processor.relational.SortNode.sortPhase(SortNode.java:111)

        at org.teiid.query.processor.relational.SortNode.nextBatchDirect(SortNode.java:91)

        at org.teiid.query.processor.relational.RelationalNode.nextBatch(RelationalNode.java:278)

        at org.teiid.query.processor.relational.LimitNode.nextBatchDirect(LimitNode.java:102)

        at org.teiid.query.processor.relational.RelationalNode.nextBatch(RelationalNode.java:278)

        at org.teiid.query.processor.relational.ProjectNode.nextBatchDirect(ProjectNode.java:146)

        at org.teiid.query.processor.relational.RelationalNode.nextBatch(RelationalNode.java:278)

        at org.teiid.query.processor.relational.RelationalPlan.nextBatch(RelationalPlan.java:136)

        at org.teiid.query.processor.QueryProcessor.nextBatchDirect(QueryProcessor.java:151)

        at org.teiid.query.processor.QueryProcessor.nextBatch(QueryProcessor.java:114)

        at org.teiid.query.processor.BatchCollector.collectTuples(BatchCollector.java:155)

        at org.teiid.dqp.internal.process.RequestWorkItem.processMore(RequestWorkItem.java:435)

        at org.teiid.dqp.internal.process.RequestWorkItem.process(RequestWorkItem.java:320)

        ... 80 more

       

      Is this a teiid bug or are we doing something wrong?

       

      Thanks

      Rakesh

        • 1. Re: NullPointerException in SortUtility
          shawkins

          Can you provide the query plan?

          • 2. Re: NullPointerException in SortUtility
            rakeshsagar

            Attached is the query plan.

            • 3. Re: NullPointerException in SortUtility
              shawkins

              The SortNode 111 line number does not match up to either the 8.5 final or the patched version.  Can you try without your patch and see if you get the same exception?

              • 4. Re: NullPointerException in SortUtility
                rakeshsagar

                Ok, I will try and update you on this.

                 

                The following is the code which we are using for the SortNode.

                Line number 111 is this.output = this.sortUtility.sort();

                 

                private void sortPhase() throws BlockedException, TeiidComponentException, TeiidProcessingException {

                    if (this.sortUtility == null) {

                    TupleSource ts = null;

                    if (!getChildren()[0].hasBuffer(true)) {

                    ts = new BatchIterator(getChildren()[0]);

                    }

                         this.sortUtility = new SortUtility(ts, items, this.mode, getBufferManager(),

                                    getConnectionID(), getChildren()[0].getElements());

                        

                         if (ts == null) {

                           this.sortUtility.setWorkingBuffer(getChildren()[0].getBuffer(-1));

                         }

                 

                 

                  }

                  this.output = this.sortUtility.sort();

                  if (this.outputTs == null) {

                  this.outputTs = this.output.createIndexedTupleSource();

                  }

                    if (rowLimit >= 0) {

                  this.output.truncateTo(rowLimit);

                  if (!this.output.isFinal() && this.output.getRowCount() == rowLimit) {

                  this.output.close();

                  }

                  }

                        this.phase = OUTPUT;

                    }

                • 5. Re: NullPointerException in SortUtility
                  rakeshsagar

                  Hi Steve,

                   

                  I tried without the patch and it works fine without any issues.

                   

                  I re-applied the patch to the source code of 8.5.Final downloaded from the downloads page and the issue is reproducable.

                  Looks like the issue is with the changes made for the JIRA issue.

                  Earlier due to eclipse formatting the line numbers did not match.

                  The following the stack trace and attached is the SortNode java file.

                   

                  Caused by: org.teiid.jdbc.TeiidSQLException: org.teiid.core.TeiidException

                    at org.teiid.jdbc.TeiidSQLException.create(TeiidSQLException.java:135)

                    at org.teiid.jdbc.TeiidSQLException.create(TeiidSQLException.java:71)

                    at org.teiid.jdbc.StatementImpl.postReceiveResults(StatementImpl.java:667)

                    at org.teiid.jdbc.StatementImpl.access$100(StatementImpl.java:63)

                    at org.teiid.jdbc.StatementImpl$2.onCompletion(StatementImpl.java:515)

                    at org.teiid.client.util.ResultsFuture.addCompletionListener(ResultsFuture.java:148)

                    at org.teiid.jdbc.StatementImpl.executeSql(StatementImpl.java:511)

                    at org.teiid.jdbc.PreparedStatementImpl.executeQuery(PreparedStatementImpl.java:261)

                    at com.ca.chorus.db.DbExecutor.withResultSet(DbExecutor.java:384)

                    ... 59 more

                  Caused by: org.teiid.core.TeiidException

                    at org.teiid.client.ResultsMessage.setException(ResultsMessage.java:194)

                    at org.teiid.dqp.internal.process.RequestWorkItem.sendError(RequestWorkItem.java:958)

                    at org.teiid.dqp.internal.process.RequestWorkItem.close(RequestWorkItem.java:543)

                    at org.teiid.dqp.internal.process.RequestWorkItem.process(RequestWorkItem.java:346)

                    at org.teiid.dqp.internal.process.AbstractWorkItem.run(AbstractWorkItem.java:51)

                    at org.teiid.dqp.internal.process.RequestWorkItem.run(RequestWorkItem.java:248)

                    at org.teiid.dqp.internal.process.DQPCore.executeRequest(DQPCore.java:307)

                    at sun.reflect.GeneratedMethodAccessor88.invoke(Unknown Source)

                    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

                    at java.lang.reflect.Method.invoke(Method.java:601)

                    at org.teiid.logging.LogManager$LoggingProxy.invoke(LogManager.java:121)

                    at org.teiid.jboss.TransportService$2.invoke(TransportService.java:234)

                    at $Proxy19.executeRequest(Unknown Source)

                    at sun.reflect.GeneratedMethodAccessor88.invoke(Unknown Source)

                    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

                    at java.lang.reflect.Method.invoke(Method.java:601)

                    at org.teiid.transport.LocalServerConnection$1$1.call(LocalServerConnection.java:137)

                    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)

                    at java.util.concurrent.FutureTask.run(FutureTask.java:166)

                    at org.teiid.dqp.internal.process.DQPWorkContext.runInContext(DQPWorkContext.java:269)

                    at org.teiid.dqp.internal.process.DQPWorkContext.runInContext(DQPWorkContext.java:253)

                    at org.teiid.transport.LocalServerConnection$1.invoke(LocalServerConnection.java:135)

                    at $Proxy19.executeRequest(Unknown Source)

                    at org.teiid.jdbc.StatementImpl.execute(StatementImpl.java:634)

                    at org.teiid.jdbc.StatementImpl.executeSql(StatementImpl.java:509)

                    ... 61 more

                  Caused by: java.lang.NullPointerException

                    at org.teiid.query.processor.relational.SortUtility.initialSort(SortUtility.java:303)

                    at org.teiid.query.processor.relational.SortUtility.sort(SortUtility.java:190)

                    at org.teiid.query.processor.relational.SortNode.sortPhase(SortNode.java:109)

                    at org.teiid.query.processor.relational.SortNode.nextBatchDirect(SortNode.java:91)

                    at org.teiid.query.processor.relational.RelationalNode.nextBatch(RelationalNode.java:278)

                    at org.teiid.query.processor.relational.LimitNode.nextBatchDirect(LimitNode.java:102)

                    at org.teiid.query.processor.relational.RelationalNode.nextBatch(RelationalNode.java:278)

                    at org.teiid.query.processor.relational.ProjectNode.nextBatchDirect(ProjectNode.java:146)

                    at org.teiid.query.processor.relational.RelationalNode.nextBatch(RelationalNode.java:278)

                    at org.teiid.query.processor.relational.RelationalPlan.nextBatch(RelationalPlan.java:136)

                    at org.teiid.query.processor.QueryProcessor.nextBatchDirect(QueryProcessor.java:151)

                    at org.teiid.query.processor.QueryProcessor.nextBatch(QueryProcessor.java:114)

                    at org.teiid.query.processor.BatchCollector.collectTuples(BatchCollector.java:155)

                    at org.teiid.dqp.internal.process.RequestWorkItem.processMore(RequestWorkItem.java:435)

                    at org.teiid.dqp.internal.process.RequestWorkItem.process(RequestWorkItem.java:320)

                    ... 82 more

                  • 6. Re: NullPointerException in SortUtility
                    shawkins

                    When I run a similar plan locally I don't see an issue.  Can you build from the 8.5.x branch instead - it has the TEIID-2672 fix applied already?  That will insure that there are no issues with the application of the patch.

                     

                    Steve

                    • 7. Re: NullPointerException in SortUtility
                      rakeshsagar

                      Ok, I will try that.

                      Can you please let me know how to download the code from the 8.5.x branch.

                      I do not see a download link using this URL https://source.jboss.org/changelog/~br=8.5.x/Teiid

                       

                      Thanks

                      Rakesh.

                      • 8. Re: NullPointerException in SortUtility
                        shawkins

                        The easiest way is to use git.  Or you could try doing a zip download from github - https://github.com/teiid/teiid/archive/8.5.x.zip

                         

                        Steve

                        • 9. Re: NullPointerException in SortUtility
                          rakeshsagar

                          Hi Steve,

                           

                          Thanks for the git link.

                          I built the code from 8.5.x branch and I still get the NullPointerException by executing the SQL.

                           

                          Thanks

                          Rakesh

                          • 10. Re: NullPointerException in SortUtility
                            shawkins

                            Yes, I can reproduce it now.  Will update the fix in the appropriate branches shortly.

                            • 11. Re: NullPointerException in SortUtility
                              shawkins

                              Ok this has been corrected.  The issue was that if we blocked on getting the working buffer then since we had already constructed the sortutility the next time through we'd get an npe.

                               

                              Thanks for catching this,

                              Steve

                              • 12. Re: NullPointerException in SortUtility
                                rakeshsagar

                                I applied the patch and that fixed the problem.

                                Thanks Steve.