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

perf(expr): new interface for expression directly returning scalar #9049

Merged
merged 10 commits into from
Apr 11, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
use eval_new for literal
Signed-off-by: Bugen Zhao <i@bugenzhao.com>
  • Loading branch information
BugenZhao committed Apr 7, 2023
commit c3900ab39f37fba22ea244219854b1f3cf9ce204
41 changes: 9 additions & 32 deletions src/expr/src/expr/expr_literal.rs
Original file line number Diff line number Diff line change
@@ -13,16 +13,15 @@
// limitations under the License.

use std::convert::TryFrom;
use std::sync::Arc;

use risingwave_common::array::{ArrayBuilder, ArrayBuilderImpl, ArrayRef, DataChunk};
use risingwave_common::for_all_variants;
use risingwave_common::array::DataChunk;
use risingwave_common::row::OwnedRow;
use risingwave_common::types::{literal_type_match, DataType, Datum, Scalar, ScalarImpl};
use risingwave_common::types::{literal_type_match, DataType, Datum};
use risingwave_common::util::value_encoding::deserialize_datum;
use risingwave_pb::expr::expr_node::{RexNode, Type};
use risingwave_pb::expr::ExprNode;

use super::ValueImpl;
use crate::expr::Expression;
use crate::{bail, ensure, ExprError, Result};

@@ -39,33 +38,11 @@ impl Expression for LiteralExpression {
self.return_type.clone()
}

async fn eval(&self, input: &DataChunk) -> Result<ArrayRef> {
let mut array_builder = self.return_type.create_array_builder(input.capacity());
let capacity = input.capacity();
let builder = &mut array_builder;
let literal = &self.literal;

macro_rules! array_impl_literal_append {
($( { $variant_name:ident, $suffix_name:ident, $array:ty, $builder:ty } ),*) => {
match (builder, literal) {
$(
(ArrayBuilderImpl::$variant_name(inner), Some(ScalarImpl::$variant_name(v))) => {
inner.append_n(capacity, Some(v.as_scalar_ref()));
}
(ArrayBuilderImpl::$variant_name(inner), None) => {
inner.append_n(capacity, None);
}
)*
(_, _) => $crate::bail!(
"Do not support values in insert values executor".to_string()
),
}
};
}

for_all_variants! { array_impl_literal_append }

Ok(Arc::new(array_builder.finish()))
async fn eval_new(&self, input: &DataChunk) -> Result<ValueImpl> {
Ok(ValueImpl::Scalar {
value: self.literal.clone(),
capacity: input.capacity(),
})
}

async fn eval_row(&self, _input: &OwnedRow) -> Result<Datum> {
@@ -126,7 +103,7 @@ mod tests {
use risingwave_common::array::{I32Array, StructValue};
use risingwave_common::array_nonnull;
use risingwave_common::types::test_utils::IntervalTestExt;
use risingwave_common::types::{Decimal, Interval, IntoOrdered};
use risingwave_common::types::{Decimal, Interval, IntoOrdered, Scalar, ScalarImpl};
use risingwave_common::util::value_encoding::serialize_datum;
use risingwave_pb::data::data_type::{IntervalType, TypeName};
use risingwave_pb::data::{PbDataType, PbDatum};
12 changes: 0 additions & 12 deletions src/expr/src/expr/template.rs
Original file line number Diff line number Diff line change
@@ -28,18 +28,6 @@ use risingwave_common::util::iter_util::ZipEqDebug;

use crate::expr::{BoxedExpression, Expression, ValueImpl, ValueRef};

trait ArrayConversion
where
Self: Array,
{
}

impl<A> ArrayConversion for A where
A: Array /* for<'a> &'a A: std::convert::From<&'a ArrayImpl>,
* for<'a> ValueRef<'a, A>: std::convert::From<&'a ValueImpl>, */
{
}

macro_rules! gen_eval {
{ ($macro:ident, $macro_row:ident), $ty_name:ident, $OA:ty, $($arg:ident,)* } => {
fn eval_new<'a, 'b, 'async_trait>(&'a self, data_chunk: &'b DataChunk)