Skip to content
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

[function] SELECT VERSION() #782

Merged
merged 7 commits into from
Jun 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions common/functions/src/udfs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ mod database_test;
mod to_type_name_test;
#[cfg(test)]
mod udf_example_test;
#[cfg(test)]
mod version_test;

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, but why we need the udfs function?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, got it.
It's ok to me.

//
// 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")
}
}
60 changes: 60 additions & 0 deletions common/functions/src/udfs/version_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright 2020-2021 The Datafuse Authors.
//
// SPDX-License-Identifier: Apache-2.0.

#[test]
fn test_version_function() -> anyhow::Result<()> {
use std::sync::Arc;

use common_datavalues::*;
use pretty_assertions::assert_eq;

use crate::udfs::*;
use crate::*;

#[allow(dead_code)]
struct Test {
name: &'static str,
display: &'static str,
nullable: bool,
columns: Vec<DataColumnarValue>,
expect: DataArrayRef,
error: &'static str,
func: Box<dyn IFunction>,
}

let tests = vec![Test {
name: "version-function-passed",
display: "version",
nullable: false,
func: VersionFunction::try_create("version")?,
columns: vec![Arc::new(StringArray::from(vec![
"FuseQuery v-0.1.0-3afb26c(1.54.0-nightly-2021-06-09T07:56:09.461981495+00:00)",
]))
.into()],
expect: Arc::new(StringArray::from(vec![
"FuseQuery v-0.1.0-3afb26c(1.54.0-nightly-2021-06-09T07:56:09.461981495+00:00)",
])),
error: "",
}];

for t in tests {
let rows = t.columns[0].len();
let func = t.func;
match func.eval(&t.columns, rows) {
Ok(v) => {
// Display check.
let expect_display = t.display.to_string();
let actual_display = format!("{}", func);
assert_eq!(expect_display, actual_display);

assert_eq!(v.to_array()?.as_ref(), t.expect.as_ref());
}
Err(e) => {
assert_eq!(t.error, e.to_string());
}
}
}

Ok(())
}
3 changes: 3 additions & 0 deletions fusequery/query/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ path = "src/bin/fuse-query.rs"
name = "fuse-benchmark"
path = "src/bin/fuse-benchmark.rs"

[features]
simd = ["common-arrow/simd"]

[dependencies]
# Workspace dependencies
common-arrow = {path = "../../common/arrow"}
Expand Down
5 changes: 5 additions & 0 deletions fusequery/query/src/configs/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ lazy_static! {
let timestamp = option_env!("VERGEN_BUILD_TIMESTAMP");

let ver = match (build_semver, git_sha, rustc_semver, timestamp) {
#[cfg(not(feature = "simd"))]
(Some(v1), Some(v2), Some(v3), Some(v4)) => format!("{}-{}({}-{})", v1, v2, v3, v4),
#[cfg(feature = "simd")]
(Some(v1), Some(v2), Some(v3), Some(v4)) => {
format!("{}-{}-simd({}-{})", v1, v2, v3, v4)
}
_ => String::new(),
};
ver
Expand Down
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
3 changes: 3 additions & 0 deletions fusestore/store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ edition = "2018"
name = "fuse-store"
path = "src/bin/fuse-store.rs"

[features]
simd = ["common-arrow/simd"]

[dependencies]
# Workspace dependencies
common-arrow = {path = "../../common/arrow"}
Expand Down
5 changes: 5 additions & 0 deletions fusestore/store/src/configs/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ lazy_static! {
let timestamp = option_env!("VERGEN_BUILD_TIMESTAMP");

let ver = match (build_semver, git_sha, rustc_semver, timestamp) {
#[cfg(not(feature = "simd"))]
(Some(v1), Some(v2), Some(v3), Some(v4)) => format!("{}-{}({}-{})", v1, v2, v3, v4),
#[cfg(feature = "simd")]
(Some(v1), Some(v2), Some(v3), Some(v4)) => {
format!("{}-{}-simd({}-{})", v1, v2, v3, v4)
}
_ => String::new(),
};
ver
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ Returns the name of the currently selected database. If no database is selected,
## Syntax

```
SELECT DATABASE()
SELECT DATABASE()
```

## Examples

```
mysql> SELECT DATABASE();
+------------+
| database() |
+------------+
| default |
+------------+
+-------------------+
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

| DATABASE(default) |
+-------------------+
| default |
+-------------------+
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
id: version
title: VERSION
---

Return the current version information of FuseQuery.

## Syntax

```
SELECT VERSION()
```

## Examples

```
mysql> SELECT VERSION();
+----------------------------------------------------------------------------------------+
| VERSION(FuseQuery v-0.1.0-3afb26c(1.54.0-nightly-2021-06-09T07:56:09.461981495+00:00)) |
+----------------------------------------------------------------------------------------+
| FuseQuery v-0.1.0-3afb26c(1.54.0-nightly-2021-06-09T07:56:09.461981495+00:00) |
+----------------------------------------------------------------------------------------+
```
1 change: 1 addition & 0 deletions website/datafuse/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ nav:
- SIPHASH: sqlstatement/hash-functions/siphash.md
- Information Functions:
- DATABASE: sqlstatement/information-functions/database.md
- VERSION: sqlstatement/information-functions/version.md
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

- Other Functions:
- ToTypeName: sqlstatement/other-functions/totypename.md
- String Functions:
Expand Down