Skip to content

Commit

Permalink
[function] SELECT VERSION()
Browse files Browse the repository at this point in the history
Signed-off-by: Chojan Shang <psiace@outlook.com>
  • Loading branch information
PsiACE committed Jun 8, 2021
1 parent b9c6fa1 commit c8acd95
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 0 deletions.
2 changes: 2 additions & 0 deletions common/functions/src/udfs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ mod database;
mod to_type_name;
mod udf;
mod udf_example;
mod version;

pub use database::DatabaseFunction;
pub use to_type_name::ToTypeNameFunction;
pub use udf::UdfFunction;
pub use udf_example::UdfExampleFunction;
pub use version::VersionFunction;
2 changes: 2 additions & 0 deletions common/functions/src/udfs/udf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use common_exception::Result;
use crate::udfs::DatabaseFunction;
use crate::udfs::ToTypeNameFunction;
use crate::udfs::UdfExampleFunction;
use crate::udfs::VersionFunction;
use crate::FactoryFuncRef;

#[derive(Clone)]
Expand All @@ -18,6 +19,7 @@ impl UdfFunction {
map.insert("example", UdfExampleFunction::try_create);
map.insert("totypename", ToTypeNameFunction::try_create);
map.insert("database", DatabaseFunction::try_create);
map.insert("version", VersionFunction::try_create);
Ok(())
}
}
53 changes: 53 additions & 0 deletions common/functions/src/udfs/version.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright 2020-2021 The Datafuse Authors.
//
// SPDX-License-Identifier: Apache-2.0.

use std::fmt;

use common_datavalues::DataColumnarValue;
use common_datavalues::DataSchema;
use common_datavalues::DataType;
use common_exception::Result;

use crate::IFunction;

#[derive(Clone)]
pub struct VersionFunction {
display_name: String,
}

impl VersionFunction {
pub fn try_create(display_name: &str) -> Result<Box<dyn IFunction>> {
Ok(Box::new(VersionFunction {
display_name: display_name.to_string(),
}))
}
}

impl IFunction for VersionFunction {
fn name(&self) -> &str {
"VersionFunction"
}

fn return_type(&self, _args: &[DataType]) -> Result<DataType> {
Ok(DataType::Utf8)
}

fn nullable(&self, _input_schema: &DataSchema) -> Result<bool> {
Ok(false)
}

fn eval(&self, columns: &[DataColumnarValue], _input_rows: usize) -> Result<DataColumnarValue> {
Ok(columns[0].clone())
}

fn num_arguments(&self) -> usize {
1
}
}

impl fmt::Display for VersionFunction {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "version")
}
}
3 changes: 3 additions & 0 deletions fusequery/query/src/functions/context_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ impl ContextFunction {
"database" => vec![Expression::Literal(DataValue::Utf8(Some(
ctx.get_current_database(),
)))],
"version" => vec![Expression::Literal(DataValue::Utf8(Some(
ctx.get_fuse_version(),
)))],
_ => vec![],
})
}
Expand Down
9 changes: 9 additions & 0 deletions fusequery/query/src/sessions/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub struct FuseQueryContext {
current_database: Arc<RwLock<String>>,
progress: Arc<Progress>,
runtime: Arc<RwLock<Runtime>>,
version: String,
}

pub type FuseQueryContextRef = Arc<FuseQueryContext>;
Expand All @@ -57,6 +58,10 @@ impl FuseQueryContext {
current_database: Arc::new(RwLock::new(String::from("default"))),
progress: Arc::new(Progress::create()),
runtime: Arc::new(RwLock::new(Runtime::with_worker_threads(cpus)?)),
version: format!(
"FuseQuery v-{}",
crate::configs::config::FUSE_COMMIT_VERSION
),
};
// Default settings.
ctx.initial_settings()?;
Expand Down Expand Up @@ -218,6 +223,10 @@ impl FuseQueryContext {
self.settings.try_update_u64("max_threads", threads)
}

pub fn get_fuse_version(&self) -> String {
self.version.clone()
}

apply_macros! { apply_getter_setter_settings, apply_initial_settings, apply_update_settings,
("max_block_size", u64, 10000, "Maximum block size for reading".to_string()),
("flight_client_timeout", u64, 60, "Max duration the flight client request is allowed to take in seconds. By default, it is 60 seconds".to_string()),
Expand Down

0 comments on commit c8acd95

Please sign in to comment.