Skip to content

Commit

Permalink
fix: correct set of target class when query target a cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
tglman committed Jan 22, 2024
1 parent a48163f commit 05312f6
Showing 1 changed file with 31 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.orientechnologies.orient.core.sql.executor;

import com.orientechnologies.orient.core.command.OCommandContext;
import com.orientechnologies.orient.core.db.ODatabaseSession;
import com.orientechnologies.orient.core.index.OIndexAbstract;
import com.orientechnologies.orient.core.metadata.schema.OClass;
import com.orientechnologies.orient.core.metadata.schema.OSchema;
import com.orientechnologies.orient.core.sql.parser.OCluster;
import com.orientechnologies.orient.core.sql.parser.OIdentifier;
import com.orientechnologies.orient.core.sql.parser.OIndexIdentifier;
Expand Down Expand Up @@ -57,12 +60,13 @@ public OInsertExecutionPlan createExecutionPlan(OCommandContext ctx, boolean ena
} else {
handleCreateRecord(result, this.insertBody, ctx, enableProfiling);
}
handleTargetClass(result, targetClass, ctx, enableProfiling);
handleTargetClass(result, ctx, enableProfiling);
handleSetFields(result, insertBody, ctx, enableProfiling);
ODatabaseSession database = ctx.getDatabase();
if (targetCluster != null) {
String name = targetCluster.getClusterName();
if (name == null) {
name = ctx.getDatabase().getClusterNameById(targetCluster.getClusterNumber());
name = database.getClusterNameById(targetCluster.getClusterNumber());
}
handleSave(result, new OIdentifier(name), ctx, enableProfiling);
} else {
Expand Down Expand Up @@ -128,12 +132,32 @@ private void handleSetFields(
}

private void handleTargetClass(
OInsertExecutionPlan result,
OIdentifier targetClass,
OCommandContext ctx,
boolean profilingEnabled) {
OInsertExecutionPlan result, OCommandContext ctx, boolean profilingEnabled) {
ODatabaseSession database = ctx.getDatabase();
OSchema schema = database.getMetadata().getSchema();
OIdentifier tc = null;
if (targetClass != null) {
result.chain(new SetDocumentClassStep(targetClass, ctx, profilingEnabled));
tc = targetClass;
} else if (targetCluster != null) {
String name = targetCluster.getClusterName();
if (name == null) {
name = database.getClusterNameById(targetCluster.getClusterNumber());
}
OClass targetClass = schema.getClassByClusterId(database.getClusterIdByName(name));
if (targetClass != null) {
tc = new OIdentifier(targetClass.getName());
}
} else if (this.targetClass == null) {

OClass targetClass =
schema.getClassByClusterId(
database.getClusterIdByName(targetClusterName.getStringValue()));
if (targetClass != null) {
tc = new OIdentifier(targetClass.getName());
}
}
if (tc != null) {
result.chain(new SetDocumentClassStep(tc, ctx, profilingEnabled));
}
}

Expand Down

0 comments on commit 05312f6

Please sign in to comment.