|
| 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::ScalarUDF; |
| 19 | +use databend_common_meta_app::principal::UDFDefinition; |
| 20 | +use databend_common_meta_app::principal::UserDefinedFunction; |
| 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_v144_scalar_udf() -> anyhow::Result<()> { |
| 37 | + let bytes = vec![ |
| 38 | + 10, 15, 116, 101, 115, 116, 95, 115, 99, 97, 108, 97, 114, 95, 117, 100, 102, 18, 21, 84, |
| 39 | + 104, 105, 115, 32, 105, 115, 32, 97, 32, 100, 101, 115, 99, 114, 105, 112, 116, 105, 111, |
| 40 | + 110, 74, 69, 10, 16, 10, 2, 99, 49, 18, 10, 146, 2, 0, 160, 6, 144, 1, 168, 6, 24, 10, 16, |
| 41 | + 10, 2, 99, 50, 18, 10, 138, 2, 0, 160, 6, 144, 1, 168, 6, 24, 18, 10, 170, 2, 0, 160, 6, |
| 42 | + 144, 1, 168, 6, 24, 26, 12, 67, 85, 82, 82, 69, 78, 84, 95, 68, 65, 84, 69, 160, 6, 144, 1, |
| 43 | + 168, 6, 24, 42, 23, 50, 48, 50, 51, 45, 49, 50, 45, 49, 53, 32, 48, 49, 58, 50, 54, 58, 48, |
| 44 | + 57, 32, 85, 84, 67, 160, 6, 144, 1, 168, 6, 24, |
| 45 | + ]; |
| 46 | + |
| 47 | + let want = || UserDefinedFunction { |
| 48 | + name: "test_scalar_udf".to_string(), |
| 49 | + description: "This is a description".to_string(), |
| 50 | + definition: UDFDefinition::ScalarUDF(ScalarUDF { |
| 51 | + arg_types: vec![(s("c1"), DataType::String), (s("c2"), DataType::Boolean)], |
| 52 | + return_type: DataType::Date, |
| 53 | + definition: "CURRENT_DATE".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(), 144, want()) |
| 60 | +} |
| 61 | + |
| 62 | +fn s(ss: impl ToString) -> String { |
| 63 | + ss.to_string() |
| 64 | +} |
0 commit comments