###################################################################### ## File: OBA-CR-Queries ###################################### ###################################################################### ## This file is part of SECONDO. ## ## Copyright (C) 2007, University in Hagen, Faculty of Mathematics and ## Computer Science, Database Systems for New Applications. ## ## SECONDO is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2 of the License, or ## (at your option) any later version. ## ## SECONDO is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with SECONDO; if not, write to the Free Software ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ###################################################################### ## This file performs the OBA-Queries of the BerlinMOD benchmark ## in the Compact Representation on the Secondo DBMS. open database berlinmod; query now(); ################################################################################ # # # Query 1: What are the models of the vehicles with license plate numbers from # # QueryLicence? # # # ################################################################################ let OBACRres001 = QueryLicences feed {O} loopjoin[ dataSCcar_Licence_btree dataSCcar exactmatch[.Licence_O]] project[Licence, Model] consume; query now(); ################################################################################ # # # Query 2: How many vehicles exist that are passenger cars? # # # ################################################################################ let OBACRres002 = dataSCcar feed filter [.Type = "passenger"] count; query now(); ################################################################################ # # # Query 3: Where have the vehicles with licenses from QueryLicence1 been at # # each instant from QueryInstant1? # # # ################################################################################ let OBACRres003 = QueryLicences feed {LL} head[10] loopjoin[dataSCcar_Licence_btree dataSCcar exactmatch[.Licence_LL]] QueryInstants feed {II} head[10] product projectextend[; Licence: .Licence_LL, Instant: .Instant_II, Pos: val(.Journey atinstant .Instant_II)] consume; query now(); ################################################################################ # # # Query 4: Which license plate numbers belong to vehicles that have passed the # # points from QueryPoints? # # # ################################################################################ let OBACRres004 = QueryPoints feed loopjoin[ dataSCcar_Journey_sptuni windowintersectsS[bbox(.Pos)] sort rdup dataSCcar gettuples] filter[.Journey passes .Pos] project[Id, Licence] sortby[Id asc, Licence asc] krdup[Id, Licence] consume; query now(); ################################################################################ # # # Query 5: What is the minimum distance between places, where a vehicle with a # # license from QueryLicences1 and a vehicle with licenses from # # from QueryLicence2 have been? # # # ################################################################################ let OBACRres005tmp1 = QueryLicences feed head[10] loopsel[ dataSCcar_Licence_btree dataSCcar exactmatch[.Licence] ] projectextend[Licence; Traj: simplify(trajectory(.Journey),0.000001)] consume; query now(); let OBACRres005tmp2 = QueryLicences feed head[20] filter[.Id>10] loopsel[ dataSCcar_Licence_btree dataSCcar exactmatch[.Licence] ] projectextend[Licence; Traj: simplify(trajectory(.Journey),0.000001)] consume; query now(); let OBACRres005 = OBACRres005tmp1 feed {V1} OBACRres005tmp2 feed {V2} product projectextend[ ; Licence1: .Licence_V1, Licence2: .Licence_V2, Dist: round(distance(.Traj_V1, .Traj_V2),3)] sort rdup consume; query now(); delete OBACRres005tmp1; delete OBACRres005tmp2; query now(); ################################################################################ # # # Query 6: What are the pairs of license plate numbers of "trucks", that have # # been as close as 10m or less to each other? # # # ################################################################################ let OBACRres006 = dataSCcar feed {V1} filter[.Type_V1 = "truck"] dataSCcar feed {V2} filter[.Type_V2 = "truck"] symmjoin[.Licence_V1 < ..Licence_V2] filter[ minimum(distance(.Journey_V1, .Journey_V2)) <= 10.0 ] projectextend[ ; Licence1: .Licence_V1, Licence2: .Licence_V2 ] sortby[Licence1, Licence2] consume; query now(); ################################################################################ # # # Query 7: What are the license plate numbers of the "passenger" cars that # # have reached points from QueryPoints first of all "passenger" cars # # during the complete observation period? # # # ################################################################################ let OBACRres007tmp1 = QueryPoints feed loopjoin[ dataSCcar_Journey_sptuni windowintersectsS[bbox(.Pos)] sort rdup dataSCcar gettuples ] filter[.Type = "passenger"] projectextend[Id, Pos ; Instant: inst(initial(.Journey at .Pos)) ] filter[not(isempty(.Instant))] sortby[Id asc, Instant asc] groupby[Id, Pos; FirstTime: group feed min[Instant] ] consume; query now(); let OBACRres007 = OBACRres007tmp1 feed extend[MBR: box3d(bbox(.Pos),.FirstTime) ] loopjoin[ dataSCcar_Journey_sptmpuni windowintersectsS[.MBR] sort rdup dataSCcar gettuples ] filter[.Type = "passenger"] filter[.Journey passes .Pos] projectextend[Licence, FirstTime, Id ; Instant: inst(initial(.Journey at .Pos))] filter[.Instant <= .FirstTime] project[ Id, Licence ] sortby [Id asc, Licence asc] consume; query now(); delete OBACRres007tmp1; query now(); ################################################################################ # # # Query 8: What are the overall traveled distances of the vehicles with # # license plate numbers from QueryLicences1 during the periods from # # QueryPeriods1? # # # ################################################################################ let OBACRres008 = QueryLicences feed {LL} head[10] loopsel[ dataSCcar_Licence_btree dataSCcar exactmatch[.Licence_LL] ] QueryPeriods feed head[10] {PP} product projectextend[Licence; Period: .Period_PP, Dist: round(length(.Journey atperiods .Period_PP),3)] project[Licence, Period, Dist] sortby [Licence asc, Period asc] consume; query now(); ################################################################################ # # # Query 9: What is the longest distance that was traveled by a vehicle during # # each of the periods from QueryPeriods? # # # ################################################################################ let OBACRres009 = dataSCcar feed project[Journey] {V1} QueryPeriods feed {PP} product projectextend[Id_PP ; Period: .Period_PP, D: round(length(.Journey_V1 atperiods .Period_PP),3)] sortby[Id_PP, Period, D desc] groupby[ Id_PP, Period; Dist: group feed max[D]] project[Period, Dist] consume; query now(); ################################################################################ # # # Query 10: When and where did the vehicles with license plate numbers from # # QueryLicences1 meet other vehicles (distance < 3m) and what are # # the latter licenses? # # # ################################################################################ let OBACRres010 = QueryLicences feed head[10] loopsel[ dataSCcar_Licence_btree dataSCcar exactmatch[.Licence] project[Licence, Journey] {V1} ] dataSCcar feed project[Licence, Journey] {V2} symmjoin[(.Licence_V1 # ..Licence_V2) ] filter[ (everNearerThan(.Journey_V1, .Journey_V2, 3.0)) ] projectextend[; QueryLicence: .Licence_V1, OtherLicence: .Licence_V2, Pos: .Journey_V1 atperiods deftime((distance(.Journey_V1, .Journey_V2) < 3.0) at TRUE) ] filter[not(isempty(deftime(.Pos)))] project[QueryLicence, OtherLicence, Pos] sortby[QueryLicence, OtherLicence] consume; query now(); ################################################################################ # # # Query 11: Which vehicles passed a point from QueryPoints1 at one of the # # instants from QueryInstant1? # # # ################################################################################ let OBACRres011 = QueryPoints feed head[10] project[Id, Pos] {PP} QueryInstants feed head[10] project[Instant] {II} product loopjoin[ dataSCcar_Journey_sptmpuni windowintersectsS[box3d(bbox(.Pos_PP), .Instant_II)] sort rdup ] dataSCcar gettuples projectextend[Licence, Id_PP,Pos_PP, Instant_II; XPos: val(.Journey atinstant .Instant_II) ] filter[not(isempty(.XPos))] filter[distance(.XPos,.Pos_PP) < 0.5] projectextend[Licence; Id: .Id_PP, Instant: .Instant_II] sortby [Id, Licence, Instant] rdup consume; query now(); ################################################################################ # # # Query 12: Which vehicles met at a point from QueryPoints1 at an instant from # # QueryInstant1? # # # ################################################################################ let OBACRres012tmp1 = QueryInstants feed head[10] extend[Period: theRange(.Instant, .Instant, TRUE, TRUE)] aggregateB[Period; fun(I1: periods, I2:periods) I1 union I2; [const periods value ()] ]; query now(); let OBACRres012 = QueryPoints feed head[10] project[Id, Pos] loopjoin[ dataSCcar_Journey_sptuni windowintersectsS[bbox(.Pos)] sort rdup dataSCcar gettuples projectextend[Licence; Journey: .Journey atperiods OBACRres012tmp1] ] filter[.Journey passes .Pos] projectextend[Licence, Id, Pos; Journey: .Journey at .Pos] {V1} QueryPoints feed head[10] project[Pos] loopjoin[ dataSCcar_Journey_sptuni windowintersectsS[bbox(.Pos)] sort rdup dataSCcar gettuples projectextend[Licence; Journey: .Journey atperiods OBACRres012tmp1] ] filter[.Journey passes .Pos] projectextend[Licence, Pos; Journey: .Journey at .Pos] {V2} symmjoin[.Licence_V1 < ..Licence_V2] QueryInstants feed head[10] symmjoin[val(.Journey_V1 atinstant ..Instant) = val(.Journey_V2 atinstant ..Instant)] projectextend[ Id_V1, Instant; Licence1: .Licence_V1, Licence2: .Licence_V2] sortby[Id_V1, Instant, Licence2] rdup consume; query now(); delete OBACRres012tmp1; query now(); ################################################################################ # # # Query 13: Which vehicles traveled within one of the regions from # # QueryRegions1 during the periods from QueryPeriods1? # # # ################################################################################ let OBACRres013 = QueryRegions feed head[10] filter[not(isempty(.Region))]{RR} QueryPeriods feed head[10] filter[not(isempty(.Period))]{PP} product loopsel [ fun(t:TUPLE) dataSCcar_Journey_sptmpuni windowintersectsS[box3d( bbox(attr(t,Region_RR)),attr(t,Period_PP))] sort rdup dataSCcar gettuples filter[(.Journey atperiods attr(t,Period_PP)) passes attr(t,Region_RR) ] projectextend[Licence; Region: attr(t,Region_RR), Period: attr(t,Period_PP), Id_RR: attr(t,Id_RR), Id_PP: attr(t,Id_PP)] ] sortby[Id_RR, Period, Licence] krdup[Id_RR, Period, Licence] project[Id_RR, Period, Licence] sortby[Id_RR, Period, Licence] consume; query now(); ################################################################################ # # # Query 14: Which vehicles traveled within one of the regions from # # QueryRegions1 at one of the instants from QueryInstant1? # # # ################################################################################ let OBACRres014 = QueryRegions feed head[10] {RR} QueryInstants feed head[10] {II} product loopsel [ fun(t:TUPLE) dataSCcar_Journey_sptmpuni windowintersectsS[box3d( bbox(attr(t,Region_RR)),attr(t,Instant_II))] sort rdup dataSCcar gettuples filter[val(.Journey atinstant attr(t,Instant_II)) inside attr(t,Region_RR) ] projectextend[Licence; Region: attr(t,Region_RR), Instant: attr(t,Instant_II), Id_RR: attr(t,Id_RR), Id_II: attr(t,Id_II)] ] sortby[Id_RR, Instant, Licence] krdup[Id_RR, Instant, Licence] project[Id_RR, Instant, Licence] consume; query now(); ################################################################################ # # # Query 15: Which vehicles passed a point from QueryPoints1 during a period # # from QueryPeriods1? # # # ################################################################################ let OBACRres015 = QueryPoints feed head[10] {PO} QueryPeriods feed head[10] {PR} product loopsel [ fun(t:TUPLE) dataSCcar_Journey_sptmpuni windowintersectsS[ box3d(bbox(attr(t,Pos_PO)),attr(t,Period_PR)) ] sort rdup dataSCcar gettuples filter[(.Journey atperiods attr(t,Period_PR)) passes attr(t,Pos_PO) ] projectextend[Licence; Point: attr(t,Pos_PO), Period: attr(t,Period_PR), Id_PO: attr(t,Id_PO), Id_PR: attr(t,Id_PR)] ] sortby[Id_PO, Period, Licence] krdup[Id_PO, Period, Licence] project[Id_PO, Period, Licence] consume; query now(); ################################################################################ # # # Query 16: List the pairs of licenses for vehicles the first from # # QueryLicences1, the second from QueryLicences2, where the # # corresponding vehicles are both present within a region from # # QueryRegions1 during a period from QueryPeriod1, but do not meet # # each other there and then. # # # ################################################################################ let OBACRres016tmp1 = QueryLicences feed head[10] loopsel[ fun(t:TUPLE) dataSCcar_Licence_btree dataSCcar exactmatch[attr(t,Licence)]] QueryPeriods feed head[10] {PP} QueryRegions feed head[10] {RR} product product projectextend[Licence, Region_RR, Period_PP, Id_RR, Id_PP ; Journey: (.Journey atperiods .Period_PP) at .Region_RR] filter[no_components(.Journey) > 0] consume; query now(); let OBACRres016tmp2 = QueryLicences feed head[20] filter[.Id > 10] loopsel[ fun(t:TUPLE) dataSCcar_Licence_btree dataSCcar exactmatch[attr(t,Licence)]] QueryPeriods feed head[10] {PP} QueryRegions feed head[10] {RR} product product projectextend[Licence, Region_RR, Period_PP, Id_RR, Id_PP ; Journey: (.Journey atperiods .Period_PP) at .Region_RR] filter[no_components(.Journey) > 0] consume; query now(); let OBACRres016 = OBACRres016tmp1 feed {C1} OBACRres016tmp2 feed {C2} symmjoin[ (.Licence_C1 # ..Licence_C2) and (.Id_RR_C1 = ..Id_RR_C2) and (.Id_PP_C1 = ..Id_PP_C2) ] filter[ not(everNearerThan(.Journey_C1, .Journey_C2, 0.1)) ] projectextend[; Licence1: .Licence_C1, Licence2: .Licence_C2, Region: .Region_RR_C1, Period: .Period_PP_C1, Id_RR: .Id_RR_C1] sortby[Id_RR, Period, Licence1, Licence2] project[Id_RR, Period, Licence1, Licence2] consume; query now(); delete OBACRres016tmp1; delete OBACRres016tmp2; query now(); ################################################################################ # # # Query 17: Which points from QueryPoints have been visited by a maximum # # number of different vehicles? # # # ################################################################################ let OBACRres017tmp1 = QueryPoints feed project[Id, Pos] {PP} loopjoin[ fun(t:TUPLE) dataSCcar_Journey_sptuni windowintersectsS[bbox(attr(t,Pos_PP))] sort rdup dataSCcar gettuples filter[.Journey passes attr(t,Pos_PP)] project[Licence] ] projectextend[Licence; Id: .Id_PP, Pos: .Pos_PP] sortby[Id asc, Pos asc, Licence asc] groupby[Id, Pos; Hits: group feed rdup count] consume; query now(); let OBACRres017 = OBACRres017tmp1 feed filter[.Hits = (OBACRres017tmp1 feed max[Hits])] project[Id, Hits] consume; query now(); delete OBACRres017tmp1; query now(); ################################################################################ # # # Store Query times # # # ################################################################################ let QRT_BMOD_OBA = SEC2COMMANDS feed consume; #save EVAL_SEC2COMMANDS_BERLINMODOBA to 'BerlinMODNNNOBARunTimesRunX.DAT'; close database;