|
| 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 chrono::DateTime; |
| 16 | +use chrono::Utc; |
| 17 | +use databend_common_expression::types::DataType; |
| 18 | +use databend_common_meta_app::principal::UDFDefinition; |
| 19 | +use databend_common_meta_app::principal::UserDefinedFunction; |
| 20 | +use databend_common_meta_app::principal::UDTF; |
| 21 | +use fastrace::func_name; |
| 22 | + |
| 23 | +use crate::common; |
| 24 | + |
| 25 | +// These bytes are built when a new version in introduced, |
| 26 | +// and are kept for backward compatibility test. |
| 27 | +// |
| 28 | +// ************************************************************* |
| 29 | +// * These messages should never be updated, * |
| 30 | +// * only be added when a new version is added, * |
| 31 | +// * or be removed when an old version is no longer supported. * |
| 32 | +// ************************************************************* |
| 33 | +// |
| 34 | +// The message bytes are built from the output of `test_pb_from_to()` |
| 35 | +#[test] |
| 36 | +fn test_decode_v143_udtf() -> anyhow::Result<()> { |
| 37 | + let bytes = vec![ |
| 38 | + 10, 9, 116, 101, 115, 116, 95, 117, 100, 116, 102, 18, 21, 84, 104, 105, 115, 32, 105, 115, |
| 39 | + 32, 97, 32, 100, 101, 115, 99, 114, 105, 112, 116, 105, 111, 110, 66, 79, 10, 16, 10, 2, |
| 40 | + 99, 49, 18, 10, 146, 2, 0, 160, 6, 143, 1, 168, 6, 24, 10, 16, 10, 2, 99, 50, 18, 10, 138, |
| 41 | + 2, 0, 160, 6, 143, 1, 168, 6, 24, 18, 16, 10, 2, 99, 51, 18, 10, 170, 2, 0, 160, 6, 143, 1, |
| 42 | + 168, 6, 24, 26, 16, 115, 101, 108, 101, 99, 116, 32, 42, 32, 102, 114, 111, 109, 32, 116, |
| 43 | + 49, 160, 6, 143, 1, 168, 6, 24, 42, 23, 50, 48, 50, 51, 45, 49, 50, 45, 49, 53, 32, 48, 49, |
| 44 | + 58, 50, 54, 58, 48, 57, 32, 85, 84, 67, 160, 6, 143, 1, 168, 6, 24, |
| 45 | + ]; |
| 46 | + |
| 47 | + let want = || UserDefinedFunction { |
| 48 | + name: "test_udtf".to_string(), |
| 49 | + description: "This is a description".to_string(), |
| 50 | + definition: UDFDefinition::UDTF(UDTF { |
| 51 | + arg_types: vec![(s("c1"), DataType::String), (s("c2"), DataType::Boolean)], |
| 52 | + return_types: vec![(s("c3"), DataType::Date)], |
| 53 | + sql: "select * from t1".to_string(), |
| 54 | + }), |
| 55 | + created_on: DateTime::<Utc>::from_timestamp(1702603569, 0).unwrap(), |
| 56 | + }; |
| 57 | + |
| 58 | + common::test_pb_from_to(func_name!(), want())?; |
| 59 | + common::test_load_old(func_name!(), bytes.as_slice(), 143, want()) |
| 60 | +} |
| 61 | + |
| 62 | +fn s(ss: impl ToString) -> String { |
| 63 | + ss.to_string() |
| 64 | +} |
0 commit comments