-
Notifications
You must be signed in to change notification settings - Fork 411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
throw exception when meet error duing cop request handling #162
Merged
Merged
Changes from 12 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
71c09fb
fix cop test regression
windtalker 6b8a054
address comments
windtalker 6f32efd
format code
windtalker 11b3e09
fix npe for dag execute
windtalker 64fef5c
Merge branch 'cop' of https://github.com/pingcap/tics into cop
windtalker f96fcf4
format code
windtalker 324b64d
address comment
windtalker 6b06122
add some comments
windtalker 2327e9f
throw exception when meet error duing cop request handling
windtalker 72d11ad
Merge branch 'cop' of https://github.com/pingcap/tics into cop
windtalker 428459a
Merge branch 'cop' of https://github.com/pingcap/tics into cop
windtalker f3eb6e5
address comments
windtalker d8bb7d9
add error code
windtalker b6eaa3b
throw exception when meet error duing cop request handling
windtalker fe7916e
address comments
windtalker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,51 +11,56 @@ | |
namespace DB | ||
{ | ||
|
||
bool DAGStringConverter::buildTSString(const tipb::TableScan & ts, std::stringstream & ss) | ||
namespace ErrorCodes | ||
{ | ||
TableID id; | ||
extern const int UNKNOWN_TABLE; | ||
extern const int COP_BAD_DAG_REQUEST; | ||
} // namespace ErrorCodes | ||
|
||
void DAGStringConverter::buildTSString(const tipb::TableScan & ts, std::stringstream & ss) | ||
{ | ||
TableID table_id; | ||
if (ts.has_table_id()) | ||
{ | ||
id = ts.table_id(); | ||
table_id = ts.table_id(); | ||
} | ||
else | ||
{ | ||
// do not have table id | ||
return false; | ||
throw Exception("Table id not specified in table scan executor", ErrorCodes::COP_BAD_DAG_REQUEST); | ||
} | ||
auto & tmt_ctx = context.getTMTContext(); | ||
auto storage = tmt_ctx.getStorages().get(id); | ||
auto storage = tmt_ctx.getStorages().get(table_id); | ||
if (storage == nullptr) | ||
{ | ||
return false; | ||
throw Exception("Table " + std::to_string(table_id) + " doesn't exist.", ErrorCodes::UNKNOWN_TABLE); | ||
} | ||
const auto * merge_tree = dynamic_cast<const StorageMergeTree *>(storage.get()); | ||
if (!merge_tree) | ||
{ | ||
return false; | ||
throw Exception("Only MergeTree table is supported in DAG request", ErrorCodes::COP_BAD_DAG_REQUEST); | ||
} | ||
|
||
if (ts.columns_size() == 0) | ||
{ | ||
// no column selected, must be something wrong | ||
return false; | ||
throw Exception("No column is selected in table scan executor", ErrorCodes::COP_BAD_DAG_REQUEST); | ||
} | ||
columns_from_ts = storage->getColumns().getAllPhysical(); | ||
for (const tipb::ColumnInfo & ci : ts.columns()) | ||
{ | ||
ColumnID cid = ci.column_id(); | ||
if (cid <= 0 || cid > (ColumnID)columns_from_ts.size()) | ||
{ | ||
throw Exception("column id out of bound"); | ||
throw Exception("column id out of bound", ErrorCodes::COP_BAD_DAG_REQUEST); | ||
} | ||
String name = merge_tree->getTableInfo().columns[cid - 1].name; | ||
output_from_ts.push_back(std::move(name)); | ||
} | ||
ss << "FROM " << merge_tree->getTableInfo().db_name << "." << merge_tree->getTableInfo().name << " "; | ||
return true; | ||
} | ||
|
||
bool DAGStringConverter::buildSelString(const tipb::Selection & sel, std::stringstream & ss) | ||
void DAGStringConverter::buildSelString(const tipb::Selection & sel, std::stringstream & ss) | ||
{ | ||
bool first = true; | ||
for (const tipb::Expr & expr : sel.conditions()) | ||
|
@@ -72,35 +77,30 @@ bool DAGStringConverter::buildSelString(const tipb::Selection & sel, std::string | |
} | ||
ss << s << " "; | ||
} | ||
return true; | ||
} | ||
|
||
bool DAGStringConverter::buildLimitString(const tipb::Limit & limit, std::stringstream & ss) | ||
{ | ||
ss << "LIMIT " << limit.limit() << " "; | ||
return true; | ||
} | ||
void DAGStringConverter::buildLimitString(const tipb::Limit & limit, std::stringstream & ss) { ss << "LIMIT " << limit.limit() << " "; } | ||
|
||
//todo return the error message | ||
bool DAGStringConverter::buildString(const tipb::Executor & executor, std::stringstream & ss) | ||
void DAGStringConverter::buildString(const tipb::Executor & executor, std::stringstream & ss) | ||
{ | ||
switch (executor.tp()) | ||
{ | ||
case tipb::ExecType::TypeTableScan: | ||
return buildTSString(executor.tbl_scan(), ss); | ||
case tipb::ExecType::TypeIndexScan: | ||
// index scan not supported | ||
return false; | ||
throw Exception("IndexScan is not supported"); | ||
case tipb::ExecType::TypeSelection: | ||
return buildSelString(executor.selection(), ss); | ||
case tipb::ExecType::TypeAggregation: | ||
// stream agg is not supported, treated as normal agg | ||
case tipb::ExecType::TypeStreamAgg: | ||
//todo support agg | ||
return false; | ||
throw Exception("Aggregation is not supported"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto. |
||
case tipb::ExecType::TypeTopN: | ||
// todo support top n | ||
return false; | ||
throw Exception("TopN is not supported"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto. |
||
case tipb::ExecType::TypeLimit: | ||
return buildLimitString(executor.limit(), ss); | ||
} | ||
|
@@ -125,10 +125,7 @@ String DAGStringConverter::buildSqlString() | |
std::stringstream project; | ||
for (const tipb::Executor & executor : dag_request.executors()) | ||
{ | ||
if (!buildString(executor, query_buf)) | ||
{ | ||
return ""; | ||
} | ||
buildString(executor, query_buf); | ||
} | ||
if (!isProject(dag_request.executors(dag_request.executors_size() - 1))) | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error code?