Skip to content

Commit

Permalink
[feature](nereids)support set command (apache#41913)
Browse files Browse the repository at this point in the history
## Proposed changes
**test case:**
setPassword and setUserProperties:
regression-test/suites/account_p0/test_auth_compatibility.groovy

setDefaultStorageVault:
regression-test/suites/vaults/privilege.groovy

setUserVariable:
regression-test/suites/query_p0/set/test_user_var.groovy

setLdapAdminPassword:
regression-test/suites/auth_p0/test_set_ldap_admin_password_auth.groovy

other commands:
regression-test/suites/query_p0/set/test_set_command.groovy

<!--Describe your changes.-->
  • Loading branch information
starocean999 authored Oct 30, 2024
1 parent 04232ca commit 3303c04
Show file tree
Hide file tree
Showing 25 changed files with 1,316 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ statementBase
| supportedJobStatement #supportedJobStatementAlias
| constraintStatement #constraintStatementAlias
| supportedDropStatement #supportedDropStatementAlias
| supportedSetStatement #supportedSetStatementAlias
| unsupportedStatement #unsupported
;

unsupportedStatement
: unsupportedSetStatement
| unsupoortedUnsetStatement
: unsupoortedUnsetStatement
| unsupportedUseStatement
| unsupportedDmlStatement
| unsupportedKillStatement
Expand Down Expand Up @@ -798,7 +798,7 @@ functionArgument
| dataType
;

unsupportedSetStatement
supportedSetStatement
: SET (optionWithType | optionWithoutType)
(COMMA (optionWithType | optionWithoutType))* #setOptions
| SET identifier AS DEFAULT STORAGE VAULT #setDefaultStorageVault
Expand All @@ -811,7 +811,7 @@ unsupportedSetStatement
;

optionWithType
: (GLOBAL | LOCAL | SESSION) identifier EQ (expression | DEFAULT)
: (GLOBAL | LOCAL | SESSION) identifier EQ (expression | DEFAULT) #setVariableWithType
;

optionWithoutType
Expand All @@ -820,7 +820,7 @@ optionWithoutType
| NAMES (charsetName=identifierOrText | DEFAULT)
(COLLATE collateName=identifierOrText | DEFAULT)? #setCollate
| PASSWORD (FOR userIdentify)? EQ (STRING_LITERAL
| (PASSWORD LEFT_PAREN STRING_LITERAL RIGHT_PAREN)) #setPassword
| (isPlain=PASSWORD LEFT_PAREN STRING_LITERAL RIGHT_PAREN)) #setPassword
| LDAP_ADMIN_PASSWORD EQ (STRING_LITERAL
| (PASSWORD LEFT_PAREN STRING_LITERAL RIGHT_PAREN)) #setLdapAdminPassword
| variable #setVariableWithoutType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,29 +176,33 @@ public void alterStorageVault(StorageVaultType type, Map<String, String> propert

@VisibleForTesting
public void setDefaultStorageVault(SetDefaultStorageVaultStmt stmt) throws DdlException {
setDefaultStorageVault(stmt.getStorageVaultName());
}

public void setDefaultStorageVault(String vaultName) throws DdlException {
Cloud.AlterObjStoreInfoRequest.Builder builder = Cloud.AlterObjStoreInfoRequest.newBuilder();
Cloud.StorageVaultPB.Builder vaultBuilder = Cloud.StorageVaultPB.newBuilder();
vaultBuilder.setName(stmt.getStorageVaultName());
vaultBuilder.setName(vaultName);
builder.setVault(vaultBuilder.build());
builder.setOp(Operation.SET_DEFAULT_VAULT);
String vaultId;
LOG.info("try to set vault {} as default vault", stmt.getStorageVaultName());
LOG.info("try to set vault {} as default vault", vaultName);
try {
Cloud.AlterObjStoreInfoResponse resp =
MetaServiceProxy.getInstance().alterStorageVault(builder.build());
if (resp.getStatus().getCode() != Cloud.MetaServiceCode.OK) {
LOG.warn("failed to set default storage vault response: {}, vault name {}",
resp, stmt.getStorageVaultName());
resp, vaultName);
throw new DdlException(resp.getStatus().getMsg());
}
vaultId = resp.getStorageVaultId();
} catch (RpcException e) {
LOG.warn("failed to set default storage vault due to RpcException: {}, vault name {}",
e, stmt.getStorageVaultName());
e, vaultName);
throw new DdlException(e.getMessage());
}
LOG.info("succeed to set {} as default vault, vault id {}", stmt.getStorageVaultName(), vaultId);
setDefaultStorageVault(Pair.of(stmt.getStorageVaultName(), vaultId));
LOG.info("succeed to set {} as default vault, vault id {}", vaultName, vaultId);
setDefaultStorageVault(Pair.of(vaultName, vaultId));
}

public void unsetDefaultStorageVault() throws DdlException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,11 @@ public void setPassword(SetPassVar stmt) throws DdlException {
false /* set by resolver */, false);
}

