Skip to content

Commit c007fab

Browse files
authored
Fix the default_for_column logic (#11403)
1 parent 8d3135a commit c007fab

File tree

1 file changed

+22
-12
lines changed
  • crates/viewer/re_dataframe_ui/src/filters

1 file changed

+22
-12
lines changed

crates/viewer/re_dataframe_ui/src/filters/filter.rs

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use arrow::datatypes::{DataType, Field, FieldRef};
22
use datafusion::logical_expr::Expr;
33

44
use re_log_types::TimestampFormat;
5-
use re_types_core::{Component as _, FIELD_METADATA_KEY_COMPONENT_TYPE};
5+
use re_types_core::{Component as _, FIELD_METADATA_KEY_COMPONENT_TYPE, Loggable as _};
66
use re_ui::SyntaxHighlighting;
77
use re_ui::syntax_highlighting::SyntaxHighlightedBuilder;
88

@@ -75,22 +75,29 @@ pub enum TypedFilter {
7575
}
7676

7777
impl TypedFilter {
78-
pub fn default_for_column(field: &FieldRef) -> Option<Self> {
79-
match field.data_type() {
78+
pub fn default_for_column(column_field: &FieldRef) -> Option<Self> {
79+
match column_field.data_type() {
8080
DataType::List(inner_field) | DataType::ListView(inner_field) => {
8181
// Note: we do not support double-nested types
82-
Self::default_for_primitive_datatype(inner_field)
82+
Self::default_for_primitive_datatype(inner_field.data_type(), column_field)
8383
}
8484

8585
//TODO(ab): support other nested types
86-
_ => Self::default_for_primitive_datatype(field),
86+
_ => Self::default_for_primitive_datatype(column_field.data_type(), column_field),
8787
}
8888
}
8989

90-
fn default_for_primitive_datatype(field: &FieldRef) -> Option<Self> {
91-
let nullability = Nullability::from_field(field);
92-
93-
match field.data_type() {
90+
/// Create a [`Self`] instance based on the provided primitive datatype.
91+
///
92+
/// Note that `column_field`, as its name implies, is from the actual column, and its datatype
93+
/// may be nested (e.g., a list array). This is why `primitive_datatype` is provided as well.
94+
fn default_for_primitive_datatype(
95+
primitive_datatype: &DataType,
96+
column_field: &FieldRef,
97+
) -> Option<Self> {
98+
let nullability = Nullability::from_field(column_field);
99+
100+
match primitive_datatype {
94101
DataType::Boolean => {
95102
if nullability.is_either() {
96103
Some(NullableBooleanFilter::default().into())
@@ -99,9 +106,12 @@ impl TypedFilter {
99106
}
100107
}
101108

102-
DataType::Int64
103-
if field.metadata().get(FIELD_METADATA_KEY_COMPONENT_TYPE)
104-
== Some(&re_types::components::Timestamp::name().to_string()) =>
109+
data_type
110+
if data_type == &re_types::components::Timestamp::arrow_datatype()
111+
&& column_field
112+
.metadata()
113+
.get(FIELD_METADATA_KEY_COMPONENT_TYPE)
114+
== Some(&re_types::components::Timestamp::name().to_string()) =>
105115
{
106116
Some(TimestampFilter::default().into())
107117
}

0 commit comments

Comments
 (0)