Skip to content

Commit 5e0b9f5

Browse files
committed
feat: readd the ability to traverse embedded links with the star argument
1 parent 989ea97 commit 5e0b9f5

File tree

1 file changed

+40
-5
lines changed

1 file changed

+40
-5
lines changed

core/src/main/java/com/orientechnologies/orient/core/sql/parser/OTraverseProjectionItem.java

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import com.orientechnologies.orient.core.command.OCommandContext;
66
import com.orientechnologies.orient.core.db.record.OIdentifiable;
7+
import com.orientechnologies.orient.core.record.OElement;
78
import com.orientechnologies.orient.core.sql.executor.OResult;
89
import com.orientechnologies.orient.core.sql.executor.OResultSet;
910
import java.util.HashSet;
@@ -49,21 +50,25 @@ public boolean refersToParent() {
4950
return false;
5051
}
5152

52-
private Object handleStar(OResult iCurrentRecord, OCommandContext ctx) {
53+
private Set<Object> handleStar(OResult iCurrentRecord, OCommandContext ctx) {
5354
Set<Object> result = new HashSet<>();
5455
for (String prop : iCurrentRecord.getPropertyNames()) {
5556
Object val = iCurrentRecord.getProperty(prop);
56-
if (isOResult(val) || isValidIdentifiable(val)) {
57+
if (isPersistentOResult(val) || isValidIdentifiable(val)) {
5758
result.add(val);
5859

60+
} else if (val instanceof OResult) {
61+
result.addAll(handleStar((OResult) val, ctx));
62+
} else if (val instanceof OElement) {
63+
handleDocument(result, (OElement) val);
5964
} else {
6065
if (val instanceof Iterable) {
6166
val = ((Iterable) val).iterator();
6267
}
6368
if (val instanceof Iterator) {
6469
while (((Iterator) val).hasNext()) {
6570
Object sub = ((Iterator) val).next();
66-
if (isOResult(sub) || isValidIdentifiable(sub)) {
71+
if (isPersistentOResult(sub) || isValidIdentifiable(sub)) {
6772
result.add(sub);
6873
}
6974
}
@@ -77,15 +82,45 @@ private Object handleStar(OResult iCurrentRecord, OCommandContext ctx) {
7782
return result;
7883
}
7984

85+
private void handleDocument(Set<Object> result, OElement record) {
86+
for (String prop : record.getPropertyNames()) {
87+
Object val = record.getProperty(prop);
88+
if (isPersistentOResult(val) || isValidIdentifiable(val)) {
89+
result.add(val);
90+
} else if (val instanceof OElement) {
91+
handleDocument(result, (OElement) val);
92+
} else {
93+
if (val instanceof Iterable) {
94+
val = ((Iterable) val).iterator();
95+
}
96+
if (val instanceof Iterator) {
97+
while (((Iterator) val).hasNext()) {
98+
Object sub = ((Iterator) val).next();
99+
if (isPersistentOResult(sub) || isValidIdentifiable(sub)) {
100+
result.add(sub);
101+
}
102+
}
103+
} else if (val instanceof OResultSet) {
104+
while (((OResultSet) val).hasNext()) {
105+
result.add(((OResultSet) val).next());
106+
}
107+
}
108+
}
109+
}
110+
}
111+
80112
private boolean isValidIdentifiable(Object val) {
81113
if (!(val instanceof OIdentifiable)) {
82114
return false;
83115
}
84116
return ((OIdentifiable) val).getIdentity().isPersistent();
85117
}
86118

87-
private boolean isOResult(Object val) {
88-
return val instanceof OResult;
119+
private boolean isPersistentOResult(Object val) {
120+
if (val instanceof OResult) {
121+
return ((OResult) val).getIdentity().map((x) -> x.getIdentity().isPersistent()).orElse(false);
122+
}
123+
return false;
89124
}
90125

91126
public void toString(Map<Object, Object> params, StringBuilder builder) {

0 commit comments

Comments
 (0)