Skip to content

RawCombinedQueryDefinition in QueryBatcher throws NPE #1242

Closed
@georgeajit

Description

@georgeajit

Version of MarkLogic Java Client API

develop (post 5.2.0 tag release)

Version of MarkLogic Server

10.0 night (post 10.0-4 server release)

Java version

Java 9

OS and version

Linux and Windows

Input: Some code to illustrate the problem, preferably in a state that can be independently reproduced on our end

Given a combined query such as one here https://github.com/marklogic/java-client-api/blob/develop/marklogic-client-api-functionaltests/src/test/java/com/marklogic/client/functionaltest/combined/combinedQueryOptionJSON.json

{"search":{"query":{"value-constraint-query":{"constraint-name":"id", "text":"0026"}}, "options":{"return-metrics":false, "return-qtext":false, "debug":true, "transform-results":{"apply":"raw"}, "constraint":{"name":"id", "value":{"element":{"ns":"", "name":"id"}}}}}}

and data files

constraint1.xml

<root>
  <title>Vannevar Bush</title>
  <popularity>5</popularity>
  <id>0011</id>
  <date xmlns="http://purl.org/dc/elements/1.1/">2005-01-01</date>
  <price xmlns="http://cloudbank.com" amt="0.1"/>
  <p>Vannevar Bush wrote an article for The Atlantic Monthly</p>
</root>

constraint2.xml

<root>
  <title>The Bush article</title>
  <popularity>4</popularity>
  <id>0012</id>
  <date xmlns="http://purl.org/dc/elements/1.1/">2006-02-02</date>
  <price xmlns="http://cloudbank.com" amt="0.12"/>
  <p>The Bush article described a device called a Memex.</p>
</root>

constraint3.xml

<root>
  <title>For 1945</title>
  <popularity>3</popularity>
  <id>0113</id>
  <date xmlns="http://purl.org/dc/elements/1.1/">2007-03-03</date>
  <price xmlns="http://cloudbank.com" amt="1.23"/>
  <p>For 1945, the thoughts expressed in The Atlantic Monthly were groundbreaking.</p>
</root>

constraint4.xml

<root>
  <title>Vannevar served</title>
  <popularity>5</popularity>
  <id>0024</id>
  <date xmlns="http://purl.org/dc/elements/1.1/">2008-04-04</date>
  <price xmlns="http://cloudbank.com" amt="12.34"/>
  <p>Vannevar served as a prominent policymaker and public intellectual.</p>
</root>

constraint5.xml

<root>
  <title>The memex</title>
<popularity>5</popularity>
<id>0026</id>
<date xmlns="http://purl.org/dc/elements/1.1/">2009-05-05</date>
<price xmlns="http://cloudbank.com" amt="123.45"/>
<p>The Memex, unfortunately, had no automated search feature.</p>
</root>

A QueryBatcher with RawCombinedQueryDefinition created with help of a Handle, when run, produces NPE
The same RawCombinedQueryDefinition when run with a QueryManager, produces the desired result.

Sample code:

     WriteBatcher wbatcher = dmManagerTmp.newWriteBatcher();

      wbatcher.withBatchSize(2);
      InputStreamHandle contentHandle1 = new InputStreamHandle();
      contentHandle1.set(new FileInputStream(dataFileDir + filenames[0]));
      InputStreamHandle contentHandle2 = new InputStreamHandle();
      contentHandle2.set(new FileInputStream(dataFileDir + filenames[1]));
      InputStreamHandle contentHandle3 = new InputStreamHandle();
      contentHandle3.set(new FileInputStream(dataFileDir + filenames[2]));
      InputStreamHandle contentHandle4 = new InputStreamHandle();
      contentHandle4.set(new FileInputStream(dataFileDir + filenames[3]));
      InputStreamHandle contentHandle5 = new InputStreamHandle();
      contentHandle5.set(new FileInputStream(dataFileDir + filenames[4]));

      wbatcher.add(filenames[0], contentHandle1);
      wbatcher.add(filenames[1], contentHandle2);
      wbatcher.add(filenames[2], contentHandle3);
      wbatcher.add(filenames[3], contentHandle4);
      wbatcher.add(filenames[4], contentHandle5);

      wbatcher.flushAndWait();
      // get the combined query
      File file = new File(combQueryFileDir + combinedQueryFileName);

      String combinedQuery = convertFileToString(file);

      // create a handle for the search criteria
      StringHandle rawHandle = new StringHandle(combinedQuery);
      rawHandle.setFormat(Format.JSON);

      // create a handle for the search criteria
      //FileHandle rawHandle = (new FileHandle(file)).withFormat(Format.JSON);
      // create a search definition based on the handle
      RawCombinedQueryDefinition querydef = queryMgr.newRawCombinedQueryDefinition(rawHandle);

      /*String wordQuery = "<cts:word-query xmlns:cts=\"http://marklogic.com/cts\">" +
              "<cts:text>unfortunately</cts:text></cts:word-query>";
      StringHandle handle = new StringHandle().with(wordQuery);
      RawCtsQueryDefinition querydef = queryMgr.newRawCtsQueryDefinition(handle);*/

      StringBuilder batchResults = new StringBuilder();
      StringBuilder batchFailResults = new StringBuilder();

      // Run a QueryBatcher on the new URIs.
      QueryBatcher queryBatcher1 = dmManagerTmp.newQueryBatcher(querydef);

      queryBatcher1.onUrisReady(batch -> {
        for (String str : batch.getItems()) {
          batchResults.append(str)
              .append('|');
        }
      });
      queryBatcher1.onQueryFailure(throwable -> {
        System.out.println("Exceptions thrown from callback onQueryFailure");
        batchFailResults.append(throwable.getMessage());
        batchFailResults.append("Test has Exceptions");
      });

      dmManagerTmp.startJob(queryBatcher1);
      boolean bJobFinished = queryBatcher1.awaitCompletion(3, TimeUnit.MINUTES);
...
...

Actual output: What did you observe? What errors did you see? Can you attach the logs? (Java logs, MarkLogic logs)

Listener QueryFailure StringBuilder variable has java.lang.NullPointerException

Expected output: What specifically did you expect to happen?

URI returned in StringBuilder should be constraint5.xml.

Alternatives: What else have you tried, actual/expected?

Used a simple word-query as QueryDefinition, the results returned are as expected.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions