|
| 1 | +// Copyright 2023 Datafuse Labs. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +use common_expression::types::decimal::DecimalSize; |
| 16 | +use common_expression::types::DecimalDataType; |
| 17 | +use common_expression::types::NumberDataType; |
| 18 | +use common_expression::TableDataType; |
| 19 | +use common_expression::TableField; |
| 20 | +use common_expression::TableSchema; |
| 21 | + |
| 22 | +use crate::common; |
| 23 | + |
| 24 | +// These bytes are built when a new version in introduced, |
| 25 | +// and are kept for backward compatibility test. |
| 26 | +// |
| 27 | +// ************************************************************* |
| 28 | +// * These messages should never be updated, * |
| 29 | +// * only be added when a new version is added, * |
| 30 | +// * or be removed when an old version is no longer supported. * |
| 31 | +// ************************************************************* |
| 32 | +// |
| 33 | +// The message bytes are built from the output of `test_build_pb_buf()` |
| 34 | +#[test] |
| 35 | +fn test_decode_v27_schema() -> anyhow::Result<()> { |
| 36 | + let schema_v27 = [ |
| 37 | + 10, 28, 10, 1, 97, 26, 17, 154, 2, 8, 34, 0, 160, 6, 27, 168, 6, 24, 160, 6, 27, 168, 6, |
| 38 | + 24, 160, 6, 27, 168, 6, 24, 10, 104, 10, 1, 98, 26, 91, 202, 2, 82, 10, 2, 98, 49, 10, 2, |
| 39 | + 98, 50, 18, 47, 202, 2, 38, 10, 3, 98, 49, 49, 10, 3, 98, 49, 50, 18, 9, 138, 2, 0, 160, 6, |
| 40 | + 27, 168, 6, 24, 18, 9, 146, 2, 0, 160, 6, 27, 168, 6, 24, 160, 6, 27, 168, 6, 24, 160, 6, |
| 41 | + 27, 168, 6, 24, 18, 17, 154, 2, 8, 66, 0, 160, 6, 27, 168, 6, 24, 160, 6, 27, 168, 6, 24, |
| 42 | + 160, 6, 27, 168, 6, 24, 160, 6, 27, 168, 6, 24, 32, 1, 160, 6, 27, 168, 6, 24, 10, 30, 10, |
| 43 | + 1, 99, 26, 17, 154, 2, 8, 34, 0, 160, 6, 27, 168, 6, 24, 160, 6, 27, 168, 6, 24, 32, 4, |
| 44 | + 160, 6, 27, 168, 6, 24, 10, 49, 10, 10, 100, 101, 99, 105, 109, 97, 108, 49, 50, 56, 26, |
| 45 | + 27, 218, 2, 18, 10, 10, 8, 18, 16, 3, 160, 6, 27, 168, 6, 24, 160, 6, 27, 168, 6, 24, 160, |
| 46 | + 6, 27, 168, 6, 24, 32, 5, 160, 6, 27, 168, 6, 24, 10, 49, 10, 10, 100, 101, 99, 105, 109, |
| 47 | + 97, 108, 50, 53, 54, 26, 27, 218, 2, 18, 18, 10, 8, 46, 16, 6, 160, 6, 27, 168, 6, 24, 160, |
| 48 | + 6, 27, 168, 6, 24, 160, 6, 27, 168, 6, 24, 32, 6, 160, 6, 27, 168, 6, 24, 24, 7, 160, 6, |
| 49 | + 27, 168, 6, 24, |
| 50 | + ]; |
| 51 | + |
| 52 | + let b1 = TableDataType::Tuple { |
| 53 | + fields_name: vec!["b11".to_string(), "b12".to_string()], |
| 54 | + fields_type: vec![TableDataType::Boolean, TableDataType::String], |
| 55 | + }; |
| 56 | + let b = TableDataType::Tuple { |
| 57 | + fields_name: vec!["b1".to_string(), "b2".to_string()], |
| 58 | + fields_type: vec![b1, TableDataType::Number(NumberDataType::Int64)], |
| 59 | + }; |
| 60 | + let fields = vec![ |
| 61 | + TableField::new("a", TableDataType::Number(NumberDataType::UInt64)), |
| 62 | + TableField::new("b", b), |
| 63 | + TableField::new("c", TableDataType::Number(NumberDataType::UInt64)), |
| 64 | + TableField::new( |
| 65 | + "decimal128", |
| 66 | + TableDataType::Decimal(DecimalDataType::Decimal128(DecimalSize { |
| 67 | + precision: 18, |
| 68 | + scale: 3, |
| 69 | + })), |
| 70 | + ), |
| 71 | + TableField::new( |
| 72 | + "decimal256", |
| 73 | + TableDataType::Decimal(DecimalDataType::Decimal256(DecimalSize { |
| 74 | + precision: 46, |
| 75 | + scale: 6, |
| 76 | + })), |
| 77 | + ), |
| 78 | + ]; |
| 79 | + let want = || TableSchema::new(fields.clone()); |
| 80 | + common::test_load_old(func_name!(), schema_v27.as_slice(), 27, want())?; |
| 81 | + common::test_pb_from_to(func_name!(), want())?; |
| 82 | + Ok(()) |
| 83 | +} |
0 commit comments