Skip to content

Commit

Permalink
[fix] row policy with a predicate containing non-existing column apac…
Browse files Browse the repository at this point in the history
  • Loading branch information
LuGuangming committed Mar 10, 2024
1 parent 340427c commit 4aa8d08
Showing 1 changed file with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,25 @@

package org.apache.doris.analysis;

import org.apache.doris.catalog.Column;
import org.apache.doris.catalog.DatabaseIf;
import org.apache.doris.catalog.Env;
import org.apache.doris.catalog.TableIf;
import org.apache.doris.common.Config;
import org.apache.doris.common.ErrorCode;
import org.apache.doris.common.ErrorReport;
import org.apache.doris.common.UserException;
import org.apache.doris.common.util.PrintableMap;
import org.apache.doris.datasource.CatalogIf;
import org.apache.doris.mysql.privilege.PrivPredicate;
import org.apache.doris.policy.FilterType;
import org.apache.doris.policy.PolicyTypeEnum;
import org.apache.doris.qe.ConnectContext;

import lombok.Getter;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
Expand Down Expand Up @@ -92,6 +98,16 @@ public CreatePolicyStmt(PolicyTypeEnum type, boolean ifNotExists, String policyN
this.properties = properties;
}

private void getColumnFromPredicate(Expr root, List<String> columnNameList) {
if (root instanceof SlotRef) {
columnNameList.add(((SlotRef) root).getColumnName());
return;
}
for (Expr child : root.getChildren()) {
getColumnFromPredicate(child, columnNameList);
}
}

@Override
public void analyze(Analyzer analyzer) throws UserException {
super.analyze(analyzer);
Expand All @@ -103,7 +119,6 @@ public void analyze(Analyzer analyzer) throws UserException {
}
break;
case ROW:
default:
tableName.analyze(analyzer);
if (user != null) {
user.analyze();
Expand All @@ -112,6 +127,29 @@ public void analyze(Analyzer analyzer) throws UserException {
user.getQualifiedUser(), user.getHost(), tableName.getTbl());
}
}
// validate the columns present in the predicate with the table schema
List<String> columnList = new ArrayList<>();
getColumnFromPredicate(wherePredicate, columnList);
String catalogName = tableName.getCtl();
CatalogIf catalog = Env.getCurrentEnv().getCatalogMgr().getCatalogOrAnalysisException(catalogName);
DatabaseIf db = catalog.getDbOrAnalysisException(tableName.getDb());
TableIf table = db.getTableOrAnalysisException(tableName.getTbl());
for (String predColName : columnList) {
boolean isColPresentInTableSchema = false;
for (Column tableColumn : table.getBaseSchema(true)) {
if (tableColumn.getName().equalsIgnoreCase(predColName)) {
isColPresentInTableSchema = true;
break;
}
}
if (!isColPresentInTableSchema) {
ErrorReport.reportAnalysisException(ErrorCode.ERR_BAD_FIELD_ERROR, predColName,
tableName.getTbl());
}
}
break;
default:
throw new IllegalStateException("Unexcepted value" + type);
}
// check auth
if (!Env.getCurrentEnv().getAccessManager().checkGlobalPriv(ConnectContext.get(), PrivPredicate.ADMIN)) {
Expand Down

0 comments on commit 4aa8d08

Please sign in to comment.