Skip to content

Commit

Permalink
Fix #6 SHOW FULL TABLES WHERE Table_type != VIEW sql can not execute (#…
Browse files Browse the repository at this point in the history
…11)

* change picture to word

* change picture to word

* SHOW FULL TABLES WHERE Table_type != VIEW sql can not execute
  • Loading branch information
chaoyli authored and imay committed Aug 15, 2017
1 parent b71dcea commit 5296746
Show file tree
Hide file tree
Showing 16 changed files with 59 additions and 28 deletions.
1 change: 1 addition & 0 deletions be/src/exec/olap_rewrite_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ Status OlapRewriteNode::close(RuntimeState* state) {
if (is_closed()) {
return Status::OK;
}
_child_row_batch.reset();
// RETURN_IF_ERROR(child(0)->close(state));
Expr::close(_columns, state);
return ExecNode::close(state);
Expand Down
3 changes: 3 additions & 0 deletions be/src/exec/schema_scan_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ void SchemaScanNode::copy_one_row() {
memset(_dest_tuple, 0, _dest_tuple_desc->num_null_bytes());

for (int i = 0; i < _slot_num; ++i) {
if (!_dest_tuple_desc->slots()[i]->is_materialized()) {
continue;
}
int j = _index_map[i];

if (_src_tuple->is_null(_src_tuple_desc->slots()[j]->null_indicator_offset())) {
Expand Down
10 changes: 9 additions & 1 deletion be/src/exec/schema_scanner/frontend_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,14 @@ Status FrontendHelper::show_varialbes(
return Status::OK;
}

std::string FrontendHelper::extract_db_name(const std::string& full_name) {
auto found = full_name.find(':');
if (found == std::string::npos) {
return full_name;
}
found++;
return std::string(full_name.c_str() + found, full_name.size() - found);
}

}

/* vim: set ts=4 sw=4 sts=4 tw=100 */
3 changes: 2 additions & 1 deletion be/src/exec/schema_scanner/frontend_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class FrontendHelper {
const int32_t port,
const TShowVariableRequest &var_params,
TShowVariableResult *var_result);

static std::string extract_db_name(const std::string& full_name);
private:
static ExecEnv* _s_exec_env;
};
Expand All @@ -64,4 +66,3 @@ class FrontendHelper {

#endif

/* vim: set ts=4 sw=4 sts=4 tw=100 : */
7 changes: 4 additions & 3 deletions be/src/exec/schema_scanner/schema_columns_scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,10 @@ Status SchemaColumnsScanner::fill_one_row(Tuple *tuple, MemPool *pool) {
{
void *slot = tuple->get_slot(_tuple_desc->slots()[1]->tuple_offset());
StringValue* str_slot = reinterpret_cast<StringValue*>(slot);
str_slot->ptr = (char *)pool->allocate(_db_result.dbs[_db_index - 1].length());
str_slot->len = _db_result.dbs[_db_index - 1].length();
memcpy(str_slot->ptr, _db_result.dbs[_db_index - 1].c_str(), str_slot->len);
std::string db_name = FrontendHelper::extract_db_name(_db_result.dbs[_db_index - 1]);
str_slot->ptr = (char *)pool->allocate(db_name.size());
str_slot->len = db_name.size();
memcpy(str_slot->ptr, db_name.c_str(), str_slot->len);
}
// table
{
Expand Down
10 changes: 4 additions & 6 deletions be/src/exec/schema_scanner/schema_schemata_scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,10 @@ Status SchemaSchemataScanner::fill_one_row(Tuple *tuple, MemPool *pool) {
{
void *slot = tuple->get_slot(_tuple_desc->slots()[1]->tuple_offset());
StringValue* str_slot = reinterpret_cast<StringValue*>(slot);
str_slot->ptr = (char *)pool->allocate(_db_result.dbs[_db_index].length());
if (NULL == str_slot->ptr) {
return Status("Allocate memory failed.");
}
str_slot->len = _db_result.dbs[_db_index].length();
memcpy(str_slot->ptr, _db_result.dbs[_db_index].c_str(), str_slot->len);
std::string db_name = FrontendHelper::extract_db_name(_db_result.dbs[_db_index]);
str_slot->ptr = (char *)pool->allocate(db_name.size());
str_slot->len = db_name.size();
memcpy(str_slot->ptr, db_name.c_str(), str_slot->len);
}
// DEFAULT_CHARACTER_SET_NAME
{
Expand Down
10 changes: 4 additions & 6 deletions be/src/exec/schema_scanner/schema_tables_scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,10 @@ Status SchemaTablesScanner::fill_one_row(Tuple *tuple, MemPool *pool) {
{
void *slot = tuple->get_slot(_tuple_desc->slots()[1]->tuple_offset());
StringValue* str_slot = reinterpret_cast<StringValue*>(slot);
str_slot->ptr = (char *)pool->allocate(_db_result.dbs[_db_index - 1].length());
if (NULL == str_slot->ptr) {
return Status("Allocate memcpy failed.");
}
str_slot->len = _db_result.dbs[_db_index - 1].length();
memcpy(str_slot->ptr, _db_result.dbs[_db_index - 1].c_str(), str_slot->len);
std::string db_name = FrontendHelper::extract_db_name(_db_result.dbs[_db_index - 1]);
str_slot->ptr = (char *)pool->allocate(db_name.size());
str_slot->len = db_name.size();
memcpy(str_slot->ptr, db_name.c_str(), str_slot->len);
}
// name
{
Expand Down
2 changes: 1 addition & 1 deletion be/src/exec/schema_scanner/schema_tables_scanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class SchemaTablesScanner : public SchemaScanner {

int _db_index;
int _table_index;
TGetDbsResult _db_result;
TGetDbsResult _db_result;
TListTableStatusResult _table_result;
static SchemaScanner::ColumnDesc _s_tbls_columns[];
};
Expand Down
1 change: 0 additions & 1 deletion be/src/exec/schema_scanner/schema_variables_scanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,4 @@ class SchemaVariablesScanner : public SchemaScanner {
};

}

#endif
2 changes: 1 addition & 1 deletion fe/src/com/baidu/palo/analysis/BaseTableRef.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public BaseTableRef(TableRef ref, Table table, TableName tableName) {
this.name = tableName;
// Set implicit aliases if no explicit one was given.
if (hasExplicitAlias()) return;
aliases_ = new String[] { name.toString(), table.getName() };
aliases_ = new String[] { name.toString(), tableName.getNoClusterString(), table.getName() };
}

protected BaseTableRef(BaseTableRef other) {
Expand Down
12 changes: 10 additions & 2 deletions fe/src/com/baidu/palo/analysis/ExprSubstitutionMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,20 @@
public final class ExprSubstitutionMap {
private final static Logger LOG = LoggerFactory.getLogger(ExprSubstitutionMap.class);

private boolean checkAnalyzed_ = true;
private List<Expr> lhs_; // left-hand side
private List<Expr> rhs_; // right-hand side

public ExprSubstitutionMap() {
this(Lists.<Expr>newArrayList(), Lists.<Expr>newArrayList());
}

// Only used to convert show statement to select statement
public ExprSubstitutionMap(boolean check_analyzed) {
this(Lists.<Expr>newArrayList(), Lists.<Expr>newArrayList());
this.checkAnalyzed_ = false;
}

public ExprSubstitutionMap(List<Expr> lhs, List<Expr> rhs) {
lhs_ = lhs;
rhs_ = rhs;
Expand All @@ -57,7 +64,8 @@ public ExprSubstitutionMap(List<Expr> lhs, List<Expr> rhs) {
* across query blocks. It is not required that the lhsExpr is analyzed.
*/
public void put(Expr lhsExpr, Expr rhsExpr) {
Preconditions.checkState(rhsExpr.isAnalyzed(), "Rhs expr must be analyzed.");
Preconditions.checkState(!checkAnalyzed_ || rhsExpr.isAnalyzed(),
"Rhs expr must be analyzed.");
lhs_.add(lhsExpr);
rhs_.add(rhsExpr);
}
Expand Down Expand Up @@ -166,7 +174,7 @@ private void verify() {
// Preconditions.checkState(false);
}
}
Preconditions.checkState(rhs_.get(i).isAnalyzed());
Preconditions.checkState(!checkAnalyzed_ || rhs_.get(i).isAnalyzed());
}
}

Expand Down
2 changes: 1 addition & 1 deletion fe/src/com/baidu/palo/analysis/ShowDbStmt.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public SelectStmt toSelectStmt(Analyzer analyzer) {
}
// Columns
SelectList selectList = new SelectList();
ExprSubstitutionMap aliasMap = new ExprSubstitutionMap();
ExprSubstitutionMap aliasMap = new ExprSubstitutionMap(false);
SelectListItem item = new SelectListItem(new SlotRef(TABLE_NAME, "SCHEMA_NAME"), DB_COL);
selectList.addItem(item);
aliasMap.put(new SlotRef(null, DB_COL), item.getExpr().clone(null));
Expand Down
2 changes: 1 addition & 1 deletion fe/src/com/baidu/palo/analysis/ShowTableStatusStmt.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public SelectStmt toSelectStmt(Analyzer analyzer) throws AnalysisException {
analyze(analyzer);
// Columns
SelectList selectList = new SelectList();
ExprSubstitutionMap aliasMap = new ExprSubstitutionMap();
ExprSubstitutionMap aliasMap = new ExprSubstitutionMap(false);
// Name
SelectListItem item = new SelectListItem(new SlotRef(TABLE_NAME, "TABLE_NAME"), "Name");
selectList.addItem(item);
Expand Down
2 changes: 1 addition & 1 deletion fe/src/com/baidu/palo/analysis/ShowTableStmt.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public SelectStmt toSelectStmt(Analyzer analyzer) throws AnalysisException {
analyze(analyzer);
// Columns
SelectList selectList = new SelectList();
ExprSubstitutionMap aliasMap = new ExprSubstitutionMap();
ExprSubstitutionMap aliasMap = new ExprSubstitutionMap(false);
SelectListItem item = new SelectListItem(new SlotRef(TABLE_NAME, "TABLE_NAME"),
NAME_COL_PREFIX + ClusterNamespace.getDbNameFromFullName(db));
selectList.addItem(item);
Expand Down
13 changes: 13 additions & 0 deletions fe/src/com/baidu/palo/analysis/TableName.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,19 @@ public boolean isFullyQualified() {
return db != null && !db.isEmpty() && !tbl.isEmpty();
}

public String getNoClusterString() {
if (db == null) {
return tbl;
} else {
String dbName = ClusterNamespace.getDbNameFromFullName(db);
if (dbName == null) {
return db + "." + tbl;
} else {
return dbName + "." + tbl;
}
}
}

@Override
public String toString() {
if (db == null) {
Expand Down
7 changes: 4 additions & 3 deletions fe/src/com/baidu/palo/service/FrontendServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,13 @@ public TGetDbsResult getDbNames(TGetDbsParams params) throws TException {
throw new TException("Pattern is in bad format " + params.getPattern());
}
}
for (String db : dbNames) {
for (String fullName : dbNames) {
final String db = ClusterNamespace.getDbNameFromFullName(fullName);
if (matcher != null && !matcher.match(db)) {
continue;
}
if (userPropertyMgr.checkAccess(params.user, db, AccessPrivilege.READ_ONLY)) {
dbs.add(db);
if (userPropertyMgr.checkAccess(params.user, fullName, AccessPrivilege.READ_ONLY)) {
dbs.add(fullName);
}
}
result.setDbs(dbs);
Expand Down

0 comments on commit 5296746

Please sign in to comment.