diff --git a/iox_query/src/provider.rs b/iox_query/src/provider.rs index e97eaa3d87..112e34b4f0 100644 --- a/iox_query/src/provider.rs +++ b/iox_query/src/provider.rs @@ -2006,6 +2006,7 @@ mod test { // request just the field and timestamp let schema = SchemaBuilder::new() .field("field_int", DataType::Int64) + .unwrap() .timestamp() .build() .unwrap(); @@ -2101,7 +2102,9 @@ mod test { // request just the fields let schema = SchemaBuilder::new() .field("field_int", DataType::Int64) + .unwrap() .field("other_field_int", DataType::Int64) + .unwrap() .build() .unwrap(); @@ -2416,6 +2419,7 @@ mod test { // request just the field and timestamp let schema = SchemaBuilder::new() .field("field_int", DataType::Int64) + .unwrap() .timestamp() .build() .unwrap(); diff --git a/iox_query/src/test.rs b/iox_query/src/test.rs index e7a0503f1c..497d932e41 100644 --- a/iox_query/src/test.rs +++ b/iox_query/src/test.rs @@ -267,6 +267,7 @@ macro_rules! impl_with_column { let new_column_schema = SchemaBuilder::new() .field(&column_name, DataType::$DATA_TYPE) + .unwrap() .build() .unwrap(); self.add_schema_to_table(new_column_schema, true, None) @@ -282,6 +283,7 @@ macro_rules! impl_with_column_no_stats { let new_column_schema = SchemaBuilder::new() .field(&column_name, DataType::$DATA_TYPE) + .unwrap() .build() .unwrap(); @@ -303,6 +305,7 @@ macro_rules! impl_with_column_with_stats { let new_column_schema = SchemaBuilder::new() .field(&column_name, DataType::$DATA_TYPE) + .unwrap() .build() .unwrap(); @@ -525,6 +528,7 @@ impl TestChunk { // merge it in to any existing schema let new_column_schema = SchemaBuilder::new() .field(&column_name, DataType::Utf8) + .unwrap() .build() .unwrap(); diff --git a/iox_query/src/util.rs b/iox_query/src/util.rs index d21dc824a8..f5e268814b 100644 --- a/iox_query/src/util.rs +++ b/iox_query/src/util.rs @@ -288,10 +288,15 @@ mod tests { let schema = SchemaBuilder::new() .tag("tag") .field("str", DataType::Utf8) + .unwrap() .field("int", DataType::Int64) + .unwrap() .field("uint", DataType::UInt64) + .unwrap() .field("float", DataType::Float64) + .unwrap() .field("bool", DataType::Boolean) + .unwrap() .build() .unwrap(); diff --git a/predicate/src/lib.rs b/predicate/src/lib.rs index 7f0b9782ac..476169bae2 100644 --- a/predicate/src/lib.rs +++ b/predicate/src/lib.rs @@ -789,7 +789,9 @@ mod tests { let schema = SchemaBuilder::new() .field("foo", ArrowDataType::Int64) + .unwrap() .field("bar", ArrowDataType::Int64) + .unwrap() .timestamp() .build() .unwrap(); @@ -896,6 +898,7 @@ mod tests { let schema = SchemaBuilder::new() .field("foo", ArrowDataType::Int64) + .unwrap() .timestamp() .build() .unwrap(); diff --git a/predicate/src/rpc_predicate.rs b/predicate/src/rpc_predicate.rs index 89fb1803c9..4b4257e799 100644 --- a/predicate/src/rpc_predicate.rs +++ b/predicate/src/rpc_predicate.rs @@ -454,7 +454,9 @@ mod tests { .tag("t1") .tag("t2") .field("f1", DataType::Int64) + .unwrap() .field("f2", DataType::Int64) + .unwrap() .build() .unwrap(); diff --git a/predicate/src/rpc_predicate/column_rewrite.rs b/predicate/src/rpc_predicate/column_rewrite.rs index a6c8d55f3f..cc925c5aae 100644 --- a/predicate/src/rpc_predicate/column_rewrite.rs +++ b/predicate/src/rpc_predicate/column_rewrite.rs @@ -91,6 +91,7 @@ mod tests { let schema = SchemaBuilder::new() .tag("t1") .field("f1", DataType::Int64) + .unwrap() .build() .unwrap(); diff --git a/predicate/src/rpc_predicate/field_rewrite.rs b/predicate/src/rpc_predicate/field_rewrite.rs index 8ccd354d19..af3baf2f87 100644 --- a/predicate/src/rpc_predicate/field_rewrite.rs +++ b/predicate/src/rpc_predicate/field_rewrite.rs @@ -505,9 +505,13 @@ mod tests { .tag("foo") .tag("bar") .field("f1", DataType::Float64) + .unwrap() .field("f2", DataType::Float64) + .unwrap() .field("f3", DataType::Float64) + .unwrap() .field("f4", DataType::Float64) + .unwrap() .build() .map(Arc::new) .unwrap() diff --git a/querier/src/cache/namespace.rs b/querier/src/cache/namespace.rs index d9b55cb05b..a01de4599b 100644 --- a/querier/src/cache/namespace.rs +++ b/querier/src/cache/namespace.rs @@ -327,6 +327,7 @@ mod tests { schema: Arc::new( SchemaBuilder::new() .field("col1", DataType::Int64) + .unwrap() .tag("col2") .timestamp() .build() @@ -346,6 +347,7 @@ mod tests { schema: Arc::new( SchemaBuilder::new() .field("col1", DataType::Float64) + .unwrap() .timestamp() .build() .unwrap(), diff --git a/querier/src/chunk/mod.rs b/querier/src/chunk/mod.rs index 03b9b8a3d7..bc053e1e1f 100644 --- a/querier/src/chunk/mod.rs +++ b/querier/src/chunk/mod.rs @@ -510,6 +510,7 @@ pub mod tests { fn assert_schema(chunk: &QuerierChunk) { let expected_schema = SchemaBuilder::new() .field("field_int", DataType::Int64) + .unwrap() .tag("tag1") .timestamp() .build() diff --git a/querier/src/ingester/mod.rs b/querier/src/ingester/mod.rs index bf959d0e14..e09e024cf5 100644 --- a/querier/src/ingester/mod.rs +++ b/querier/src/ingester/mod.rs @@ -1955,6 +1955,7 @@ mod tests { let expected_schema = Arc::new( SchemaBuilder::new() .field("b", DataType::Boolean) + .unwrap() .timestamp() .build() .unwrap(), diff --git a/query_tests/src/table_schema.rs b/query_tests/src/table_schema.rs index 359ba1ce49..2f8b438b2e 100644 --- a/query_tests/src/table_schema.rs +++ b/query_tests/src/table_schema.rs @@ -85,6 +85,7 @@ async fn list_schema_cpu_all() { .tag("region") .timestamp() .field("user", DataType::Float64) + .unwrap() .build() .unwrap(); @@ -107,6 +108,7 @@ async fn list_schema_cpu_all_set_sort_key() { .tag("region") .timestamp() .field("user", DataType::Float64) + .unwrap() .build() .unwrap(); @@ -127,6 +129,7 @@ async fn list_schema_disk_all() { // we expect columns to come out in lexicographic order by name let expected_schema = SchemaBuilder::new() .field("bytes", DataType::Int64) + .unwrap() .tag("region") .timestamp() .build() @@ -146,6 +149,7 @@ async fn list_schema_disk_all() { async fn list_schema_cpu_selection() { let expected_schema = SchemaBuilder::new() .field("user", DataType::Float64) + .unwrap() .tag("region") .build() .unwrap(); @@ -162,6 +166,7 @@ async fn list_schema_disk_selection() { let expected_schema = SchemaBuilder::new() .timestamp() .field("bytes", DataType::Int64) + .unwrap() .build() .unwrap(); @@ -176,6 +181,7 @@ async fn list_schema_location_all() { // we expect columns to come out in lexicographic order by name let expected_schema = SchemaBuilder::new() .field("count", DataType::UInt64) + .unwrap() .timestamp() .tag("town") .build() diff --git a/schema/src/builder.rs b/schema/src/builder.rs index 89cf0a402a..2e5a8aaf29 100644 --- a/schema/src/builder.rs +++ b/schema/src/builder.rs @@ -70,34 +70,34 @@ impl SchemaBuilder { pub fn influx_column(&mut self, column_name: &str, column_type: InfluxColumnType) -> &mut Self { match column_type { InfluxColumnType::Tag => self.tag(column_name), - InfluxColumnType::Field(influx_field_type) => { - self.field(column_name, influx_field_type.into()) - } + InfluxColumnType::Field(influx_field_type) => self + .field(column_name, influx_field_type.into()) + .expect("just converted this from a valid type"), InfluxColumnType::Timestamp => self.timestamp(), } } /// Add a new nullable field column with the specified Arrow datatype. - pub fn field(&mut self, column_name: &str, arrow_type: ArrowDataType) -> &mut Self { - let influxdb_column_type = arrow_type - .clone() - .try_into() - .map(InfluxColumnType::Field) - .ok(); + pub fn field( + &mut self, + column_name: &str, + arrow_type: ArrowDataType, + ) -> Result<&mut Self, &'static str> { + let influxdb_column_type = arrow_type.clone().try_into().map(InfluxColumnType::Field)?; - self.add_column(column_name, true, influxdb_column_type, arrow_type) + Ok(self.add_column(column_name, true, Some(influxdb_column_type), arrow_type)) } /// Add a new field column with the specified Arrow datatype that can not be /// null - pub fn non_null_field(&mut self, column_name: &str, arrow_type: ArrowDataType) -> &mut Self { - let influxdb_column_type = arrow_type - .clone() - .try_into() - .map(InfluxColumnType::Field) - .ok(); + pub fn non_null_field( + &mut self, + column_name: &str, + arrow_type: ArrowDataType, + ) -> Result<&mut Self, &'static str> { + let influxdb_column_type = arrow_type.clone().try_into().map(InfluxColumnType::Field)?; - self.add_column(column_name, false, influxdb_column_type, arrow_type) + Ok(self.add_column(column_name, false, Some(influxdb_column_type), arrow_type)) } /// Add the InfluxDB data model timestamp column @@ -241,8 +241,9 @@ mod test { fn test_builder_field() { let s = SchemaBuilder::new() .field("the_influx_field", ArrowDataType::Float64) - // can't represent with lp - .field("the_no_influx_field", ArrowDataType::Decimal128(10, 0)) + .unwrap() + .field("the_other_influx_field", ArrowDataType::Int64) + .unwrap() .build() .unwrap(); @@ -253,10 +254,10 @@ mod test { assert_eq!(influxdb_column_type, Some(Field(Float))); let (influxdb_column_type, field) = s.field(1); - assert_eq!(field.name(), "the_no_influx_field"); - assert_eq!(field.data_type(), &ArrowDataType::Decimal128(10, 0)); + assert_eq!(field.name(), "the_other_influx_field"); + assert_eq!(field.data_type(), &ArrowDataType::Int64); assert!(field.is_nullable()); - assert_eq!(influxdb_column_type, None); + assert_eq!(influxdb_column_type, Some(Field(Integer))); assert_eq!(s.len(), 2); } @@ -281,8 +282,9 @@ mod test { fn test_builder_non_field() { let s = SchemaBuilder::new() .non_null_field("the_influx_field", ArrowDataType::Float64) - // can't represent with lp - .non_null_field("the_no_influx_field", ArrowDataType::Decimal128(10, 0)) + .unwrap() + .non_null_field("the_other_influx_field", ArrowDataType::Int64) + .unwrap() .build() .unwrap(); @@ -293,10 +295,10 @@ mod test { assert_eq!(influxdb_column_type, Some(Field(Float))); let (influxdb_column_type, field) = s.field(1); - assert_eq!(field.name(), "the_no_influx_field"); - assert_eq!(field.data_type(), &ArrowDataType::Decimal128(10, 0)); + assert_eq!(field.name(), "the_other_influx_field"); + assert_eq!(field.data_type(), &ArrowDataType::Int64); assert!(!field.is_nullable()); - assert_eq!(influxdb_column_type, None); + assert_eq!(influxdb_column_type, Some(Field(Integer))); assert_eq!(s.len(), 2); } diff --git a/schema/src/lib.rs b/schema/src/lib.rs index 97a1a38541..739499090e 100644 --- a/schema/src/lib.rs +++ b/schema/src/lib.rs @@ -1026,8 +1026,11 @@ mod test { fn test_sort_fields_by_name_already_sorted() { let schema = SchemaBuilder::new() .field("field_a", ArrowDataType::Int64) + .unwrap() .field("field_b", ArrowDataType::Int64) + .unwrap() .field("field_c", ArrowDataType::Int64) + .unwrap() .build() .unwrap(); @@ -1044,8 +1047,11 @@ mod test { fn test_sort_fields_by_name() { let schema = SchemaBuilder::new() .field("field_b", ArrowDataType::Int64) + .unwrap() .field("field_a", ArrowDataType::Int64) + .unwrap() .field("field_c", ArrowDataType::Int64) + .unwrap() .build() .unwrap(); @@ -1053,8 +1059,11 @@ mod test { let expected_schema = SchemaBuilder::new() .field("field_a", ArrowDataType::Int64) + .unwrap() .field("field_b", ArrowDataType::Int64) + .unwrap() .field("field_c", ArrowDataType::Int64) + .unwrap() .build() .unwrap(); diff --git a/schema/src/merge.rs b/schema/src/merge.rs index a50e7290d2..9dafc1846b 100644 --- a/schema/src/merge.rs +++ b/schema/src/merge.rs @@ -418,16 +418,16 @@ mod tests { #[test] fn test_merge_incompatible_data_types() { // same field name with different type - let schema1 = SchemaBuilder::new() - .field("the_field", ArrowDataType::Int16) - .build() - .unwrap(); + let schema1 = Schema::try_from_arrow(Arc::new(arrow::datatypes::Schema::new(vec![ + arrow::datatypes::Field::new("the_field", ArrowDataType::Int16, true), + ]))) + .unwrap(); // same field name with different type - let schema2 = SchemaBuilder::new() - .field("the_field", ArrowDataType::Int8) - .build() - .unwrap(); + let schema2 = Schema::try_from_arrow(Arc::new(arrow::datatypes::Schema::new(vec![ + arrow::datatypes::Field::new("the_field", ArrowDataType::Int8, true), + ]))) + .unwrap(); let merged_schema_error = SchemaMerger::new() .merge(&schema1) @@ -461,12 +461,14 @@ mod tests { fn test_merge_incompatible_schema_nullability() { let schema1 = SchemaBuilder::new() .non_null_field("int_field", ArrowDataType::Int64) + .unwrap() .build() .unwrap(); // same field name with different nullability let schema2 = SchemaBuilder::new() .field("int_field", ArrowDataType::Int64) + .unwrap() .build() .unwrap(); diff --git a/service_grpc_influxrpc/src/expr.rs b/service_grpc_influxrpc/src/expr.rs index bb448bbd97..94dbde3429 100644 --- a/service_grpc_influxrpc/src/expr.rs +++ b/service_grpc_influxrpc/src/expr.rs @@ -908,7 +908,9 @@ mod tests { .tag("t2") .tag("host") .field("foo", DataType::Int64) + .unwrap() .field("bar", DataType::Int64) + .unwrap() .build() .unwrap(); @@ -918,6 +920,7 @@ mod tests { let schema = SchemaBuilder::new() .tag("t3") .field("baz", DataType::Int64) + .unwrap() .build() .unwrap();