forked from databendlabs/databend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmetadata.rs
More file actions
766 lines (672 loc) · 24.3 KB
/
Copy pathmetadata.rs
File metadata and controls
766 lines (672 loc) · 24.3 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
// 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::collections::BTreeSet;
use std::collections::HashMap;
use std::collections::VecDeque;
use std::collections::hash_map::Entry;
use std::fmt::Debug;
use std::fmt::Formatter;
use std::sync::Arc;
use databend_common_ast::ast::Expr;
use databend_common_ast::ast::Literal;
use databend_common_catalog::plan::DataSourcePlan;
use databend_common_catalog::plan::InternalColumn;
use databend_common_catalog::table::Table;
use databend_common_expression::ColumnId;
use databend_common_expression::ComputedExpr;
pub use databend_common_expression::Symbol;
use databend_common_expression::TableDataType;
use databend_common_expression::TableField;
use databend_common_expression::display::display_tuple_field_name;
use databend_common_expression::is_stream_column_id;
use databend_common_expression::types::DataType;
use jsonb::keypath::OwnedKeyPaths;
use parking_lot::RwLock;
use crate::optimizer::ir::SExpr;
/// Planner use [`usize`] as it's index type.
///
/// This type will be used across the whole planner.
pub type IndexType = usize;
/// Use IndexType::MAX to represent dummy table.
pub const DUMMY_TABLE_INDEX: IndexType = IndexType::MAX;
/// ColumnSet represents a set of columns identified by `Symbol`.
pub type ColumnSet = BTreeSet<Symbol>;
/// A Send & Send version of [`Metadata`].
///
/// Callers can clone this ref safely and cheaply.
pub type MetadataRef = Arc<RwLock<Metadata>>;
/// Metadata stores information about columns and tables used in a query.
/// Tables and columns are identified with its unique index.
/// Notice that index value of a column can be same with that of a table.
#[derive(Clone, Debug, Default)]
pub struct Metadata {
tables: Vec<TableEntry>,
columns: Vec<ColumnEntry>,
removed_mark_indexes: ColumnSet,
/// Table column indexes that are lazy materialized.
table_lazy_columns: HashMap<IndexType, ColumnSet>,
table_source: HashMap<IndexType, DataSourcePlan>,
retained_columns: ColumnSet,
/// Columns that are lazy materialized.
lazy_columns: ColumnSet,
/// Columns that are used for compute lazy materialized.
/// If outer query match the lazy materialized rule but inner query doesn't,
/// we need add cols that inner query required to non_lazy_columns
/// to prevent these cols to be pruned.
non_lazy_columns: ColumnSet,
/// Mappings from table index to _row_id column index.
table_row_id_index: HashMap<IndexType, Symbol>,
agg_indices: HashMap<String, Vec<(u64, String, SExpr)>>,
max_column_position: usize, // for CSV
has_column_name_ref: bool, // for schema inference from stage files
/// Scan id of each scan operator.
next_scan_id: usize,
/// Mappings from base column index to scan id.
base_column_scan_id: HashMap<Symbol, usize>,
next_runtime_filter_id: usize,
next_logical_recursive_cte_id: u32,
next_materialized_cte_id: usize,
}
impl Metadata {
pub fn default_ref() -> MetadataRef {
Arc::new(RwLock::new(Self::default()))
}
fn next_column_index(&self) -> Symbol {
Symbol::new(self.columns.len())
}
pub fn table(&self, index: IndexType) -> &TableEntry {
self.tables.get(index).expect("metadata must contain table")
}
pub fn tables(&self) -> &[TableEntry] {
self.tables.as_slice()
}
pub fn table_index_by_column_indexes(&self, column_indexes: &ColumnSet) -> Option<IndexType> {
self.columns.iter().find_map(|v| match v {
ColumnEntry::BaseTableColumn(BaseTableColumn {
column_index,
table_index,
..
}) if column_indexes.contains(column_index) => Some(*table_index),
_ => None,
})
}
pub fn get_table_index(
&self,
database_name: Option<&str>,
table_name: &str,
) -> Option<IndexType> {
// Use `rev` is because a table may be queried multiple times in join clause,
// and the virtual columns should add to the table newly added.
self.tables
.iter()
.rev()
.find(|table| match database_name {
Some(database_name) => {
table.database == database_name && table.name == table_name
|| table.alias_name == Some(table_name.to_string())
}
None => {
table.name == table_name || table.alias_name == Some(table_name.to_string())
}
})
.map(|table| table.index)
}
pub fn column(&self, index: Symbol) -> &ColumnEntry {
self.columns
.get(index.as_usize())
.expect("metadata must contain column")
}
pub fn columns(&self) -> &[ColumnEntry] {
self.columns.as_slice()
}
pub fn add_removed_mark_index(&mut self, index: Symbol) {
self.removed_mark_indexes.insert(index);
}
pub fn is_removed_mark_index(&self, index: Symbol) -> bool {
self.removed_mark_indexes.contains(&index)
}
pub fn add_retained_column(&mut self, index: Symbol) {
self.retained_columns.insert(index);
}
pub fn get_retained_column(&self) -> &ColumnSet {
&self.retained_columns
}
pub fn set_table_lazy_columns(&mut self, table_index: IndexType, lazy_columns: ColumnSet) {
self.table_lazy_columns.insert(table_index, lazy_columns);
}
pub fn get_table_lazy_columns(&self, table_index: &IndexType) -> Option<ColumnSet> {
self.table_lazy_columns.get(table_index).cloned()
}
pub fn set_table_source(&mut self, table_index: IndexType, source: DataSourcePlan) {
self.table_source.insert(table_index, source);
}
pub fn get_table_source(&self, table_index: &IndexType) -> Option<&DataSourcePlan> {
self.table_source.get(table_index)
}
pub fn is_lazy_column(&self, index: Symbol) -> bool {
self.lazy_columns.contains(&index)
}
pub fn add_lazy_columns(&mut self, indices: ColumnSet) {
if !self.lazy_columns.is_empty() {
// `lazy_columns` is only allowed to be set once.
return;
}
debug_assert!(indices.iter().all(|i| i.as_usize() < self.columns.len()));
self.lazy_columns.extend(indices);
}
pub fn clear_lazy_columns(&mut self) {
self.lazy_columns.clear();
}
pub fn add_non_lazy_columns(&mut self, indices: ColumnSet) {
debug_assert!(indices.iter().all(|i| i.as_usize() < self.columns.len()));
self.non_lazy_columns.extend(indices);
}
pub fn lazy_columns(&self) -> &ColumnSet {
&self.lazy_columns
}
pub fn non_lazy_columns(&self) -> &ColumnSet {
&self.non_lazy_columns
}
pub fn set_table_row_id_index(&mut self, table_index: IndexType, row_id_index: Symbol) {
self.table_row_id_index.insert(table_index, row_id_index);
}
pub fn row_id_index_by_table_index(&self, table_index: IndexType) -> Option<Symbol> {
self.table_row_id_index.get(&table_index).copied()
}
pub fn row_id_indexes(&self) -> Vec<Symbol> {
self.table_row_id_index.values().copied().collect()
}
pub fn allocate_logical_recursive_cte_id(&mut self) -> u32 {
let logical_recursive_cte_id = self.next_logical_recursive_cte_id;
self.next_logical_recursive_cte_id += 1;
logical_recursive_cte_id
}
pub fn allocate_materialized_cte_id(&mut self) -> usize {
let materialized_cte_id = self.next_materialized_cte_id;
self.next_materialized_cte_id += 1;
materialized_cte_id
}
pub fn columns_by_table_index(&self, index: IndexType) -> Vec<ColumnEntry> {
self.columns
.iter()
.filter(|column| match column {
ColumnEntry::BaseTableColumn(BaseTableColumn { table_index, .. }) => {
index == *table_index
}
ColumnEntry::InternalColumn(TableInternalColumn { table_index, .. }) => {
index == *table_index
}
ColumnEntry::VirtualColumn(VirtualColumn { table_index, .. }) => {
index == *table_index
}
_ => false,
})
.cloned()
.collect()
}
pub fn virtual_columns_by_table_index(&self, index: IndexType) -> Vec<ColumnEntry> {
self.columns
.iter()
.filter(|column| match column {
ColumnEntry::VirtualColumn(VirtualColumn { table_index, .. }) => {
index == *table_index
}
_ => false,
})
.cloned()
.collect()
}
#[allow(clippy::too_many_arguments)]
pub fn add_base_table_column(
&mut self,
name: String,
data_type: TableDataType,
table_index: IndexType,
path_indices: Option<Vec<IndexType>>,
column_id: ColumnId,
column_position: Option<usize>,
virtual_expr: Option<String>,
) -> Symbol {
let column_index = self.next_column_index();
let column_entry = ColumnEntry::BaseTableColumn(BaseTableColumn {
column_name: name,
column_position,
data_type,
column_index,
table_index,
path_indices,
column_id,
virtual_expr,
});
self.columns.push(column_entry);
column_index
}
pub fn add_derived_column(&mut self, alias: String, data_type: DataType) -> Symbol {
let column_index = self.next_column_index();
let column_entry = ColumnEntry::DerivedColumn(DerivedColumn {
column_index,
alias,
data_type,
});
self.columns.push(column_entry);
column_index
}
pub fn add_internal_column(
&mut self,
table_index: IndexType,
internal_column: InternalColumn,
) -> Symbol {
let column_index = self.next_column_index();
self.columns
.push(ColumnEntry::InternalColumn(TableInternalColumn {
table_index,
column_index,
internal_column,
}));
column_index
}
pub fn add_virtual_column(
&mut self,
table_index: IndexType,
source_column_name: String,
source_column_id: u32,
column_id: u32,
column_name: String,
key_paths: OwnedKeyPaths,
data_type: TableDataType,
is_try: bool,
) -> Symbol {
let column_index = self.next_column_index();
let column = ColumnEntry::VirtualColumn(VirtualColumn {
table_index,
source_column_name,
source_column_id,
column_id,
column_index,
column_name,
key_paths,
data_type,
is_try,
});
self.columns.push(column);
column_index
}
pub fn add_agg_indices(&mut self, table: String, agg_indices: Vec<(u64, String, SExpr)>) {
match self.agg_indices.entry(table) {
Entry::Occupied(occupied) => occupied.into_mut().extend(agg_indices),
Entry::Vacant(vacant) => {
vacant.insert(agg_indices);
}
}
}
pub fn agg_indices(&self) -> &HashMap<String, Vec<(u64, String, SExpr)>> {
&self.agg_indices
}
pub fn replace_agg_indices(&mut self, agg_indices: HashMap<String, Vec<(u64, String, SExpr)>>) {
self.agg_indices = agg_indices
}
pub fn get_agg_indices(&self, table: &str) -> Option<&[(u64, String, SExpr)]> {
self.agg_indices.get(table).map(|v| v.as_slice())
}
pub fn has_agg_indices(&self) -> bool {
!self.agg_indices.is_empty()
}
fn remove_cte_suffix(mut table_name: String, cte_suffix_name: Option<String>) -> String {
if let Some(suffix) = cte_suffix_name {
if table_name.ends_with(&suffix) {
table_name.truncate(table_name.len() - suffix.len() - 1);
}
}
table_name
}
#[allow(clippy::too_many_arguments)]
pub fn add_table(
&mut self,
catalog: String,
database: String,
table_meta: Arc<dyn Table>,
branch: Option<String>,
table_alias_name: Option<String>,
source_of_view: bool,
source_of_index: bool,
source_of_stage: bool,
cte_suffix_name: Option<String>,
) -> IndexType {
let table_name = table_meta.name().to_string();
let table_name = Self::remove_cte_suffix(table_name, cte_suffix_name);
let table_index = self.tables.len();
// If exists table alias name, use it instead of origin name
let table_entry = TableEntry {
index: table_index,
name: table_name,
database,
catalog,
table: table_meta.clone(),
branch,
alias_name: table_alias_name,
source_of_view,
source_of_index,
source_of_stage,
};
self.tables.push(table_entry);
let table_schema = table_meta.schema_with_stream();
let mut index = 0;
let mut fields = VecDeque::with_capacity(table_schema.fields().len());
for field in table_schema.fields().iter() {
if let Some(ComputedExpr::Virtual(_)) = field.computed_expr() {
fields.push_back((vec![], field.clone()));
} else {
fields.push_back((vec![index], field.clone()));
index += 1;
}
}
while let Some((indices, field)) = fields.pop_front() {
if indices.is_empty() {
self.add_base_table_column(
field.name().clone(),
field.data_type().clone(),
table_index,
None,
field.column_id,
None,
Some(field.computed_expr().unwrap().expr().clone()),
);
continue;
}
let path_indices = if indices.len() > 1 {
Some(indices.clone())
} else {
None
};
if let TableDataType::Tuple {
fields_name,
fields_type,
} = field.data_type().remove_nullable()
{
self.add_base_table_column(
field.name().clone(),
field.data_type().clone(),
table_index,
path_indices,
field.column_id,
None,
None,
);
let mut inner_column_id = field.column_id;
for (index, (inner_field_name, inner_field_type)) in
fields_name.iter().zip(fields_type.iter()).enumerate()
{
let mut inner_indices = indices.clone();
inner_indices.push(index);
// create tuple inner field
let inner_name = format!(
"{}:{}",
field.name(),
display_tuple_field_name(inner_field_name)
);
let inner_field = TableField::new_from_column_id(
&inner_name,
inner_field_type.clone(),
inner_column_id,
);
inner_column_id += inner_field_type.num_leaf_columns() as u32;
fields.push_front((inner_indices, inner_field));
}
} else {
self.add_base_table_column(
field.name().clone(),
field.data_type().clone(),
table_index,
path_indices,
field.column_id,
Some(indices[0] + 1),
None,
);
}
}
table_index
}
pub fn change_derived_column_alias(&mut self, index: Symbol, alias: String) {
let derived_column = self
.columns
.get_mut(index.as_usize())
.expect("metadata must contain column");
if let ColumnEntry::DerivedColumn(column) = derived_column {
column.alias = alias;
}
}
pub fn set_stage_column_references(&mut self, max_pos: usize, has_name_ref: bool) {
self.max_column_position = max_pos;
self.has_column_name_ref = has_name_ref;
}
pub fn get_max_column_position(&self) -> usize {
self.max_column_position
}
pub fn has_column_name_ref(&self) -> bool {
self.has_column_name_ref
}
pub fn next_scan_id(&mut self) -> usize {
let next_scan_id = self.next_scan_id;
self.next_scan_id += 1;
next_scan_id
}
pub fn next_runtime_filter_id(&mut self) -> usize {
let next_runtime_filter_id = self.next_runtime_filter_id;
self.next_runtime_filter_id += 1;
next_runtime_filter_id
}
pub fn add_base_column_scan_id(&mut self, base_column_scan_id: HashMap<Symbol, usize>) {
self.base_column_scan_id.extend(base_column_scan_id);
}
pub fn base_column_scan_id(&self, column_index: Symbol) -> Option<usize> {
self.base_column_scan_id.get(&column_index).cloned()
}
pub fn replace_all_tables(&mut self, table: Arc<dyn Table>) {
for entry in self.tables.iter_mut() {
entry.table = table.clone();
}
}
}
#[derive(Clone)]
pub struct TableEntry {
catalog: String,
database: String,
name: String,
branch: Option<String>,
alias_name: Option<String>,
index: IndexType,
source_of_view: bool,
/// If this table is bound to an index.
source_of_index: bool,
source_of_stage: bool,
table: Arc<dyn Table>,
}
impl Debug for TableEntry {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
f.debug_struct("TableEntry")
.field("catalog", &self.catalog)
.field("database", &self.database)
.field("name", &self.name)
.field("index", &self.index)
.finish_non_exhaustive()
}
}
impl TableEntry {
/// Get the catalog name of this table entry.
pub fn catalog(&self) -> &str {
&self.catalog
}
/// Get the database name of this table entry.
pub fn database(&self) -> &str {
&self.database
}
/// Get the name of this table entry.
pub fn name(&self) -> &str {
&self.name
}
pub fn branch(&self) -> &Option<String> {
&self.branch
}
/// Get the alias name of this table entry.
pub fn alias_name(&self) -> &Option<String> {
&self.alias_name
}
/// Get the index this table entry.
pub fn index(&self) -> IndexType {
self.index
}
/// Get the table of this table entry.
pub fn table(&self) -> Arc<dyn Table> {
self.table.clone()
}
/// Return true if it is source from view.
pub fn is_source_of_view(&self) -> bool {
self.source_of_view
}
/// Return true if it is source from stage.
pub fn is_source_of_stage(&self) -> bool {
self.source_of_stage
}
/// Return true if it is bound for an index.
pub fn is_source_of_index(&self) -> bool {
self.source_of_index
}
pub fn update_table_index(&mut self, table_index: IndexType) {
self.index = table_index;
}
pub fn qualified_name(&self) -> String {
match &self.branch {
None => format!("{}.{}.{}", self.catalog, self.database, self.name),
Some(branch) => format!(
"{}.{}.{}/{}",
self.catalog, self.database, self.name, branch
),
}
}
}
#[derive(Clone, Debug)]
pub struct BaseTableColumn {
pub table_index: IndexType,
pub column_index: Symbol,
pub column_name: String,
// column_position inside table schema
pub column_position: Option<usize>,
pub data_type: TableDataType,
/// Path indices for inner column of struct data type.
pub path_indices: Option<Vec<usize>>,
/// The column id in table schema.
pub column_id: ColumnId,
/// Virtual computed expression, generated in query.
pub virtual_expr: Option<String>,
}
#[derive(Clone, Debug)]
pub struct DerivedColumn {
pub column_index: Symbol,
pub alias: String,
pub data_type: DataType,
}
#[derive(Clone, Debug)]
pub struct TableInternalColumn {
pub table_index: IndexType,
pub column_index: Symbol,
pub internal_column: InternalColumn,
}
#[derive(Clone, Debug)]
pub struct VirtualColumn {
pub table_index: IndexType,
pub source_column_name: String,
pub source_column_id: u32,
pub column_id: u32,
pub column_index: Symbol,
pub column_name: String,
pub key_paths: OwnedKeyPaths,
pub data_type: TableDataType,
/// try cast to target type or not
pub is_try: bool,
}
#[allow(clippy::large_enum_variant)]
#[derive(Clone, Debug)]
pub enum ColumnEntry {
/// Column from base table, for example `SELECT t.a, t.b FROM t`.
BaseTableColumn(BaseTableColumn),
/// Column synthesized from other columns, for example `SELECT t.a + t.b AS a FROM t`.
DerivedColumn(DerivedColumn),
/// Internal columns, such as `_row_id`, `_segment_name`, etc.
InternalColumn(TableInternalColumn),
/// Virtual column generated from source column by paths, such as `a.b.c`, `a[1][2]`, etc.
VirtualColumn(VirtualColumn),
}
impl ColumnEntry {
pub fn index(&self) -> Symbol {
match self {
ColumnEntry::BaseTableColumn(base) => base.column_index,
ColumnEntry::DerivedColumn(derived) => derived.column_index,
ColumnEntry::InternalColumn(internal) => internal.column_index,
ColumnEntry::VirtualColumn(virtual_column) => virtual_column.column_index,
}
}
pub fn data_type(&self) -> DataType {
match self {
ColumnEntry::BaseTableColumn(BaseTableColumn { data_type, .. }) => {
DataType::from(data_type)
}
ColumnEntry::DerivedColumn(DerivedColumn { data_type, .. }) => data_type.clone(),
ColumnEntry::InternalColumn(TableInternalColumn {
internal_column, ..
}) => internal_column.data_type(),
ColumnEntry::VirtualColumn(VirtualColumn { data_type, .. }) => {
DataType::from(data_type)
}
}
}
pub fn name(&self) -> String {
match self {
ColumnEntry::BaseTableColumn(BaseTableColumn { column_name, .. }) => {
column_name.to_string()
}
ColumnEntry::DerivedColumn(DerivedColumn { alias, .. }) => alias.to_string(),
ColumnEntry::InternalColumn(TableInternalColumn {
internal_column, ..
}) => internal_column.column_name.clone(),
ColumnEntry::VirtualColumn(VirtualColumn { column_name, .. }) => {
column_name.to_string()
}
}
}
pub fn table_index(&self) -> Option<IndexType> {
match self {
ColumnEntry::BaseTableColumn(BaseTableColumn { table_index, .. }) => Some(*table_index),
ColumnEntry::DerivedColumn(_) => None,
ColumnEntry::InternalColumn(TableInternalColumn { table_index, .. }) => {
Some(*table_index)
}
ColumnEntry::VirtualColumn(VirtualColumn { table_index, .. }) => Some(*table_index),
}
}
pub fn is_stream_column(&self) -> bool {
if let ColumnEntry::BaseTableColumn(BaseTableColumn { column_id, .. }) = self {
if is_stream_column_id(*column_id) {
return true;
}
}
false
}
}
pub fn optimize_remove_count_args(name: &str, distinct: bool, args: &[&Expr]) -> bool {
name.eq_ignore_ascii_case("count")
&& !distinct
&& args
.iter()
.all(|expr| matches!(expr, Expr::Literal { value,.. } if *value != Literal::Null))
}