forked from databendlabs/databend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathempty_array.rs
More file actions
172 lines (139 loc) · 4.48 KB
/
Copy pathempty_array.rs
File metadata and controls
172 lines (139 loc) · 4.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// Copyright 2021 Datafuse 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::ops::Range;
use crate::property::Domain;
use crate::types::ArgType;
use crate::types::DataType;
use crate::types::GenericMap;
use crate::types::ValueType;
use crate::values::Column;
use crate::values::Scalar;
use crate::ColumnBuilder;
use crate::ScalarRef;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct EmptyArrayType;
impl ValueType for EmptyArrayType {
type Scalar = ();
type ScalarRef<'a> = ();
type Column = usize;
type Domain = ();
type ColumnIterator<'a> = std::iter::Take<std::iter::Repeat<()>>;
type ColumnBuilder = usize;
#[inline]
fn upcast_gat<'short, 'long: 'short>(_: Self::ScalarRef<'long>) -> Self::ScalarRef<'short> {}
fn to_owned_scalar<'a>(scalar: Self::ScalarRef<'a>) -> Self::Scalar {
scalar
}
fn to_scalar_ref<'a>(scalar: &'a Self::Scalar) -> Self::ScalarRef<'a> {
*scalar
}
fn try_downcast_scalar<'a>(scalar: &'a ScalarRef) -> Option<Self::ScalarRef<'a>> {
match scalar {
ScalarRef::EmptyArray => Some(()),
_ => None,
}
}
fn try_downcast_column<'a>(col: &'a Column) -> Option<Self::Column> {
match col {
Column::EmptyArray { len } => Some(*len),
_ => None,
}
}
fn try_downcast_domain(domain: &Domain) -> Option<Self::Domain> {
match domain {
Domain::Array(None) => Some(()),
_ => None,
}
}
fn try_downcast_builder<'a>(
builder: &'a mut ColumnBuilder,
) -> Option<&'a mut Self::ColumnBuilder> {
match builder {
ColumnBuilder::EmptyArray { len } => Some(len),
_ => None,
}
}
fn upcast_scalar(_: Self::Scalar) -> Scalar {
Scalar::EmptyArray
}
fn upcast_column(len: Self::Column) -> Column {
Column::EmptyArray { len }
}
fn upcast_domain(_: Self::Domain) -> Domain {
Domain::Array(None)
}
fn column_len<'a>(len: &'a Self::Column) -> usize {
*len
}
fn index_column<'a>(len: &'a Self::Column, index: usize) -> Option<Self::ScalarRef<'a>> {
if index < *len { Some(()) } else { None }
}
unsafe fn index_column_unchecked<'a>(
_len: &'a Self::Column,
_index: usize,
) -> Self::ScalarRef<'a> {
}
fn slice_column<'a>(len: &'a Self::Column, range: Range<usize>) -> Self::Column {
assert!(range.end <= *len, "range {range:?} out of 0..{len}");
range.end - range.start
}
fn iter_column<'a>(len: &'a Self::Column) -> Self::ColumnIterator<'a> {
std::iter::repeat(()).take(*len)
}
fn column_to_builder(len: Self::Column) -> Self::ColumnBuilder {
len
}
fn builder_len(len: &Self::ColumnBuilder) -> usize {
*len
}
fn push_item(len: &mut Self::ColumnBuilder, _: Self::Scalar) {
*len += 1
}
fn push_default(len: &mut Self::ColumnBuilder) {
*len += 1
}
fn append_column(len: &mut Self::ColumnBuilder, other_len: &Self::Column) {
*len += other_len
}
fn build_column(len: Self::ColumnBuilder) -> Self::Column {
len
}
fn build_scalar(len: Self::ColumnBuilder) -> Self::Scalar {
assert_eq!(len, 1);
}
fn scalar_memory_size<'a>(_: &Self::ScalarRef<'a>) -> usize {
0
}
fn column_memory_size(_: &Self::Column) -> usize {
std::mem::size_of::<usize>()
}
}
impl ArgType for EmptyArrayType {
fn data_type() -> DataType {
DataType::EmptyArray
}
fn full_domain() -> Self::Domain {}
fn create_builder(_capacity: usize, _generics: &GenericMap) -> Self::ColumnBuilder {
0
}
fn column_from_iter(iter: impl Iterator<Item = Self::Scalar>, _: &GenericMap) -> Self::Column {
iter.count()
}
fn column_from_ref_iter<'a>(
iter: impl Iterator<Item = Self::ScalarRef<'a>>,
_: &GenericMap,
) -> Self::Column {
iter.count()
}
}