Skip to content

Commit 05d7b81

Browse files
committed
fix: resolved collate from schema, avoid record cached value that may be outdated
1 parent 5123a11 commit 05d7b81

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

Diff for: core/src/main/java/com/orientechnologies/orient/core/sql/parser/OSuffixIdentifier.java

+20-7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
import com.orientechnologies.orient.core.command.OCommandContext;
88
import com.orientechnologies.orient.core.db.record.OIdentifiable;
99
import com.orientechnologies.orient.core.exception.OCommandExecutionException;
10+
import com.orientechnologies.orient.core.metadata.OMetadataInternal;
11+
import com.orientechnologies.orient.core.metadata.schema.OClass;
12+
import com.orientechnologies.orient.core.metadata.schema.OImmutableSchema;
13+
import com.orientechnologies.orient.core.metadata.schema.OProperty;
1014
import com.orientechnologies.orient.core.record.OElement;
1115
import com.orientechnologies.orient.core.record.ORecord;
1216
import com.orientechnologies.orient.core.record.impl.ODocument;
@@ -411,13 +415,22 @@ public boolean isDefinedFor(OElement currentRecord) {
411415

412416
public OCollate getCollate(OResult currentRecord, OCommandContext ctx) {
413417
if (identifier != null && currentRecord != null) {
414-
return currentRecord
415-
.getRecord()
416-
.map(x -> (OElement) x)
417-
.flatMap(elem -> elem.getSchemaType())
418-
.map(clazz -> clazz.getProperty(identifier.getStringValue()))
419-
.map(prop -> prop.getCollate())
420-
.orElse(null);
418+
String clazz = currentRecord.getProperty("@class");
419+
if (clazz != null && ctx.getDatabase() != null) {
420+
OImmutableSchema schema =
421+
((OMetadataInternal) ctx.getDatabase().getMetadata()).getImmutableSchemaSnapshot();
422+
OClass cl = schema.getClass(clazz);
423+
if (cl == null) {
424+
cl = schema.getView(clazz);
425+
}
426+
if (cl == null) {
427+
return null;
428+
}
429+
OProperty prop = cl.getProperty(identifier.getStringValue());
430+
if (prop != null) {
431+
return prop.getCollate();
432+
}
433+
}
421434
}
422435
return null;
423436
}

0 commit comments

Comments
 (0)