public void setPassword(UserIdentity userIdentity, byte[] password) throws DdlException {
setPasswordInternal(userIdentity, password, null, true /* err on non exist */,
false /* set by resolver */, false);
}

public void replaySetPassword(PrivInfo info) {
try {
setPasswordInternal(info.getUserIdent(), info.getPasswd(), null, true /* err on non exist */,
Expand Down Expand Up @@ -986,6 +991,12 @@ public void setLdapPassword(SetLdapPassVar stmt) {
LOG.info("finished to set ldap password.");
}

public void setLdapPassword(String ldapPassword) {
ldapInfo = new LdapInfo(ldapPassword);
Env.getCurrentEnv().getEditLog().logSetLdapPassword(ldapInfo);
LOG.info("finished to set ldap password.");
}

public void replaySetLdapPassword(LdapInfo info) {
ldapInfo = info;
if (LOG.isDebugEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import org.apache.doris.analysis.ArithmeticExpr.Operator;
import org.apache.doris.analysis.BrokerDesc;
import org.apache.doris.analysis.ColumnNullableType;
import org.apache.doris.analysis.PassVar;
import org.apache.doris.analysis.SetType;
import org.apache.doris.analysis.StorageBackend;
import org.apache.doris.analysis.TableName;
import org.apache.doris.analysis.TableScanParams;
Expand Down Expand Up @@ -173,7 +175,19 @@
import org.apache.doris.nereids.DorisParser.SelectClauseContext;
import org.apache.doris.nereids.DorisParser.SelectColumnClauseContext;
import org.apache.doris.nereids.DorisParser.SelectHintContext;
import org.apache.doris.nereids.DorisParser.SetCharsetContext;
import org.apache.doris.nereids.DorisParser.SetCollateContext;
import org.apache.doris.nereids.DorisParser.SetDefaultStorageVaultContext;
import org.apache.doris.nereids.DorisParser.SetLdapAdminPasswordContext;
import org.apache.doris.nereids.DorisParser.SetNamesContext;
import org.apache.doris.nereids.DorisParser.SetOperationContext;
import org.apache.doris.nereids.DorisParser.SetOptionsContext;
import org.apache.doris.nereids.DorisParser.SetPasswordContext;
import org.apache.doris.nereids.DorisParser.SetSystemVariableContext;
import org.apache.doris.nereids.DorisParser.SetTransactionContext;
import org.apache.doris.nereids.DorisParser.SetUserPropertiesContext;
import org.apache.doris.nereids.DorisParser.SetUserVariableContext;
import org.apache.doris.nereids.DorisParser.SetVariableWithTypeContext;
import org.apache.doris.nereids.DorisParser.ShowConfigContext;
import org.apache.doris.nereids.DorisParser.ShowConstraintContext;
import org.apache.doris.nereids.DorisParser.ShowCreateMTMVContext;
Expand Down Expand Up @@ -398,6 +412,10 @@
import org.apache.doris.nereids.trees.plans.commands.RefreshMTMVCommand;
import org.apache.doris.nereids.trees.plans.commands.ReplayCommand;
import org.apache.doris.nereids.trees.plans.commands.ResumeMTMVCommand;
import org.apache.doris.nereids.trees.plans.commands.SetDefaultStorageVaultCommand;
import org.apache.doris.nereids.trees.plans.commands.SetOptionsCommand;
import org.apache.doris.nereids.trees.plans.commands.SetTransactionCommand;
import org.apache.doris.nereids.trees.plans.commands.SetUserPropertiesCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowConfigCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowConstraintsCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowCreateMTMVCommand;
Expand Down Expand Up @@ -438,6 +456,14 @@
import org.apache.doris.nereids.trees.plans.commands.info.RefreshMTMVInfo;
import org.apache.doris.nereids.trees.plans.commands.info.ResumeMTMVInfo;
import org.apache.doris.nereids.trees.plans.commands.info.RollupDefinition;
import org.apache.doris.nereids.trees.plans.commands.info.SetCharsetAndCollateVarOp;
import org.apache.doris.nereids.trees.plans.commands.info.SetLdapPassVarOp;
import org.apache.doris.nereids.trees.plans.commands.info.SetNamesVarOp;
import org.apache.doris.nereids.trees.plans.commands.info.SetPassVarOp;
import org.apache.doris.nereids.trees.plans.commands.info.SetSessionVarOp;
import org.apache.doris.nereids.trees.plans.commands.info.SetUserDefinedVarOp;
import org.apache.doris.nereids.trees.plans.commands.info.SetUserPropertyVarOp;
import org.apache.doris.nereids.trees.plans.commands.info.SetVarOp;
import org.apache.doris.nereids.trees.plans.commands.info.ShowCreateMTMVInfo;
import org.apache.doris.nereids.trees.plans.commands.info.SimpleColumnDefinition;
import org.apache.doris.nereids.trees.plans.commands.info.StepPartition;
Expand Down Expand Up @@ -3833,4 +3859,111 @@ public LogicalPlan visitShowConfig(ShowConfigContext ctx) {
}
return command;
}

@Override
public SetOptionsCommand visitSetOptions(SetOptionsContext ctx) {
List<SetVarOp> setVarOpList = new ArrayList<>(1);
for (Object child : ctx.children) {
if (child instanceof RuleNode) {
setVarOpList.add(typedVisit((RuleNode) child));
}
}
return new SetOptionsCommand(setVarOpList);
}

@Override
public SetVarOp visitSetSystemVariable(SetSystemVariableContext ctx) {
SetType type = SetType.DEFAULT;
if (ctx.GLOBAL() != null) {
type = SetType.GLOBAL;
} else if (ctx.LOCAL() != null || ctx.SESSION() != null) {
type = SetType.SESSION;
}
String name = stripQuotes(ctx.identifier().getText());
Expression expression = ctx.expression() != null ? typedVisit(ctx.expression()) : null;
return new SetSessionVarOp(type, name, expression);
}

@Override
public SetVarOp visitSetVariableWithType(SetVariableWithTypeContext ctx) {
SetType type = SetType.DEFAULT;
if (ctx.GLOBAL() != null) {
type = SetType.GLOBAL;
} else if (ctx.LOCAL() != null || ctx.SESSION() != null) {
type = SetType.SESSION;
}
String name = stripQuotes(ctx.identifier().getText());
Expression expression = ctx.expression() != null ? typedVisit(ctx.expression()) : null;
return new SetSessionVarOp(type, name, expression);
}

@Override
public SetVarOp visitSetPassword(SetPasswordContext ctx) {
String user;
String host;
boolean isDomain;
String passwordText;
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().ATSIGN() != null;
userIdentity = new UserIdentity(user, host, isDomain);
}
passwordText = stripQuotes(ctx.STRING_LITERAL().getText());
return new SetPassVarOp(userIdentity, new PassVar(passwordText, ctx.isPlain != null));
}

@Override
public SetVarOp visitSetNames(SetNamesContext ctx) {
return new SetNamesVarOp();
}

@Override
public SetVarOp visitSetCharset(SetCharsetContext ctx) {
String charset = ctx.charsetName != null ? stripQuotes(ctx.charsetName.getText()) : null;
return new SetCharsetAndCollateVarOp(charset);
}

@Override
public SetVarOp visitSetCollate(SetCollateContext ctx) {
String charset = ctx.charsetName != null ? stripQuotes(ctx.charsetName.getText()) : null;
String collate = ctx.collateName != null ? stripQuotes(ctx.collateName.getText()) : null;
return new SetCharsetAndCollateVarOp(charset, collate);
}

@Override
public SetVarOp visitSetLdapAdminPassword(SetLdapAdminPasswordContext ctx) {
String passwordText = stripQuotes(ctx.STRING_LITERAL().getText());
boolean isPlain = ctx.PASSWORD() != null;
return new SetLdapPassVarOp(new PassVar(passwordText, isPlain));
}

@Override
public SetVarOp visitSetUserVariable(SetUserVariableContext ctx) {
String name = stripQuotes(ctx.identifier().getText());
Expression expression = typedVisit(ctx.expression());
return new SetUserDefinedVarOp(name, expression);
}

@Override
public SetTransactionCommand visitSetTransaction(SetTransactionContext ctx) {
return new SetTransactionCommand();
}

@Override
public SetUserPropertiesCommand visitSetUserProperties(SetUserPropertiesContext ctx) {
String user = ctx.user != null ? stripQuotes(ctx.user.getText()) : null;
Map<String, String> userPropertiesMap = visitPropertyItemList(ctx.propertyItemList());
List<SetUserPropertyVarOp> setUserPropertyVarOpList = new ArrayList<>(userPropertiesMap.size());
for (Map.Entry<String, String> entry : userPropertiesMap.entrySet()) {
setUserPropertyVarOpList.add(new SetUserPropertyVarOp(user, entry.getKey(), entry.getValue()));
}
return new SetUserPropertiesCommand(user, setUserPropertyVarOpList);
}

@Override
public SetDefaultStorageVaultCommand visitSetDefaultStorageVault(SetDefaultStorageVaultContext ctx) {
return new SetDefaultStorageVaultCommand(stripQuotes(ctx.identifier().getText()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ public enum PlanType {
DROP_CATALOG_RECYCLE_BIN_COMMAND,
UNSUPPORTED_COMMAND,
CREATE_TABLE_LIKE_COMMAND,
SET_OPTIONS_COMMAND,
SET_TRANSACTION_COMMAND,
SET_USER_PROPERTIES_COMMAND,
SET_DEFAULT_STORAGE_VAULT_COMMAND,

PREPARED_COMMAND,
EXECUTE_COMMAND,
Expand Down
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
@@ -0,0 +1,29 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.apache.doris.nereids.trees.plans.commands;

/**
* NeedAuditEncryption
*/
public interface NeedAuditEncryption {

boolean needAuditEncryption();

String toSql();

}
Loading

0 comments on commit 3303c04

Please sign in to comment.