如何对 SQL 数据进行无向图处理
我在为 ActiveMQ 系统动态创建主题时遇到了以下问题:
我有许多进程 (M_1
, ..., M_n
),其中 n
不大,一般是5-10个。一些进程将通过消息队列监听其他进程的输出;这些边在 XML 文件中指定,例如
<link from="M1" to="M3"</link>
<link from="M2" to="M4"</link>
<link from="M3" to="M4"</link>
等。边是稀疏的,因此不会有很多边。我将解析此 XML 并将此信息存储在 SQL DB 中,一个表用于节点,另一个表用于边。
现在,我需要动态创建
M1.exe --output_topic=T1
M2.exe --output_topic=T2
M3.exe --input_topic=T1 --output_topic=T3
M4.exe --input_topic=T2 --input_topic=T3
顺序生成标签的形式的字符串。查询 SQL 以获得这些关系的最佳方法是什么?您可以向我指出任何工具或其他教程吗?我从来没有用 SQL 做过图表。
使用 SQL 是势在必行的,因为我们也将它用于其他用途。
谢谢!
I ran into the following problem in dynamically creating topics for our ActiveMQ system:
I have a number of processes (M_1
, ..., M_n
), where n
is not large, typically 5-10. Some of the processes will listen to the output of others, through a message queue; these edges are specified in an XML file, e.g.
<link from="M1" to="M3"</link>
<link from="M2" to="M4"</link>
<link from="M3" to="M4"</link>
etc. The edges are sparse, so there won't be many of them. I will parse this XML and store this information in an SQL DB, one table for nodes and another for edges.
Now, I need to dynamically create strings of the form
M1.exe --output_topic=T1
M2.exe --output_topic=T2
M3.exe --input_topic=T1 --output_topic=T3
M4.exe --input_topic=T2 --input_topic=T3
where the tags are sequentially generated. What is the best way to go about querying SQL to obtain these relationships? Are there any tools or other tutorials you can point me to? I've never done graps with SQL.
Using SQL is imperative, because we use it for other stuff, too.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,这是我对这个问题的尝试。
这是节点和边表的草图:
假设您的数据库支持 CTE,那么像这样构造的查询将汇集关系并连接结果:
我正在立即执行此操作,因此肯定存在一些语法错误。我希望评论能够解释其意图。
Ok, here's my stab at the problem.
Here's a sketch of the nodes and edges tables:
Assuming your db has support for CTEs, then a query structured like this will bring together the relationships and concatenate results:
I'm doing this off the bat, so surely a few syntax errors in there. I hope the comments explain the intent.