Skip to content

complexValues reference option is not returning any result on queryAsStream() #484

Description

@ayuwono

Steps:

  1. Setup: node config-optic/setupqa.js
  2. The result has a column (the column name is 'xml') with complex values (xml elements). If complexValues is specified as 'inline', it will return the result:
  it('TEST 8 - construct xml from Triples with queryAsStream', function(done){
    let count = 0;
    let str = '';
    const chunks = [];
    const bb = op.prefixer('http://marklogic.com/baseball/players/');
    const ageCol = op.col('age');
    const idCol = op.col('id');
    const nameCol = op.col('name');
    const posCol = op.col('position');
    const output =
      op.fromTriples([
        op.pattern(idCol, bb('age'), ageCol),
        op.pattern(idCol, bb('name'), nameCol),
        op.pattern(idCol, bb('position'), posCol)
      ])
      .where(
        op.and(
          op.le(ageCol, 25),
          op.eq(posCol, 'Catcher')
        )
      )
      .orderBy(op.desc(ageCol))
      .select([
        op.as('PlayerName', nameCol),
        op.as('PlayerPosition', posCol),
        op.as('PlayerAge', ageCol)
      ])
      .select([
        'PlayerName',
        'PlayerPosition',
        'PlayerAge',
        op.as('xml',
          op.xmlDocument(
            op.xmlElement(
              'root',
              op.xmlAttribute('attrA', op.col('PlayerName')),
              [
                op.xmlElement('elemA', null, op.col('PlayerPosition')),
                op.xmlElement('elemACodePoints', null, op.fn.stringToCodepoints(op.col('PlayerPosition'))),
                op.xmlElement('elemB', null, op.col('PlayerAge')),
                op.xmlElement('elemC', null, op.math.sqrt(op.col('PlayerAge')))
              ]
            )
          )
        )
      ])
    db.rows.queryAsStream(output, 'chunked', { format: 'json', structure: 'object', columnTypes: 'header', complexValues: 'reference' })
    .on('data', function(chunk) {
      console.log(chunk.toString());
      //str = str + chunk.toString().trim().replace(/[\n\r]/g, ' ');
      count++;
    }).
    on('end', function() {
      //console.log(str);
      console.log(count);
      done();
    }, done);
  });

Result:

{
"columns": [{"name":"PlayerName","type":"xs:string"},{"name":"PlayerPosition","type":"xs:string"},{"name":"PlayerAge","type":"xs:integer"},{"name":"xml","type":"element"}],
"rows":[
{"PlayerName":"Pat Crenshaw","PlayerPosition":"Catcher","PlayerAge":25,"xml":"<root attrA=\"Pat Crenshaw\"><elemA>Catcher</elemA><elemACodePoints>67 97 116 99 104 101 114</elemACodePoints><elemB>25</elemB><elemC>5</elemC></root>"}]
}

But if I change the complexValues to "reference", the result is empty (count = 0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions