Skip to content

Commit

Permalink
feat(expr): add rw_epoch_to_ts (#19473)
Browse files Browse the repository at this point in the history
Signed-off-by: xxchan <[email protected]>
  • Loading branch information
xxchan authored Nov 21, 2024
1 parent ad1d929 commit 1eb4ce0
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions proto/expr.proto
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ message ExprNode {
HAS_SCHEMA_PRIVILEGE = 2409;
PG_IS_IN_RECOVERY = 2411;
RW_RECOVERY_STATUS = 2412;
RW_EPOCH_TO_TS = 2413;

// EXTERNAL
ICEBERG_TRANSFORM = 2201;
Expand Down
1 change: 1 addition & 0 deletions src/frontend/src/binder/expr/function/builtin_scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,7 @@ impl Binder {
("shobj_description", raw_literal(ExprImpl::literal_varchar("".to_string()))),
("pg_is_in_recovery", raw_call(ExprType::PgIsInRecovery)),
("rw_recovery_status", raw_call(ExprType::RwRecoveryStatus)),
("rw_epoch_to_ts", raw_call(ExprType::RwEpochToTs)),
// internal
("rw_vnode", raw_call(ExprType::VnodeUser)),
("rw_test_paid_tier", raw_call(ExprType::TestPaidTier)), // for testing purposes
Expand Down
1 change: 1 addition & 0 deletions src/frontend/src/expr/function_impl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ mod pg_get_viewdef;
mod pg_index_column_has_property;
mod pg_indexes_size;
mod pg_relation_size;
mod rw_epoch_to_ts;
mod rw_recovery_status;
22 changes: 22 additions & 0 deletions src/frontend/src/expr/function_impl/rw_epoch_to_ts.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2024 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 risingwave_common::types::Timestamptz;
use risingwave_common::util::epoch::Epoch;
use risingwave_expr::{function, Result};

#[function("rw_epoch_to_ts(int8) -> timestamptz")]
fn rw_epoch_to_ts(epoch: i64) -> Result<Timestamptz> {
Ok(Epoch(epoch as u64).as_timestamptz())
}
3 changes: 2 additions & 1 deletion src/frontend/src/expr/pure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,8 @@ impl ExprVisitor for ImpureAnalyzer {
| Type::MapDelete
| Type::MapInsert
| Type::MapLength
| Type::VnodeUser =>
| Type::VnodeUser
|Type::RwEpochToTs =>
// expression output is deterministic(same result for the same input)
{
func_call
Expand Down
3 changes: 2 additions & 1 deletion src/frontend/src/optimizer/plan_expr_visitor/strong.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,8 @@ impl Strong {
| ExprType::HasAnyColumnPrivilege
| ExprType::HasSchemaPrivilege
| ExprType::InetAton
| ExprType::InetNtoa => false,
| ExprType::InetNtoa
| ExprType::RwEpochToTs => false,
ExprType::Unspecified => unreachable!(),
}
}
Expand Down

0 comments on commit 1eb4ce0

Please sign in to comment.