forked from databendlabs/databend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ISSUE databendlabs#3206: Support SHOW ENGINES Statement
- Loading branch information
Showing
13 changed files
with
198 additions
and
0 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
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
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,38 @@ | ||
// 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 std::sync::Arc; | ||
|
||
use common_exception::Result; | ||
use common_tracing::tracing; | ||
|
||
use crate::sessions::QueryContext; | ||
use crate::sql::statements::AnalyzableStatement; | ||
use crate::sql::statements::AnalyzedResult; | ||
use crate::sql::PlanParser; | ||
|
||
#[derive(Debug, Clone, PartialEq)] | ||
pub struct DfShowEngines; | ||
|
||
#[async_trait::async_trait] | ||
impl AnalyzableStatement for DfShowEngines { | ||
#[tracing::instrument(level = "debug", skip(self, ctx), fields(ctx.id = ctx.get_id().as_str()))] | ||
async fn analyze(&self, ctx: Arc<QueryContext>) -> Result<AnalyzedResult> { | ||
let rewritten_query = "SELECT * FROM system.engines"; | ||
let rewritten_query_plan = PlanParser::parse(rewritten_query, ctx); | ||
Ok(AnalyzedResult::SimpleQuery(Box::new( | ||
rewritten_query_plan.await?, | ||
))) | ||
} | ||
} |
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,90 @@ | ||
// 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 std::any::Any; | ||
use std::sync::Arc; | ||
|
||
use common_datablocks::DataBlock; | ||
use common_datavalues::prelude::*; | ||
use common_exception::Result; | ||
use common_meta_types::TableIdent; | ||
use common_meta_types::TableInfo; | ||
use common_meta_types::TableMeta; | ||
use common_planners::ReadDataSourcePlan; | ||
use common_streams::DataBlockStream; | ||
use common_streams::SendableDataBlockStream; | ||
|
||
use crate::sessions::QueryContext; | ||
use crate::storages::Table; | ||
|
||
pub struct EnginesTable { | ||
table_info: TableInfo, | ||
} | ||
|
||
impl EnginesTable { | ||
pub fn create(table_id: u64) -> Self { | ||
let schema = DataSchemaRefExt::create(vec![ | ||
DataField::new("Engine", DataType::String, false), | ||
DataField::new("Support", DataType::String, false), | ||
DataField::new("Comment", DataType::String, false), | ||
]); | ||
|
||
let table_info = TableInfo { | ||
desc: "'system'.'engines'".to_string(), | ||
name: "engines".to_string(), | ||
ident: TableIdent::new(table_id, 0), | ||
meta: TableMeta { | ||
schema, | ||
engine: "SystemEngines".to_string(), | ||
..Default::default() | ||
}, | ||
}; | ||
EnginesTable { table_info } | ||
} | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl Table for EnginesTable { | ||
fn as_any(&self) -> &dyn Any { | ||
self | ||
} | ||
|
||
fn get_table_info(&self) -> &TableInfo { | ||
&self.table_info | ||
} | ||
|
||
async fn read( | ||
&self, | ||
_ctx: Arc<QueryContext>, | ||
_plan: &ReadDataSourcePlan, | ||
) -> Result<SendableDataBlockStream> { | ||
let mut engine_name = Vec::with_capacity(1); | ||
let mut engine_support = Vec::with_capacity(1); | ||
let mut engine_comment = Vec::with_capacity(1); | ||
// fuse engine | ||
engine_name.push("FUSE".as_bytes()); | ||
engine_support.push("YES".as_bytes()); | ||
engine_comment.push("Fuse storage engine".as_bytes()); | ||
let block = DataBlock::create_by_array(self.table_info.schema(), vec![ | ||
Series::new(engine_name), | ||
Series::new(engine_support), | ||
Series::new(engine_comment), | ||
]); | ||
Ok(Box::pin(DataBlockStream::create( | ||
self.table_info.schema(), | ||
None, | ||
vec![block], | ||
))) | ||
} | ||
} |
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,44 @@ | ||
// 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 std::sync::Arc; | ||
|
||
use common_base::tokio; | ||
use common_exception::Result; | ||
use databend_query::storages::system::EnginesTable; | ||
use databend_query::storages::Table; | ||
use databend_query::storages::ToReadDataSourcePlan; | ||
use futures::TryStreamExt; | ||
|
||
#[tokio::test(flavor = "multi_thread", worker_threads = 1)] | ||
async fn test_engines_table() -> Result<()> { | ||
let ctx = crate::tests::create_query_context()?; | ||
|
||
let table: Arc<dyn Table> = Arc::new(EnginesTable::create(1)); | ||
let source_plan = table.read_plan(ctx.clone(), None).await?; | ||
|
||
let stream = table.read(ctx, &source_plan).await?; | ||
let result = stream.try_collect::<Vec<_>>().await?; | ||
|
||
let expected = vec![ | ||
"+--------+---------+---------------------+", | ||
"| Engine | Support | Comment |", | ||
"+--------+---------+---------------------+", | ||
"| FUSE | YES | Fuse storage engine |", | ||
"+--------+---------+---------------------+", | ||
]; | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
FUSE YES Fuse storage engine |
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,2 @@ | ||
SHOW ENGINES; | ||
|