|
| 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_expression::types::NumberDataType; |
| 19 | +use databend_common_meta_app::principal::UDFDefinition; |
| 20 | +use databend_common_meta_app::principal::UDFScript; |
| 21 | +use databend_common_meta_app::principal::UserDefinedFunction; |
| 22 | +use fastrace::func_name; |
| 23 | + |
| 24 | +use crate::common; |
| 25 | + |
| 26 | +// These bytes are built when a new version in introduced, |
| 27 | +// and are kept for backward compatibility test. |
| 28 | +// |
| 29 | +// ************************************************************* |
| 30 | +// * These messages should never be updated, * |
| 31 | +// * only be added when a new version is added, * |
| 32 | +// * or be removed when an old version is no longer supported. * |
| 33 | +// ************************************************************* |
| 34 | +// |
| 35 | +// The message bytes are built from the output of `test_pb_from_to()` |
| 36 | +#[test] |
| 37 | +fn test_decode_v130_udf_script() -> anyhow::Result<()> { |
| 38 | + let bytes = vec![ |
| 39 | + 10, 5, 109, 121, 95, 102, 110, 18, 21, 84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 100, |
| 40 | + 101, 115, 99, 114, 105, 112, 116, 105, 111, 110, 50, 119, 10, 9, 115, 111, 109, 101, 32, |
| 41 | + 99, 111, 100, 101, 18, 5, 109, 121, 95, 102, 110, 26, 6, 112, 121, 116, 104, 111, 110, 34, |
| 42 | + 19, 154, 2, 9, 58, 0, 160, 6, 130, 1, 168, 6, 24, 160, 6, 130, 1, 168, 6, 24, 42, 19, 154, |
| 43 | + 2, 9, 74, 0, 160, 6, 130, 1, 168, 6, 24, 160, 6, 130, 1, 168, 6, 24, 50, 6, 51, 46, 49, 50, |
| 44 | + 46, 50, 58, 9, 64, 115, 49, 47, 97, 46, 122, 105, 112, 58, 8, 64, 115, 50, 47, 98, 46, 112, |
| 45 | + 121, 66, 5, 110, 117, 109, 112, 121, 66, 6, 112, 97, 110, 100, 97, 115, 160, 6, 130, 1, |
| 46 | + 168, 6, 24, 42, 23, 49, 57, 55, 48, 45, 48, 49, 45, 48, 49, 32, 48, 48, 58, 48, 48, 58, 48, |
| 47 | + 48, 32, 85, 84, 67, 160, 6, 130, 1, 168, 6, 24, |
| 48 | + ]; |
| 49 | + |
| 50 | + let want = || UserDefinedFunction { |
| 51 | + name: "my_fn".to_string(), |
| 52 | + description: "This is a description".to_string(), |
| 53 | + definition: UDFDefinition::UDFScript(UDFScript { |
| 54 | + code: "some code".to_string(), |
| 55 | + handler: "my_fn".to_string(), |
| 56 | + language: "python".to_string(), |
| 57 | + arg_types: vec![DataType::Number(NumberDataType::Int32)], |
| 58 | + return_type: DataType::Number(NumberDataType::Float32), |
| 59 | + imports: vec!["@s1/a.zip".to_string(), "@s2/b.py".to_string()], |
| 60 | + packages: vec!["numpy".to_string(), "pandas".to_string()], |
| 61 | + runtime_version: "3.12.2".to_string(), |
| 62 | + }), |
| 63 | + created_on: DateTime::<Utc>::default(), |
| 64 | + }; |
| 65 | + |
| 66 | + common::test_pb_from_to(func_name!(), want())?; |
| 67 | + common::test_load_old(func_name!(), bytes.as_slice(), 130, want()) |
| 68 | +} |
0 commit comments