Skip to content

Commit

Permalink
update code
Browse files Browse the repository at this point in the history
  • Loading branch information
starocean999 committed Oct 25, 2024
1 parent 963a879 commit 3c9bd7e
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3876,7 +3876,7 @@ public SetVarOp visitSetSystemVariable(SetSystemVariableContext ctx) {
type = SetType.SESSION;
}
String name = stripQuotes(ctx.identifier().getText());
Expression expression = ctx.expression() != null ? typedVisit(ctx.expression()) : NullLiteral.INSTANCE;
Expression expression = ctx.expression() != null ? typedVisit(ctx.expression()) : null;
return new SetSessionVarOp(type, name, expression);
}

Expand All @@ -3889,7 +3889,7 @@ public SetVarOp visitSetVariableWithType(SetVariableWithTypeContext ctx) {
type = SetType.SESSION;
}
String name = stripQuotes(ctx.identifier().getText());
Expression expression = ctx.expression() != null ? typedVisit(ctx.expression()) : NullLiteral.INSTANCE;
Expression expression = ctx.expression() != null ? typedVisit(ctx.expression()) : null;
return new SetSessionVarOp(type, name, expression);
}

Expand All @@ -3899,17 +3899,15 @@ public SetVarOp visitSetPassword(SetPasswordContext ctx) {
String host;
boolean isDomain;
String passwordText;
boolean isPlain;
UserIdentity userIdentity = null;
if (ctx.userIdentify() != null) {
user = stripQuotes(ctx.userIdentify().user.getText());
host = ctx.userIdentify().host != null ? stripQuotes(ctx.userIdentify().host.getText()) : "%";
isDomain = ctx.userIdentify().LEFT_PAREN() != null;
isDomain = ctx.userIdentify().ATSIGN() != null;
userIdentity = new UserIdentity(user, host, isDomain);
}
passwordText = stripQuotes(ctx.STRING_LITERAL().getText());
isPlain = ctx.LEFT_PAREN() != null;
return new SetPassVarOp(userIdentity, new PassVar(passwordText, isPlain));
return new SetPassVarOp(userIdentity, new PassVar(passwordText, ctx.isPlain != null));
}

@Override
Expand All @@ -3933,7 +3931,7 @@ public SetVarOp visitSetCollate(SetCollateContext ctx) {
@Override
public SetVarOp visitSetLdapAdminPassword(SetLdapAdminPasswordContext ctx) {
String passwordText = stripQuotes(ctx.STRING_LITERAL().getText());
boolean isPlain = ctx.LEFT_PAREN() != null;
boolean isPlain = ctx.PASSWORD() != null;
return new SetLdapPassVarOp(new PassVar(passwordText, isPlain));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,4 @@ public String treeString() {
public Plan withGroupExpression(Optional<GroupExpression> groupExpression) {
throw new RuntimeException("Command do not implement withGroupExpression");
}

public String toSql() {
return "";
}

public boolean needAuditEncryption() {
return false;
}

public void afterForwardToMaster(ConnectContext ctx) throws Exception {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@
package org.apache.doris.nereids.trees.plans.commands;

import org.apache.doris.analysis.RedirectStatus;
import org.apache.doris.qe.ConnectContext;

/**
* forward to master.
*/
public interface Forward {
RedirectStatus toRedirectStatus();

default void afterForwardToMaster(ConnectContext ctx) throws Exception {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,23 @@ public class SetSessionVarOp extends SetVarOp {
private String name;
private final Expression expression;
private Literal value;
private final boolean isDefault;

/** constructor*/
public SetSessionVarOp(SetType type, String name, Expression expression) {
super(type);
this.name = name;
this.expression = expression;
this.isDefault = expression == null;
}

@Override
public void validate(ConnectContext ctx) throws UserException {
value = ExpressionUtils.analyzeAndFoldToLiteral(ctx, expression);
if (value.isNullLiteral()) {
if (isDefault) {
value = new StringLiteral("default");
return;
}
value = ExpressionUtils.analyzeAndFoldToLiteral(ctx, expression);

if (getType() == SetType.GLOBAL) {
if (!Env.getCurrentEnv().getAccessManager().checkGlobalPriv(ConnectContext.get(), PrivPredicate.ADMIN)) {
Expand Down Expand Up @@ -134,11 +137,15 @@ public void afterForwardToMaster(ConnectContext ctx) throws Exception {

// TODO delete this method after removing dependence of SetVar in VariableMgr
private SetVar translateToLegacyVar(ConnectContext ctx) {
LogicalEmptyRelation plan = new LogicalEmptyRelation(
ConnectContext.get().getStatementContext().getNextRelationId(), new ArrayList<>());
CascadesContext cascadesContext = CascadesContext.initContext(ctx.getStatementContext(), plan,
PhysicalProperties.ANY);
Expr expr = ExpressionTranslator.translate(value, new PlanTranslatorContext(cascadesContext));
return new SetVar(getType(), name, expr.isNullLiteral() ? null : expr);
if (isDefault) {
return new SetVar(getType(), name, null);
} else {
LogicalEmptyRelation plan = new LogicalEmptyRelation(
ConnectContext.get().getStatementContext().getNextRelationId(), new ArrayList<>());
CascadesContext cascadesContext = CascadesContext.initContext(ctx.getStatementContext(), plan,
PhysicalProperties.ANY);
Expr expr = ExpressionTranslator.translate(value, new PlanTranslatorContext(cascadesContext));
return new SetVar(getType(), name, expr);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1202,9 +1202,9 @@ private void forwardToMaster() throws Exception {
masterOpExecutor.execute();
if (parsedStmt instanceof LogicalPlanAdapter) {
// for nereids command
if (((LogicalPlanAdapter) parsedStmt).getLogicalPlan() instanceof Command) {
Command command = (Command) ((LogicalPlanAdapter) parsedStmt).getLogicalPlan();
command.afterForwardToMaster(context);
if (((LogicalPlanAdapter) parsedStmt).getLogicalPlan() instanceof Forward) {
Forward forward = (Forward) ((LogicalPlanAdapter) parsedStmt).getLogicalPlan();
forward.afterForwardToMaster(context);
}
} else if (parsedStmt instanceof SetStmt) {
SetStmt setStmt = (SetStmt) parsedStmt;
Expand Down

0 comments on commit 3c9bd7e

Please sign in to comment.