1
1
package datalog .execution
2
2
3
- import datalog .dsl .{Atom , Constant , Variable , GroupingAtom , AggOp }
3
+ import datalog .dsl .{Atom , Constant , Variable }
4
4
import datalog .execution .ir .{IROp , ProjectJoinFilterOp , ScanOp }
5
- import datalog .storage .{DB , EDB , NS , RelationId , StorageManager , StorageAggOp }
5
+ import datalog .storage .{DB , EDB , NS , RelationId , StorageManager }
6
6
import datalog .tools .Debug .debug
7
7
8
8
import scala .collection .mutable
@@ -12,19 +12,7 @@ import scala.reflect.ClassTag
12
12
type AllIndexes = mutable.Map [String , JoinIndexes ]
13
13
14
14
enum PredicateType :
15
- case POSITIVE , NEGATED , GROUPING
16
-
17
-
18
- enum AggOpIndex :
19
- case LV (i : Int )
20
- case GV (i : Int )
21
- case C (c : Constant )
22
-
23
- case class GroupingJoinIndexes (varIndexes : Seq [Seq [Int ]],
24
- constIndexes : mutable.Map [Int , Constant ],
25
- groupingIndexes : Seq [Int ],
26
- aggOpInfos : Seq [(StorageAggOp , AggOpIndex )]
27
- )
15
+ case POSITIVE , NEGATED
28
16
29
17
/**
30
18
* Wrapper object for join keys for IDB rules
@@ -43,8 +31,7 @@ case class JoinIndexes(varIndexes: Seq[Seq[Int]],
43
31
deps : Seq [(PredicateType , RelationId )],
44
32
atoms : Seq [Atom ],
45
33
cxns : mutable.Map [String , mutable.Map [Int , Seq [String ]]],
46
- edb : Boolean = false ,
47
- groupingIndexes : Map [String , GroupingJoinIndexes ] = Map .empty
34
+ edb : Boolean = false
48
35
) {
49
36
override def toString (): String = " " // toStringWithNS(null)
50
37
@@ -70,18 +57,13 @@ case class JoinIndexes(varIndexes: Seq[Seq[Int]],
70
57
}
71
58
72
59
object JoinIndexes {
73
- def apply (rule : Seq [Atom ], precalculatedCxns : Option [mutable.Map [String , mutable.Map [Int , Seq [String ]]]],
74
- precalculatedGroupingIndexes : Option [Map [String , GroupingJoinIndexes ]]) = {
60
+ def apply (rule : Seq [Atom ], precalculatedCxns : Option [mutable.Map [String , mutable.Map [Int , Seq [String ]]]]) = {
75
61
val constants = mutable.Map [Int , Constant ]() // position => constant
76
62
val variables = mutable.Map [Variable , Int ]() // v.oid => position
77
63
78
64
val body = rule.drop(1 )
79
65
80
- val deps = body.map(a => (
81
- a match
82
- case _ : GroupingAtom => PredicateType .GROUPING
83
- case _ => if (a.negated) PredicateType .NEGATED else PredicateType .POSITIVE
84
- , a.rId))
66
+ val deps = body.map(a => (if (a.negated) PredicateType .NEGATED else PredicateType .POSITIVE , a.rId))
85
67
86
68
val typeHelper = body.flatMap(a => a.terms.map(* => ! a.negated))
87
69
@@ -137,36 +119,7 @@ object JoinIndexes {
137
119
)).to(mutable.Map )
138
120
)
139
121
140
- // groupings
141
- val groupingIndexes = precalculatedGroupingIndexes.getOrElse(
142
- body.collect{ case ga : GroupingAtom => ga }.map(ga =>
143
- val (varsp, ctans) = ga.gp.terms.zipWithIndex.partitionMap{
144
- case (v : Variable , i) => Left ((v, i))
145
- case (c : Constant , i) => Right ((c, i))
146
- }
147
- val vars = varsp.filterNot(_._1.anon)
148
- val gis = ga.gv.map(v => vars.find(_._1 == v).get).map(_._2)
149
- ga.hash -> GroupingJoinIndexes (
150
- vars.groupBy(_._1).values.filter(_.size > 1 ).map(_.map(_._2)).toSeq,
151
- ctans.map(_.swap).to(mutable.Map ),
152
- gis,
153
- ga.ags.map(_._1).map(ao =>
154
- val aoi = ao.t match
155
- case v : Variable =>
156
- val i = ga.gv.indexOf(v)
157
- if i >= 0 then AggOpIndex .GV (gis(i)) else AggOpIndex .LV (vars.find(_._1 == v).get._2)
158
- case c : Constant => AggOpIndex .C (c)
159
- ao match
160
- case AggOp .SUM (t) => (StorageAggOp .SUM , aoi)
161
- case AggOp .COUNT (t) => (StorageAggOp .COUNT , aoi)
162
- case AggOp .MIN (t) => (StorageAggOp .MIN , aoi)
163
- case AggOp .MAX (t) => (StorageAggOp .MAX , aoi)
164
- )
165
- )
166
- ).toMap
167
- )
168
-
169
- new JoinIndexes (bodyVars, constants.to(mutable.Map ), projects, deps, rule, cxns, edb = false , groupingIndexes = groupingIndexes)
122
+ new JoinIndexes (bodyVars, constants.to(mutable.Map ), projects, deps, rule, cxns)
170
123
}
171
124
172
125
// used to approximate poor user-defined order
@@ -261,7 +214,7 @@ object JoinIndexes {
261
214
presortSelect(sortBy, originalK, sm, - 1 )
262
215
val newK = sm.allRulesAllIndexes(rId).getOrElseUpdate(
263
216
newHash,
264
- JoinIndexes (originalK.atoms.head +: newBody.map(_._1), Some (originalK.cxns), Some (originalK.groupingIndexes) )
217
+ JoinIndexes (originalK.atoms.head +: newBody.map(_._1), Some (originalK.cxns))
265
218
)
266
219
(input.map(c => ProjectJoinFilterOp (rId, newK, newBody.map((_, oldP) => c.childrenSO(oldP)): _* )), newK)
267
220
}
@@ -282,15 +235,15 @@ object JoinIndexes {
282
235
presortSelect(sortBy, originalK, sm, deltaIdx)
283
236
val newK = sm.allRulesAllIndexes(rId).getOrElseUpdate(
284
237
newHash,
285
- JoinIndexes (originalK.atoms.head +: newBody.map(_._1), Some (originalK.cxns), Some (originalK.groupingIndexes) )
238
+ JoinIndexes (originalK.atoms.head +: newBody.map(_._1), Some (originalK.cxns))
286
239
)
287
240
(newK.atoms.drop(1 ).map(a => input(originalK.atoms.drop(1 ).indexOf(a))), newK)
288
241
}
289
242
290
243
def allOrders (rule : Seq [Atom ]): AllIndexes = {
291
- val idx = JoinIndexes (rule, None , None )
244
+ val idx = JoinIndexes (rule, None )
292
245
mutable.Map [String , JoinIndexes ](rule.drop(1 ).permutations.map(r =>
293
- val toRet = JoinIndexes (rule.head +: r, Some (idx.cxns), Some (idx.groupingIndexes) )
246
+ val toRet = JoinIndexes (rule.head +: r, Some (idx.cxns))
294
247
toRet.hash -> toRet
295
248
).toSeq:_* )
296
249
}
0 commit comments