栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何编写一个选择查询或服务器端函数,该函数将从许多数据点生成整洁的时间流图?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何编写一个选择查询或服务器端函数,该函数将从许多数据点生成整洁的时间流图?

天啊。

经过一个多星期的努力,我认为我终于可以发挥作用了。这并不是针对性能进行优化(哦,循环!),但是在我可以提高性能的同时暂时完成了工作。产生的OrientDB服务器端函数(用javascript编写):

功能:

// Clear previous runsdb.command("truncate class tmp_Then");db.command("truncate class tmp_Events");// Get all distinct eventsvar distinctEvents = db.query("select from Events group by event");// Send 404 if null, otherwise proceedif (distinctEvents == null) {  response.send(404, "Events not found", "text/plain", "Error: events not found" );} else {  var edges = [];  // Loop through all distinct events  distinctEvents.forEach(function(distinctEvent) {    var newEvent = [];    var rid = distinctEvent.field("@rid");    var eventType = distinctEvent.field("event");    // The main query that finds all *direct* descendents of the distinct event    var result = db.query("select from (traverse * from (select from Events where event = ?) where $depth <= 2) where @class = 'Events' and $depth > 1 and @rid in (select from Events group by event)", [eventType]);    // Save the distinct event in a temp table to create temp edges    db.command("create vertex tmp_Events set rid = ?, event = ?", [rid, event]);      edges.push(result);    });  // The edges array defines which edges should exist for a given event  edges.forEach(function(edge, index) {    edge.forEach(function(e) {      // Create the temp edge that corresponds to its distinct event      db.command("create edge tmp_Then from (select from tmp_Events where rid = " + distinctEvents[index].field("@rid") + ") to (select from tmp_Events where rid = " + e.field("@rid") + ")");    });  });  var result = db.query("select from tmp_Events");  return result;}

外卖:

  • 临时表似乎是必要的。 我尝试在没有临时表(类)的情况下执行此操作,但是我不确定是否可以执行此操作。我需要模拟原始数据中不存在的边缘。
  • Traverse在编写主查询时非常有帮助。 遍历一个事件以找到其直接,唯一的后代非常简单。
  • 能够用Javascript编写存储的proc的能力真是太棒了。 这在SQL中将是一场噩梦。
  • omfg循环。 我计划对此进行优化,并继续使其更好,以便希望其他人可以从中找到一些用处。


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/670097.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号