in query/src/main/kotlin/jetbrains/exodus/query/QueryEngine.kt [104:143]
open fun union(left: Iterable<Entity>, right: Iterable<Entity>): Iterable<Entity> {
if (left === right) {
return left
}
if (left.isEmpty) {
return right
}
if (right.isEmpty) {
return left
}
if (left is TreeKeepingEntityIterable) {
val leftType = left.getEntityType()
if (right is TreeKeepingEntityIterable) {
if (left.instance === right.instance && leftType == right.getEntityType()) {
return TreeKeepingEntityIterable(
right.instance, leftType,
or(left.tree, right.tree), left.annotatedTree, right.annotatedTree, this
)
}
}
}
var staticType: String? = null
if (left is StaticTypedEntityIterable) {
val leftType = left.getEntityType()
if (right is StaticTypedEntityIterable) {
val rightType = right.getEntityType()
if (leftType == rightType) {
staticType = rightType
if (left.isGetAllTree) {
return AddNullStaticTypedEntityIterable(staticType, left, right, this)
}
if (right.isGetAllTree) {
return AddNullStaticTypedEntityIterable(staticType, right, left, this)
}
}
}
}
val result = unionNonTrees(instantiateAndAdjust(left), instantiateAndAdjust(right))
return staticType?.let { StaticTypedIterableDecorator(staticType, result, this) } ?: result
}