|
| 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 std::collections::BTreeMap; |
| 16 | + |
| 17 | +use chrono::DateTime; |
| 18 | +use chrono::Utc; |
| 19 | +use databend_common_expression::types::DataType; |
| 20 | +use databend_common_expression::types::NumberDataType; |
| 21 | +use databend_common_meta_app::principal::UDFDefinition; |
| 22 | +use databend_common_meta_app::principal::UDTFServer; |
| 23 | +use databend_common_meta_app::principal::UserDefinedFunction; |
| 24 | +use fastrace::func_name; |
| 25 | + |
| 26 | +use crate::common; |
| 27 | + |
| 28 | +// These bytes are built when a new version in introduced, |
| 29 | +// and are kept for backward compatibility test. |
| 30 | +// |
| 31 | +// ************************************************************* |
| 32 | +// * These messages should never be updated, * |
| 33 | +// * only be added when a new version is added, * |
| 34 | +// * or be removed when an old version is no longer supported. * |
| 35 | +// ************************************************************* |
| 36 | +// |
| 37 | +// The message bytes are built from the output of `test_pb_from_to()` |
| 38 | +#[test] |
| 39 | +fn test_decode_v158_server_udtf() -> anyhow::Result<()> { |
| 40 | + let bytes = vec![ |
| 41 | + 10, 15, 116, 101, 115, 116, 95, 115, 99, 97, 108, 97, 114, 95, 117, 100, 102, 18, 21, 84, |
| 42 | + 104, 105, 115, 32, 105, 115, 32, 97, 32, 100, 101, 115, 99, 114, 105, 112, 116, 105, 111, |
| 43 | + 110, 82, 144, 1, 10, 21, 104, 116, 116, 112, 58, 47, 47, 108, 111, 99, 97, 108, 104, 111, |
| 44 | + 115, 116, 58, 56, 56, 56, 56, 18, 11, 112, 108, 117, 115, 95, 105, 110, 116, 95, 112, 121, |
| 45 | + 26, 6, 112, 121, 116, 104, 111, 110, 34, 10, 146, 2, 0, 160, 6, 158, 1, 168, 6, 24, 34, 10, |
| 46 | + 138, 2, 0, 160, 6, 158, 1, 168, 6, 24, 42, 16, 10, 2, 99, 49, 18, 10, 146, 2, 0, 160, 6, |
| 47 | + 158, 1, 168, 6, 24, 42, 25, 10, 2, 99, 50, 18, 19, 154, 2, 9, 42, 0, 160, 6, 158, 1, 168, |
| 48 | + 6, 24, 160, 6, 158, 1, 168, 6, 24, 50, 14, 10, 4, 107, 101, 121, 49, 18, 6, 118, 97, 108, |
| 49 | + 117, 101, 49, 66, 2, 99, 49, 66, 2, 99, 50, 160, 6, 158, 1, 168, 6, 24, 42, 23, 50, 48, 50, |
| 50 | + 51, 45, 49, 50, 45, 49, 53, 32, 48, 49, 58, 50, 54, 58, 48, 57, 32, 85, 84, 67, 160, 6, |
| 51 | + 158, 1, 168, 6, 24, |
| 52 | + ]; |
| 53 | + |
| 54 | + let want = || UserDefinedFunction { |
| 55 | + name: "test_scalar_udf".to_string(), |
| 56 | + description: "This is a description".to_string(), |
| 57 | + definition: UDFDefinition::UDTFServer(UDTFServer { |
| 58 | + address: "http://localhost:8888".to_string(), |
| 59 | + handler: "plus_int_py".to_string(), |
| 60 | + headers: vec![("key1".to_string(), "value1".to_string())] |
| 61 | + .into_iter() |
| 62 | + .collect(), |
| 63 | + language: "python".to_string(), |
| 64 | + arg_names: vec![s("c1"), s("c2")], |
| 65 | + arg_types: vec![DataType::String, DataType::Boolean], |
| 66 | + return_types: vec![ |
| 67 | + (s("c1"), DataType::String), |
| 68 | + (s("c2"), DataType::Number(NumberDataType::Int8)), |
| 69 | + ], |
| 70 | + immutable: None, |
| 71 | + }), |
| 72 | + created_on: DateTime::<Utc>::from_timestamp(1702603569, 0).unwrap(), |
| 73 | + }; |
| 74 | + |
| 75 | + common::test_pb_from_to(func_name!(), want())?; |
| 76 | + common::test_load_old(func_name!(), bytes.as_slice(), 158, want()) |
| 77 | +} |
| 78 | + |
| 79 | +fn s(ss: impl ToString) -> String { |
| 80 | + ss.to_string() |
| 81 | +} |
0 commit comments