Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ok, here's my stab at the problem. </p> <p>Here's a sketch of the nodes and edges tables:</p> <pre><code>[nodes] node : varchar(xx) [edges] outputNode : varchar(xx) inputNode : varchar(xx) </code></pre> <p>Assuming your db has support for CTEs, then a query structured like this will bring together the relationships and concatenate results:</p> <pre><code>/* pair output nodes with a topic, assigned sequentially */ WITH OutputTopics(node, topicNumber) AS ( SELECT outputNode, ROW_NUMBER() (ORDER BY outputNode) AS topicNumber FROM (SELECT DISTINCT outputNode FROM edges) AS outputNodes ), /* pair input nodes to the topic of associated output nodes */ InputTopicNumbers(inputNode, topicNumber) AS ( SELECT edges.inputNode, ot.topicNumber FROM edges INNER JOIN OutputTopics AS ot ON ot.node=edges.outputNode ), /* Recursive CTE to concat all topics together */ InputTopics(inputNode, topics, topicNumber) AS ( /* The seed for the recursion - all input nodes */ SELECT inputNode, CAST ('' AS nvarchar(max)), 0 /* max topic handled for node */ FROM InputTopicNumbers GROUP BY inputNode UNION ALL /* Add topics that are greater than those processed */ /* recursively concat topic numbers in ascending order */ SELECT i.inputNode, CONCAT(c.topics, ' --input-topic=T',i.topicNumber), i.topicNumber FROM InputTopics AS c INNER JOIN InputTopicNumbers i ON i.inputNode=c.inputNode WHERE i.topicNumber &gt; c.topicNumber ), /* Bring it all together - append each node with '.exe', list the output topic, if present Use the recursive CTE to concat all inputTopics */ NodeCommands(node, exe, input, output) AS ( SELECT nodes.node, CONCAT(nodes.node,'.exe'), CONCAT(' --output_topic=T',ot.topicNumber), /* NULL if no output node */ it.topics FROM nodes LEFT OUTER JOIN OutputTopics AS ot ON ot.node=nodes.node LEFT OUTER JOIN InputTopics AS it ON it.inputNode=nodes.node ) /* finally our top-level query concatenates the parts to arrive at a single command line */ SELECT CONCAT( exe, ISNULL(input, ''), ISNULL(output, '')) FROM NodeCommands ORDER BY node </code></pre> <p>I'm doing this off the bat, so surely a few syntax errors in there. I hope the comments explain the intent.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload