Skip to content

Commit 5293672

Browse files
committed
Merge branch 'main' of https://github.com/datafuselabs/databend into query-tests
Signed-off-by: Chojan Shang <[email protected]>
2 parents 7b2c9f6 + 1af20a3 commit 5293672

File tree

108 files changed

+1244
-407
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+1244
-407
lines changed

.github/workflows/stateless-tests-standalone.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
- name: Minio Setup for (ubuntu-latest only)
5454
if: matrix.config.os == 'ubuntu-latest'
5555
run: |
56-
docker run -d -p 9000:9000 --name minio \
56+
docker run -d -p 9900:9000 --name minio \
5757
-e "MINIO_ACCESS_KEY=minioadmin" \
5858
-e "MINIO_SECRET_KEY=minioadmin" \
5959
-v /tmp/data:/data \
@@ -63,8 +63,9 @@ jobs:
6363
export AWS_ACCESS_KEY_ID=minioadmin
6464
export AWS_SECRET_ACCESS_KEY=minioadmin
6565
export AWS_EC2_METADATA_DISABLED=true
66+
aws --endpoint-url http://127.0.0.1:9900/ s3 mb s3://testbucket
67+
aws --endpoint-url http://127.0.0.1:9900/ s3 cp tests/data s3://testbucket/tests/data --recursive
6668
67-
aws --endpoint-url http://127.0.0.1:9000/ s3 mb s3://testbucket
6869
6970
- name: Run Stateless Tests with Standalone mode (ubuntu-latest only)
7071
if: matrix.config.os == 'ubuntu-latest'

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,6 @@ tests/perfs/*-result.json
4343

4444
# python
4545
venv/
46+
*.pyc
47+
__pycache__/*
48+

Cargo.lock

+2-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/arrow/Cargo.toml

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
[package]
2-
name = "common-arrow"
3-
version = "0.1.0"
42
authors = ["Databend Authors <[email protected]>"]
3+
edition = "2021"
54
license = "Apache-2.0"
5+
name = "common-arrow"
66
publish = false
7-
edition = "2021"
7+
version = "0.1.0"
88

99
[lib]
1010
doctest = false
1111
test = false
1212

1313
[features]
14-
default = ["arrow-default", "parquet-default"]
1514
arrow-default = ["arrow/compute", "arrow/regex", "arrow/merge_sort", "arrow/io_csv", "arrow/io_parquet", "arrow/io_json", "arrow/io_flight"]
15+
default = ["arrow-default", "parquet-default"]
1616
parquet-default = ["parquet2/stream", "parquet2/lz4"]
1717
simd = ["arrow/simd"]
1818

1919
[dependencies] # In alphabetical order
2020
# Workspace dependencies
2121

2222
# Github dependencies
23-
arrow = { package = "arrow2", git="https://github.com/datafuse-extras/arrow2", default-features = false, rev = "83d828c" }
24-
arrow-format = { version = "0.3.0", features = ["flight-data", "flight-service"]}
25-
parquet2 = { version = "0.6", default_features = false }
23+
arrow = {package = "arrow2", git = "https://github.com/datafuse-extras/arrow2", default-features = false, rev = "83d828c"}
24+
arrow-format = {version = "0.3.0", features = ["flight-data", "flight-service"]}
25+
parquet2 = {version = "0.6", default_features = false}
2626
# Crates.io dependencies
2727

2828
[dev-dependencies]

common/base/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ pub use profiling::Profiling;
3030
pub use progress::Progress;
3131
pub use progress::ProgressCallback;
3232
pub use progress::ProgressValues;
33-
pub use runtime::BlockingWait;
3433
pub use runtime::Dropper;
3534
pub use runtime::Runtime;
3635
pub use runtime::TrySpawn;

common/base/src/runtime.rs

-76
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,11 @@
1313
// limitations under the License.
1414

1515
use std::future::Future;
16-
use std::sync::mpsc::channel;
1716
use std::sync::Arc;
1817
use std::thread;
19-
use std::time::Duration;
2018

2119
use common_exception::ErrorCode;
2220
use common_exception::Result;
23-
use futures::future::Either;
2421
use tokio::runtime::Handle;
2522
use tokio::sync::oneshot;
2623
use tokio::task::JoinHandle;
@@ -67,79 +64,6 @@ impl<S: TrySpawn> TrySpawn for Arc<S> {
6764
}
6865
}
6966

70-
/// Blocking wait for a future to complete.
71-
///
72-
/// This trait turns an `async` function into `sync`.
73-
/// It is meant to provide convenience for building a proof-of-concept demo or else.
74-
/// Always avoid using it in a real world production,
75-
/// unless **you KNOW what you are doing**:
76-
///
77-
/// - `wait()` runs the future in current thread and **blocks** current thread until the future is finished.
78-
/// - `wait_in(rt)` runs the future in the specified runtime, and **blocks** current thread until the future is finished.
79-
pub trait BlockingWait
80-
where
81-
Self: Future + Send + 'static,
82-
Self::Output: Send + 'static,
83-
{
84-
/// Runs the future and blocks current thread.
85-
///
86-
/// ```ignore
87-
/// use runtime::BlockingWait;
88-
/// async fn five() -> u8 { 5 }
89-
/// assert_eq!(5, five().wait());
90-
/// ```
91-
fn wait(self, timeout: Option<Duration>) -> Result<Self::Output>;
92-
93-
/// Runs the future in provided runtime and blocks current thread.
94-
fn wait_in<RT: TrySpawn>(self, rt: &RT, timeout: Option<Duration>) -> Result<Self::Output>;
95-
}
96-
97-
impl<T> BlockingWait for T
98-
where
99-
T: Future + Send + 'static,
100-
T::Output: Send + 'static,
101-
{
102-
fn wait(self, timeout: Option<Duration>) -> Result<T::Output> {
103-
match timeout {
104-
None => Ok(futures::executor::block_on(self)),
105-
Some(d) => {
106-
let rt = tokio::runtime::Builder::new_current_thread()
107-
.enable_time()
108-
.build()
109-
.map_err(|e| ErrorCode::TokioError(format!("{}", e)))?;
110-
111-
rt.block_on(async move {
112-
let sl = tokio::time::sleep(d);
113-
let sl = Box::pin(sl);
114-
let task = Box::pin(self);
115-
116-
match futures::future::select(sl, task).await {
117-
Either::Left((_, _)) => Err::<T::Output, ErrorCode>(ErrorCode::Timeout(
118-
format!("timeout: {:?}", d),
119-
)),
120-
Either::Right((res, _)) => Ok(res),
121-
}
122-
})
123-
}
124-
}
125-
}
126-
127-
fn wait_in<RT: TrySpawn>(self, rt: &RT, timeout: Option<Duration>) -> Result<T::Output> {
128-
let (tx, rx) = channel();
129-
let _jh = rt.spawn(async move {
130-
let r = self.await;
131-
let _ = tx.send(r);
132-
});
133-
let reply = match timeout {
134-
Some(to) => rx
135-
.recv_timeout(to)
136-
.map_err(|timeout_err| ErrorCode::Timeout(timeout_err.to_string()))?,
137-
None => rx.recv().map_err(ErrorCode::from_std_error)?,
138-
};
139-
Ok(reply)
140-
}
141-
}
142-
14367
/// Tokio Runtime wrapper.
14468
/// If a runtime is in an asynchronous context, shutdown it first.
14569
pub struct Runtime {

common/base/tests/it/runtime.rs

-59
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ use std::sync::Arc;
1616
use std::sync::Mutex;
1717

1818
use common_base::*;
19-
use common_exception::ErrorCode;
2019
use common_exception::Result;
21-
use tokio::time::Duration;
2220

2321
#[tokio::test(flavor = "multi_thread", worker_threads = 8)]
2422
async fn test_runtime() -> Result<()> {
@@ -61,60 +59,3 @@ async fn test_runtime() -> Result<()> {
6159

6260
Ok(())
6361
}
64-
65-
#[test]
66-
fn test_blocking_wait() -> Result<()> {
67-
async fn five() -> Result<u8> {
68-
Ok(5)
69-
}
70-
71-
let res = five().wait(None)?;
72-
assert!(res.is_ok());
73-
assert_eq!(5, res.unwrap());
74-
75-
let rt = Runtime::with_default_worker_threads().unwrap();
76-
77-
let res = five().wait_in(&rt, None)?;
78-
assert!(res.is_ok());
79-
assert_eq!(5, res.unwrap());
80-
81-
Ok(())
82-
}
83-
84-
#[test]
85-
fn test_blocking_wait_timeout() -> Result<()> {
86-
async fn sleep_5_sec() -> Result<()> {
87-
tokio::time::sleep(Duration::from_millis(5000)).await;
88-
Ok(())
89-
}
90-
91-
let res = sleep_5_sec().wait(Some(Duration::from_millis(1000)));
92-
assert!(res.is_err());
93-
assert_eq!(ErrorCode::Timeout("").code(), res.unwrap_err().code());
94-
95-
let rt = Runtime::with_default_worker_threads().unwrap();
96-
97-
let res = sleep_5_sec().wait_in(&rt, Some(Duration::from_millis(1000)));
98-
assert!(res.is_err());
99-
assert_eq!(ErrorCode::Timeout("").code(), res.unwrap_err().code());
100-
101-
Ok(())
102-
}
103-
104-
#[test]
105-
fn test_blocking_wait_no_timeout() -> Result<()> {
106-
async fn sleep_1_sec() -> Result<()> {
107-
tokio::time::sleep(Duration::from_millis(1000)).await;
108-
Ok(())
109-
}
110-
111-
let res = sleep_1_sec().wait(Some(Duration::from_millis(5000)))?;
112-
assert!(res.is_ok());
113-
114-
let rt = Runtime::with_default_worker_threads().unwrap();
115-
116-
let res = sleep_1_sec().wait_in(&rt, Some(Duration::from_millis(5000)))?;
117-
assert!(res.is_ok());
118-
119-
Ok(())
120-
}

common/exception/src/exception.rs

+1
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ build_exceptions! {
186186
BadPredicateRows(56),
187187
SHA1CheckFailed(57),
188188
UnknownColumn(58),
189+
InvalidSourceFormat(59),
189190

190191
// uncategorized
191192
UnexpectedResponseType(600),

common/functions/src/scalars/maths/math.rs

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use crate::scalars::LogFunction;
2727
use crate::scalars::PiFunction;
2828
use crate::scalars::RadiansFunction;
2929
use crate::scalars::SignFunction;
30+
use crate::scalars::SqrtFunction;
3031
use crate::scalars::TrigonometricAcosFunction;
3132
use crate::scalars::TrigonometricAsinFunction;
3233
use crate::scalars::TrigonometricAtan2Function;
@@ -63,5 +64,6 @@ impl MathsFunction {
6364
factory.register("atan", TrigonometricAtanFunction::desc());
6465
factory.register("atan2", TrigonometricAtan2Function::desc());
6566
factory.register("sign", SignFunction::desc());
67+
factory.register("sqrt", SqrtFunction::desc());
6668
}
6769
}

common/functions/src/scalars/maths/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ mod log;
2222
mod math;
2323
mod pi;
2424
mod sign;
25+
mod sqrt;
2526
mod trigonometric;
2627

2728
pub use abs::AbsFunction;
@@ -38,6 +39,7 @@ pub use log::LogFunction;
3839
pub use math::MathsFunction;
3940
pub use pi::PiFunction;
4041
pub use sign::SignFunction;
42+
pub use sqrt::SqrtFunction;
4143
pub use trigonometric::Trigonometric;
4244
pub use trigonometric::TrigonometricAcosFunction;
4345
pub use trigonometric::TrigonometricAsinFunction;
+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
// Copyright 2020 Datafuse Labs.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
use std::fmt;
16+
17+
use common_datavalues::prelude::*;
18+
use common_datavalues::DataSchema;
19+
use common_datavalues::DataType;
20+
use common_exception::ErrorCode;
21+
use common_exception::Result;
22+
23+
use crate::scalars::function_factory::FunctionDescription;
24+
use crate::scalars::function_factory::FunctionFeatures;
25+
use crate::scalars::Function;
26+
27+
#[derive(Clone)]
28+
pub struct SqrtFunction {
29+
display_name: String,
30+
}
31+
32+
impl SqrtFunction {
33+
pub fn try_create(display_name: &str) -> Result<Box<dyn Function>> {
34+
Ok(Box::new(SqrtFunction {
35+
display_name: display_name.to_string(),
36+
}))
37+
}
38+
39+
pub fn desc() -> FunctionDescription {
40+
FunctionDescription::creator(Box::new(Self::try_create))
41+
.features(FunctionFeatures::default().deterministic())
42+
}
43+
}
44+
45+
impl Function for SqrtFunction {
46+
fn name(&self) -> &str {
47+
&*self.display_name
48+
}
49+
50+
fn num_arguments(&self) -> usize {
51+
1
52+
}
53+
54+
fn return_type(&self, args: &[DataType]) -> Result<DataType> {
55+
if is_numeric(&args[0]) || args[0] == DataType::String || args[0] == DataType::Null {
56+
Ok(DataType::Float64)
57+
} else {
58+
Err(ErrorCode::IllegalDataType(format!(
59+
"Expected numeric types, but got {}",
60+
args[0]
61+
)))
62+
}
63+
}
64+
65+
fn nullable(&self, _input_schema: &DataSchema) -> Result<bool> {
66+
Ok(true)
67+
}
68+
69+
fn eval(&self, columns: &DataColumnsWithField, _input_rows: usize) -> Result<DataColumn> {
70+
let opt_iter = columns[0]
71+
.column()
72+
.to_minimal_array()?
73+
.cast_with_type(&DataType::Float64)?;
74+
let opt_iter = opt_iter.f64()?.into_iter().map(|v| match v {
75+
Some(&v) => {
76+
if v >= 0_f64 {
77+
Some(v.sqrt())
78+
} else {
79+
None
80+
}
81+
}
82+
None => None,
83+
});
84+
let result = DFFloat64Array::new_from_opt_iter(opt_iter);
85+
let column: DataColumn = result.into();
86+
Ok(column.resize_constant(columns[0].column().len()))
87+
}
88+
}
89+
90+
impl fmt::Display for SqrtFunction {
91+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
92+
write!(f, "SQRT")
93+
}
94+
}

0 commit comments

Comments
 (0)