-
Notifications
You must be signed in to change notification settings - Fork 752
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4894 from cadl/issue-4860
ISSUE-4860: fix empty query
- Loading branch information
Showing
9 changed files
with
132 additions
and
7 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright 2022 Datafuse Labs. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use std::sync::Arc; | ||
|
||
use common_datavalues::prelude::*; | ||
use common_exception::Result; | ||
use common_planners::EmptyPlan; | ||
use common_streams::DataBlockStream; | ||
use common_streams::SendableDataBlockStream; | ||
|
||
use crate::interpreters::Interpreter; | ||
use crate::interpreters::InterpreterPtr; | ||
use crate::sessions::QueryContext; | ||
|
||
// EmptyInterpreter is a Empty interpreter to execute nothing. | ||
// Such as the query '/*!40101*/', it makes the front-end (e.g. MySQL handler) no need check the EmptyPlan or not. | ||
pub struct EmptyInterpreter {} | ||
|
||
impl EmptyInterpreter { | ||
pub fn try_create(_ctx: Arc<QueryContext>, _plan: EmptyPlan) -> Result<InterpreterPtr> { | ||
Ok(Arc::new(EmptyInterpreter {})) | ||
} | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl Interpreter for EmptyInterpreter { | ||
fn name(&self) -> &str { | ||
"EmptyInterpreter" | ||
} | ||
|
||
async fn execute( | ||
&self, | ||
_input_stream: Option<SendableDataBlockStream>, | ||
) -> Result<SendableDataBlockStream> { | ||
Ok(Box::pin(DataBlockStream::create( | ||
Arc::new(DataSchema::empty()), | ||
None, | ||
vec![], | ||
))) | ||
} | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright 2021 Datafuse Labs. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use common_base::tokio; | ||
use common_exception::Result; | ||
use databend_query::interpreters::*; | ||
use databend_query::sql::*; | ||
use futures::TryStreamExt; | ||
use pretty_assertions::assert_eq; | ||
|
||
#[tokio::test(flavor = "multi_thread", worker_threads = 1)] | ||
async fn test_empty_interpreter() -> Result<()> { | ||
common_tracing::init_default_ut_tracing(); | ||
let ctx = crate::tests::create_query_context().await?; | ||
|
||
{ | ||
let query = "/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */"; | ||
let plan = PlanParser::parse(ctx.clone(), query).await?; | ||
let executor = InterpreterFactory::get(ctx.clone(), plan)?; | ||
assert_eq!(executor.name(), "EmptyInterpreter"); | ||
|
||
let stream = executor.execute(None).await?; | ||
let result = stream.try_collect::<Vec<_>>().await; | ||
assert!(result.is_ok()) | ||
} | ||
|
||
{ | ||
let query = "/*!40101*/select number from numbers_mt(1)"; | ||
let plan = PlanParser::parse(ctx.clone(), query).await?; | ||
let executor = InterpreterFactory::get(ctx.clone(), plan)?; | ||
assert_eq!(executor.name(), "SelectInterpreter"); | ||
|
||
let stream = executor.execute(None).await?; | ||
let result = stream.try_collect::<Vec<_>>().await?; | ||
let block = &result[0]; | ||
assert_eq!(block.num_columns(), 1); | ||
|
||
let expected = vec![ | ||
"+--------+", | ||
"| number |", | ||
"+--------+", | ||
"| 0 |", | ||
"+--------+", | ||
]; | ||
common_datablocks::assert_blocks_sorted_eq(expected, result.as_slice()); | ||
} | ||
|
||
Ok(()) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
0 | ||
1 | ||
0 |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/*!40101*/select number from numbers_mt(2); | ||
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; | ||
/*!40101*/select number from numbers_mt(1); |