Skip to content

Commit

Permalink
Merge branch 'main' into zhidong/refactor-full-key
Browse files Browse the repository at this point in the history
  • Loading branch information
Gun9niR authored Nov 11, 2022
2 parents 1c4e16c + 0b1f2bc commit 4af4a8d
Show file tree
Hide file tree
Showing 40 changed files with 1,399 additions and 763 deletions.
8 changes: 7 additions & 1 deletion e2e_test/batch/basic/func.slt.part
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@ select nullif(1,2);
----
1

query IIIII
select coalesce(1,2), coalesce(null,2), coalesce(null), coalesce(null,null), coalesce(null,2,3);
----
1 2 NULL NULL 2

query I
select coalesce(1,2);
select coalesce(1, 1 / (v1-v1)) from generate_series(1, 3, 1) as t(v1) where v1 != 2;
----
1
1

statement ok
create table t1 (v1 int, v2 int, v3 int);
Expand Down
77 changes: 9 additions & 68 deletions src/common/src/array/data_chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::fmt;
use std::hash::BuildHasher;
use std::sync::Arc;
use std::{fmt, iter};

use auto_enums::auto_enum;
use itertools::Itertools;
use risingwave_pb::data::DataChunk as ProstDataChunk;

use super::ArrayResult;
use super::{ArrayResult, Vis};
use crate::array::column::Column;
use crate::array::data_chunk_iter::{Row, RowRef};
use crate::array::{ArrayBuilderImpl, StructValue};
Expand All @@ -40,71 +39,6 @@ pub struct DataChunk {
vis2: Vis,
}

/// `Vis` is a visibility bitmap of rows. When all rows are visible, it is considered compact and
/// is represented by a single cardinality number rather than that many of ones.
#[derive(Clone, PartialEq, Debug)]
pub enum Vis {
Bitmap(Bitmap),
Compact(usize), // equivalent to all ones of this size
}

impl From<Bitmap> for Vis {
fn from(b: Bitmap) -> Self {
Vis::Bitmap(b)
}
}

impl From<usize> for Vis {
fn from(c: usize) -> Self {
Vis::Compact(c)
}
}

impl From<&Vis> for Vis {
fn from(vis: &Vis) -> Self {
match vis {
Vis::Bitmap(b) => b.clone().into(),
Vis::Compact(c) => (*c).into(),
}
}
}

impl Vis {
pub fn is_empty(&self) -> bool {
match self {
Vis::Bitmap(b) => b.is_empty(),
Vis::Compact(c) => *c == 0,
}
}

pub fn len(&self) -> usize {
match self {
Vis::Bitmap(b) => b.len(),
Vis::Compact(c) => *c,
}
}

/// # Panics
/// Panics if `idx > len`.
pub fn is_set(&self, idx: usize) -> bool {
match self {
Vis::Bitmap(b) => b.is_set(idx),
Vis::Compact(c) => {
assert!(idx <= *c);
true
}
}
}

#[auto_enum(Iterator)]
pub fn iter(&self) -> impl Iterator<Item = bool> + '_ {
match self {
Vis::Bitmap(b) => b.iter(),
Vis::Compact(c) => iter::repeat(true).take(*c),
}
}
}

impl DataChunk {
/// Create a `DataChunk` with `columns` and visibility. The visibility can either be a `Bitmap`
/// or a simple cardinality number.
Expand Down Expand Up @@ -206,6 +140,13 @@ impl DataChunk {
}
}

pub fn set_vis(&mut self, vis: Vis) {
for column in &self.columns {
assert_eq!(vis.len(), column.array_ref().len())
}
self.vis2 = vis;
}

pub fn set_visibility(&mut self, visibility: Bitmap) {
for column in &self.columns {
assert_eq!(visibility.len(), column.array_ref().len())
Expand Down
4 changes: 3 additions & 1 deletion src/common/src/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ mod stream_chunk_iter;
pub mod struct_array;
mod utf8_array;
mod value_reader;
mod vis;

use std::convert::From;
use std::hash::{Hash, Hasher};
Expand All @@ -43,7 +44,7 @@ pub use chrono_array::{
NaiveTimeArray, NaiveTimeArrayBuilder,
};
pub use column_proto_readers::*;
pub use data_chunk::{DataChunk, DataChunkTestExt, Vis};
pub use data_chunk::{DataChunk, DataChunkTestExt};
pub use data_chunk_iter::{Row, RowDeserializer, RowRef};
pub use decimal_array::{DecimalArray, DecimalArrayBuilder};
pub use interval_array::{IntervalArray, IntervalArrayBuilder};
Expand All @@ -55,6 +56,7 @@ use risingwave_pb::data::{Array as ProstArray, ArrayType as ProstArrayType};
pub use stream_chunk::{Op, StreamChunk, StreamChunkTestExt};
pub use struct_array::{StructArray, StructArrayBuilder, StructRef, StructValue};
pub use utf8_array::*;
pub use vis::{Vis, VisRef};

pub use self::error::ArrayError;
use crate::buffer::Bitmap;
Expand Down
Loading

0 comments on commit 4af4a8d

Please sign in to comment.