Fix show variables where failed (#30)

This commit is contained in:
Zhao Chun
2017-08-18 13:49:23 +08:00
committed by 李超勇
parent f5882c587c
commit 3edd06f275
4 changed files with 19 additions and 3 deletions

View File

@ -24,6 +24,7 @@ import com.baidu.palo.catalog.AccessPrivilege;
import com.baidu.palo.catalog.Catalog;
import com.baidu.palo.catalog.Column;
import com.baidu.palo.catalog.Database;
import com.baidu.palo.catalog.InfoSchemaDb;
import com.baidu.palo.catalog.Table;
import com.baidu.palo.cluster.ClusterNamespace;
import com.baidu.palo.catalog.Type;
@ -525,6 +526,10 @@ public class Analyzer {
if (tblName == null) {
d = resolveColumnRef(colName);
} else {
if (InfoSchemaDb.isInfoSchemaDb(tblName.getDb()) ||
(tblName.getDb() == null && InfoSchemaDb.isInfoSchemaDb(getDefaultDb()))) {
tblName = new TableName(tblName.getDb(), tblName.getTbl().toLowerCase());
}
d = resolveColumnRef(tblName, colName);
}
if (d == null && hasAncestors() && isSubquery) {

View File

@ -49,9 +49,9 @@ public final class ExprSubstitutionMap {
}
// Only used to convert show statement to select statement
public ExprSubstitutionMap(boolean check_analyzed) {
public ExprSubstitutionMap(boolean checkAnalyzed) {
this(Lists.<Expr>newArrayList(), Lists.<Expr>newArrayList());
this.checkAnalyzed_ = false;
this.checkAnalyzed_ = checkAnalyzed;
}
public ExprSubstitutionMap(List<Expr> lhs, List<Expr> rhs) {

View File

@ -82,7 +82,7 @@ public class ShowVariablesStmt extends ShowStmt {
analyze(analyzer);
// Columns
SelectList selectList = new SelectList();
ExprSubstitutionMap aliasMap = new ExprSubstitutionMap();
ExprSubstitutionMap aliasMap = new ExprSubstitutionMap(false);
TableName tableName = null;
if (type == SetType.GLOBAL) {
tableName = new TableName(InfoSchemaDb.getDatabaseName(), "GLOBAL_VARIABLES");

View File

@ -90,4 +90,15 @@ public class InfoSchemaDb extends Database {
public static String getFullInfoSchemaDbName(String cluster) {
return ClusterNamespace.getDbFullName(cluster, DATABASE_NAME);
}
public static boolean isInfoSchemaDb(String dbName) {
if (dbName == null) {
return false;
}
String[] ele = dbName.split(ClusterNamespace.CLUSTER_DELIMITER);
if (ele.length == 2) {
dbName = ele[1];
}
return DATABASE_NAME.equalsIgnoreCase(dbName);
}
}