[Bug] Fix show load like match (#6314)
* fix show load like match * Compatible with historical issues
This commit is contained in:
@ -115,6 +115,9 @@ public class CancelLoadStmt extends DdlStmt {
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
if (!isAccurateMatch && !label.contains("%")) {
|
||||
label = "%" + label + "%";
|
||||
}
|
||||
} while (false);
|
||||
|
||||
if (!valid) {
|
||||
|
||||
@ -219,6 +219,9 @@ public class ShowLoadStmt extends ShowStmt {
|
||||
break CHECK;
|
||||
}
|
||||
|
||||
if (!isAccurateMatch && !value.contains("%")) {
|
||||
value = "%" + value + "%";
|
||||
}
|
||||
if (hasLabel) {
|
||||
labelValue = value;
|
||||
} else if (hasState) {
|
||||
|
||||
@ -65,6 +65,7 @@ import org.apache.doris.catalog.TabletMeta;
|
||||
import org.apache.doris.catalog.Type;
|
||||
import org.apache.doris.cluster.ClusterNamespace;
|
||||
import org.apache.doris.common.AnalysisException;
|
||||
import org.apache.doris.common.CaseSensibility;
|
||||
import org.apache.doris.common.Config;
|
||||
import org.apache.doris.common.DdlException;
|
||||
import org.apache.doris.common.ErrorCode;
|
||||
@ -75,6 +76,7 @@ import org.apache.doris.common.LabelAlreadyUsedException;
|
||||
import org.apache.doris.common.LoadException;
|
||||
import org.apache.doris.common.MetaNotFoundException;
|
||||
import org.apache.doris.common.Pair;
|
||||
import org.apache.doris.common.PatternMatcher;
|
||||
import org.apache.doris.common.UserException;
|
||||
import org.apache.doris.common.util.ListComparator;
|
||||
import org.apache.doris.common.util.MetaLockUtils;
|
||||
@ -1591,7 +1593,7 @@ public class Load {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isLabelExist(String dbName, String labelValue, boolean isAccurateMatch) throws DdlException {
|
||||
public boolean isLabelExist(String dbName, String labelValue, boolean isAccurateMatch) throws DdlException, AnalysisException {
|
||||
// get load job and check state
|
||||
Database db = Catalog.getCurrentCatalog().getDb(dbName);
|
||||
if (db == null) {
|
||||
@ -1609,8 +1611,9 @@ public class Load {
|
||||
loadJobs.addAll(labelToLoadJobs.get(labelValue));
|
||||
}
|
||||
} else {
|
||||
PatternMatcher matcher = PatternMatcher.createMysqlPattern(labelValue, CaseSensibility.LABEL.getCaseSensibility());
|
||||
for (Map.Entry<String, List<LoadJob>> entry : labelToLoadJobs.entrySet()) {
|
||||
if (entry.getKey().contains(labelValue)) {
|
||||
if (matcher.match(entry.getKey())) {
|
||||
loadJobs.addAll(entry.getValue());
|
||||
}
|
||||
}
|
||||
@ -1627,7 +1630,7 @@ public class Load {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean cancelLoadJob(CancelLoadStmt stmt, boolean isAccurateMatch) throws DdlException {
|
||||
public boolean cancelLoadJob(CancelLoadStmt stmt, boolean isAccurateMatch) throws DdlException, AnalysisException {
|
||||
// get params
|
||||
String dbName = stmt.getDbName();
|
||||
String label = stmt.getLabel();
|
||||
@ -1653,9 +1656,10 @@ public class Load {
|
||||
matchLoadJobs.addAll(labelToLoadJobs.get(label));
|
||||
}
|
||||
} else {
|
||||
PatternMatcher matcher = PatternMatcher.createMysqlPattern(label, CaseSensibility.LABEL.getCaseSensibility());
|
||||
for (Map.Entry<String, List<LoadJob>> entry : labelToLoadJobs.entrySet()) {
|
||||
if (entry.getKey().contains(label)) {
|
||||
matchLoadJobs.addAll(entry.getValue());
|
||||
if (matcher.match(entry.getKey())) {
|
||||
loadJobs.addAll(entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1904,7 +1908,7 @@ public class Load {
|
||||
}
|
||||
|
||||
public LinkedList<List<Comparable>> getLoadJobInfosByDb(long dbId, String dbName, String labelValue,
|
||||
boolean accurateMatch, Set<JobState> states) {
|
||||
boolean accurateMatch, Set<JobState> states) throws AnalysisException {
|
||||
LinkedList<List<Comparable>> loadJobInfos = new LinkedList<List<Comparable>>();
|
||||
readLock();
|
||||
try {
|
||||
@ -1915,6 +1919,11 @@ public class Load {
|
||||
|
||||
long start = System.currentTimeMillis();
|
||||
LOG.debug("begin to get load job info, size: {}", loadJobs.size());
|
||||
PatternMatcher matcher = null;
|
||||
if (labelValue != null && !accurateMatch) {
|
||||
matcher = PatternMatcher.createMysqlPattern(labelValue, CaseSensibility.LABEL.getCaseSensibility());
|
||||
}
|
||||
|
||||
for (LoadJob loadJob : loadJobs) {
|
||||
// filter first
|
||||
String label = loadJob.getLabel();
|
||||
@ -1926,7 +1935,7 @@ public class Load {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if (!label.contains(labelValue)) {
|
||||
if (!matcher.match(label)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,12 +23,15 @@ import org.apache.doris.catalog.Catalog;
|
||||
import org.apache.doris.catalog.Database;
|
||||
import org.apache.doris.catalog.Table;
|
||||
import org.apache.doris.cluster.ClusterNamespace;
|
||||
import org.apache.doris.common.AnalysisException;
|
||||
import org.apache.doris.common.CaseSensibility;
|
||||
import org.apache.doris.common.Config;
|
||||
import org.apache.doris.common.DataQualityException;
|
||||
import org.apache.doris.common.DdlException;
|
||||
import org.apache.doris.common.DuplicatedRequestException;
|
||||
import org.apache.doris.common.LabelAlreadyUsedException;
|
||||
import org.apache.doris.common.MetaNotFoundException;
|
||||
import org.apache.doris.common.PatternMatcher;
|
||||
import org.apache.doris.common.UserException;
|
||||
import org.apache.doris.common.io.Writable;
|
||||
import org.apache.doris.common.util.LogBuilder;
|
||||
@ -294,7 +297,7 @@ public class LoadManager implements Writable{
|
||||
Catalog.getCurrentCatalog().getEditLog().logCreateLoadJob(loadJob);
|
||||
}
|
||||
|
||||
public void cancelLoadJob(CancelLoadStmt stmt, boolean isAccurateMatch) throws DdlException {
|
||||
public void cancelLoadJob(CancelLoadStmt stmt, boolean isAccurateMatch) throws DdlException, AnalysisException {
|
||||
Database db = Catalog.getCurrentCatalog().getDb(stmt.getDbName());
|
||||
if (db == null) {
|
||||
throw new DdlException("Db does not exist. name: " + stmt.getDbName());
|
||||
@ -316,8 +319,9 @@ public class LoadManager implements Writable{
|
||||
matchLoadJobs.addAll(labelToLoadJobs.get(stmt.getLabel()));
|
||||
}
|
||||
} else {
|
||||
PatternMatcher matcher = PatternMatcher.createMysqlPattern(stmt.getLabel(), CaseSensibility.LABEL.getCaseSensibility());
|
||||
for (Map.Entry<String, List<LoadJob>> entry : labelToLoadJobs.entrySet()) {
|
||||
if (entry.getKey().contains(stmt.getLabel())) {
|
||||
if (matcher.match(entry.getKey())) {
|
||||
matchLoadJobs.addAll(entry.getValue());
|
||||
}
|
||||
}
|
||||
@ -503,7 +507,7 @@ public class LoadManager implements Writable{
|
||||
* The result is unordered.
|
||||
*/
|
||||
public List<List<Comparable>> getLoadJobInfosByDb(long dbId, String labelValue,
|
||||
boolean accurateMatch, Set<String> statesValue) {
|
||||
boolean accurateMatch, Set<String> statesValue) throws AnalysisException {
|
||||
LinkedList<List<Comparable>> loadJobInfos = new LinkedList<List<Comparable>>();
|
||||
if (!dbIdToLabelToLoadJobs.containsKey(dbId)) {
|
||||
return loadJobInfos;
|
||||
@ -538,8 +542,9 @@ public class LoadManager implements Writable{
|
||||
loadJobList.addAll(labelToLoadJobs.get(labelValue));
|
||||
} else {
|
||||
// non-accurate match
|
||||
PatternMatcher matcher = PatternMatcher.createMysqlPattern(labelValue, CaseSensibility.LABEL.getCaseSensibility());
|
||||
for (Map.Entry<String, List<LoadJob>> entry : labelToLoadJobs.entrySet()) {
|
||||
if (entry.getKey().contains(labelValue)) {
|
||||
if (matcher.match(entry.getKey())) {
|
||||
loadJobList.addAll(entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
@ -108,10 +108,12 @@ public class ShowLoadStmtTest {
|
||||
stmt.analyze(analyzer);
|
||||
Assert.assertEquals("SHOW LOAD FROM `testCluster:testDb` WHERE `label` = \'abc\' LIMIT 10", stmt.toString());
|
||||
|
||||
StringLiteral stringLiteralLike = new StringLiteral("ab%");
|
||||
LikePredicate likePredicate = new LikePredicate(org.apache.doris.analysis.LikePredicate.Operator.LIKE,
|
||||
slotRef, stringLiteral);
|
||||
slotRef, stringLiteralLike);
|
||||
|
||||
stmt = new ShowLoadStmt(null, likePredicate, null, new LimitElement(10));
|
||||
stmt.analyze(analyzer);
|
||||
Assert.assertEquals("SHOW LOAD FROM `testCluster:testDb` WHERE `label` LIKE \'abc\' LIMIT 10", stmt.toString());
|
||||
Assert.assertEquals("SHOW LOAD FROM `testCluster:testDb` WHERE `label` LIKE \'ab%\' LIMIT 10", stmt.toString());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user