-
Notifications
You must be signed in to change notification settings - Fork 599
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(expr): add
pg_sleep
function (#12294)
Signed-off-by: Runji Wang <[email protected]>
- Loading branch information
1 parent
6c90f0b
commit 639acc2
Showing
10 changed files
with
110 additions
and
14 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,52 @@ | ||
// Copyright 2023 RisingWave 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::time::Duration; | ||
|
||
use risingwave_common::types::{Interval, F64}; | ||
use risingwave_expr_macro::function; | ||
|
||
/// Makes the current session's process sleep until the given number of seconds have elapsed. | ||
/// | ||
/// ```slt | ||
/// query I | ||
/// SELECT pg_sleep(1.5); | ||
/// ---- | ||
/// NULL | ||
/// ``` | ||
#[function("pg_sleep(float64)", volatile)] | ||
async fn pg_sleep(second: F64) { | ||
tokio::time::sleep(Duration::from_secs_f64(second.0)).await; | ||
} | ||
|
||
/// Makes the current session's process sleep until the given interval has elapsed. | ||
/// | ||
/// ```slt | ||
/// query I | ||
/// SELECT pg_sleep_for('1 second'); | ||
/// ---- | ||
/// NULL | ||
/// ``` | ||
#[function("pg_sleep_for(interval)", volatile)] | ||
async fn pg_sleep_for(interval: Interval) { | ||
// we only use the microsecond part of the interval | ||
let usecs = if interval.is_positive() { | ||
interval.usecs() as u64 | ||
} else { | ||
// return if the interval is not positive | ||
return; | ||
}; | ||
let duration = Duration::from_micros(usecs); | ||
tokio::time::sleep(duration).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
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