-
Notifications
You must be signed in to change notification settings - Fork 760
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
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c8acd95
[function] SELECT VERSION()
PsiACE 623cfb1
Merge branch 'datafuselabs:master' into version()
3afb26c
[building] fix build, and add simd feature
PsiACE 61fe8f8
[docs] add version function to menu
PsiACE c127833
[test] add basic test for version func
PsiACE 01e2dac
[docs] fix result
PsiACE 53dfa19
[lint] cargo fmt
PsiACE 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
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 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") | ||
} | ||
} |
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 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(()) | ||
} |
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
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 |
---|---|---|
|
@@ -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 | | ||
+------------+ | ||
+-------------------+ | ||
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. 💯 |
||
| DATABASE(default) | | ||
+-------------------+ | ||
| default | | ||
+-------------------+ | ||
``` |
23 changes: 23 additions & 0 deletions
23
website/datafuse/docs/sqlstatement/information-functions/version.md
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,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) | | ||
+----------------------------------------------------------------------------------------+ | ||
``` |
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 |
---|---|---|
|
@@ -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 | ||
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. +1 |
||
- Other Functions: | ||
- ToTypeName: sqlstatement/other-functions/totypename.md | ||
- String Functions: | ||
|
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.
Cool, but why we need the udfs function?
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.
Sorry, got it.
It's ok to me.