Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F995446
query-and.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
query-and.ts
View Options
import
{
Query
}
from
"./query-base.js"
;
import
QueryStep
,
{
Match
}
from
"./query-step.js"
;
import
Graph
from
"./graph.js"
;
import
{
QueryTypes
}
from
"../main.js"
;
import
type
QueryStage
from
"./query-stage.js"
;
export
default
class
And
extends
Query
{
graph
:
Graph
;
aggregation_steps
:
{
[
id
:
string
]
:
QueryStep
};
received_deny_all
:
boolean
;
constructor
(...
queries
:
Query
[])
{
super
();
this
.
_reset
();
for
(
let
query
of
queries
)
{
this
.
addQuery
(
query
);
}
}
_reset
()
{
this
.
graph
=
new
Graph
();
this
.
aggregation_steps
=
{};
this
.
received_deny_all
=
false
;
}
addQuery
(
query
:
Query
)
{
if
(
this
.
received_deny_all
)
{
return
;
}
if
(
query
instanceof
QueryTypes
.
DenyAll
)
{
this
.
_reset
();
this
.
received_deny_all
=
true
;
}
const
steps
=
query
.
dump
();
for
(
let
step
of
steps
)
{
const
id
=
step
.
hash
();
if
(
this
.
_isInGraph
(
id
))
{
continue
;
}
this
.
_addToAggregationSteps
(
id
,
step
);
this
.
_addDependenciesInGraph
(
id
,
step
);
}
}
_isInGraph
(
key
:
string
)
{
return
key
.
length
===
32
&&
this
.
graph
.
node_ids
.
includes
(
key
);
}
_addToAggregationSteps
(
id
:
string
,
step
:
QueryStep
)
{
this
.
graph
.
addNode
(
id
,
step
.
getCost
());
this
.
aggregation_steps
[
id
]
=
step
;
}
_addDependenciesInGraph
(
id
:
string
,
step
:
QueryStep
)
{
let
dependencies
=
step
.
getUsedFields
()
.
filter
((
field
)
=>
this
.
_isInGraph
(
field
));
if
(
step
instanceof
Match
)
{
dependencies
=
dependencies
.
filter
((
d1
)
=>
this
.
_isNotDependencyForAnyInGroup
(
d1
,
dependencies
)
);
}
for
(
let
dependency
of
dependencies
)
{
this
.
graph
.
addEdge
(
dependency
,
id
);
}
}
_isNotDependencyForAnyInGroup
(
id
:
string
,
nodeGroup
:
string
[])
{
return
!
nodeGroup
.
some
(
(
node
)
=>
id
!==
node
&&
this
.
graph
.
pathExists
(
id
,
node
)
);
}
dump
()
{
const
sortedStepIds
=
this
.
graph
.
bestFirstSearch
();
return
sortedStepIds
.
reduce
((
steps
,
id
)
=>
{
steps
.
push
(
this
.
aggregation_steps
[
id
]);
return
steps
;
},
[]
as
QueryStep
[]);
}
toPipeline
()
:
QueryStage
[]
{
const
sortedStepIds
=
this
.
graph
.
bestFirstSearch
();
const
ret
=
sortedStepIds
.
reduce
((
pipeline
:
QueryStage
[],
id
)
=>
{
return
[...
pipeline
,
...
this
.
aggregation_steps
[
id
].
toPipeline
()];
},
[]
as
QueryStage
[]);
return
ret
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Mon, Dec 23, 04:52 (18 h, 19 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
556817
Default Alt Text
query-and.ts (2 KB)
Attached To
Mode
rS Sealious
Attached
Detach File
Event Timeline
Log In to Comment