Coverage Report

Created: 2026-11-05 14:36

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exprs/function/ai/ai_functions.h
Line
Count
Source
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
#pragma once
19
20
#include <gen_cpp/FrontendService.h>
21
#include <gen_cpp/PaloInternalService_types.h>
22
#include <glog/logging.h>
23
24
#include <algorithm>
25
#include <cstdlib>
26
#include <memory>
27
#include <string>
28
#include <type_traits>
29
#include <utility>
30
#include <vector>
31
32
#include "common/config.h"
33
#include "common/status.h"
34
#include "core/column/column_array.h"
35
#include "core/column/column_const.h"
36
#include "core/column/column_nullable.h"
37
#include "core/cow.h"
38
#include "core/data_type/data_type_array.h"
39
#include "core/data_type/data_type_nullable.h"
40
#include "core/data_type/data_type_number.h"
41
#include "core/data_type/define_primitive_type.h"
42
#include "core/data_type/primitive_type.h"
43
#include "exec/common/util.hpp"
44
#include "exprs/function/ai/ai_adapter.h"
45
#include "exprs/function/ai/ai_request_executor.h"
46
#include "exprs/function/function.h"
47
#include "runtime/query_context.h"
48
#include "runtime/runtime_state.h"
49
#include "util/defer_op.h"
50
#include "util/string_util.h"
51
#include "util/threadpool.h"
52
#include "util/time.h"
53
54
namespace doris {
55
56
// Base class for AI-based functions
57
template <typename Derived>
58
class AIFunction : public IFunction {
59
public:
60
182
    static const char* batch_system_prompt(bool structured_batch) {
61
        // Cache both complete prompts per function. Requests only select an immutable string;
62
        // changing task wording does not depend on finding/replacing an exact sentence.
63
182
        static const std::string structured_prompt =
64
182
                std::string(Derived::system_prompt) +
65
182
                " Return exactly one JSON object with a single field `results`, an array of "
66
182
                "strings. The results array must have the same length and order as the input "
67
182
                "array. Do not return input objects or indexes. Two-row output format example "
68
182
                "(replace placeholders with actual results): {\"results\":[\"row1\",\"row2\"]}.";
69
182
        static const std::string legacy_prompt =
70
182
                std::string(Derived::system_prompt) +
71
182
                " Return exactly one JSON array of strings, with the same length and order as "
72
182
                "the input array. Do not return input objects or indexes. Two-row output format "
73
182
                "example (replace placeholders with actual results): [\"row1\",\"row2\"].";
74
182
        return structured_batch ? structured_prompt.c_str() : legacy_prompt.c_str();
75
182
    }
_ZN5doris10AIFunctionINS_16FunctionAIFilterEE19batch_system_promptEb
Line
Count
Source
60
10
    static const char* batch_system_prompt(bool structured_batch) {
61
        // Cache both complete prompts per function. Requests only select an immutable string;
62
        // changing task wording does not depend on finding/replacing an exact sentence.
63
10
        static const std::string structured_prompt =
64
10
                std::string(Derived::system_prompt) +
65
10
                " Return exactly one JSON object with a single field `results`, an array of "
66
10
                "strings. The results array must have the same length and order as the input "
67
10
                "array. Do not return input objects or indexes. Two-row output format example "
68
10
                "(replace placeholders with actual results): {\"results\":[\"row1\",\"row2\"]}.";
69
10
        static const std::string legacy_prompt =
70
10
                std::string(Derived::system_prompt) +
71
10
                " Return exactly one JSON array of strings, with the same length and order as "
72
10
                "the input array. Do not return input objects or indexes. Two-row output format "
73
10
                "example (replace placeholders with actual results): [\"row1\",\"row2\"].";
74
10
        return structured_batch ? structured_prompt.c_str() : legacy_prompt.c_str();
75
10
    }
_ZN5doris10AIFunctionINS_20FunctionAIFixGrammarEE19batch_system_promptEb
Line
Count
Source
60
8
    static const char* batch_system_prompt(bool structured_batch) {
61
        // Cache both complete prompts per function. Requests only select an immutable string;
62
        // changing task wording does not depend on finding/replacing an exact sentence.
63
8
        static const std::string structured_prompt =
64
8
                std::string(Derived::system_prompt) +
65
8
                " Return exactly one JSON object with a single field `results`, an array of "
66
8
                "strings. The results array must have the same length and order as the input "
67
8
                "array. Do not return input objects or indexes. Two-row output format example "
68
8
                "(replace placeholders with actual results): {\"results\":[\"row1\",\"row2\"]}.";
69
8
        static const std::string legacy_prompt =
70
8
                std::string(Derived::system_prompt) +
71
8
                " Return exactly one JSON array of strings, with the same length and order as "
72
8
                "the input array. Do not return input objects or indexes. Two-row output format "
73
8
                "example (replace placeholders with actual results): [\"row1\",\"row2\"].";
74
8
        return structured_batch ? structured_prompt.c_str() : legacy_prompt.c_str();
75
8
    }
_ZN5doris10AIFunctionINS_19FunctionAISentimentEE19batch_system_promptEb
Line
Count
Source
60
8
    static const char* batch_system_prompt(bool structured_batch) {
61
        // Cache both complete prompts per function. Requests only select an immutable string;
62
        // changing task wording does not depend on finding/replacing an exact sentence.
63
8
        static const std::string structured_prompt =
64
8
                std::string(Derived::system_prompt) +
65
8
                " Return exactly one JSON object with a single field `results`, an array of "
66
8
                "strings. The results array must have the same length and order as the input "
67
8
                "array. Do not return input objects or indexes. Two-row output format example "
68
8
                "(replace placeholders with actual results): {\"results\":[\"row1\",\"row2\"]}.";
69
8
        static const std::string legacy_prompt =
70
8
                std::string(Derived::system_prompt) +
71
8
                " Return exactly one JSON array of strings, with the same length and order as "
72
8
                "the input array. Do not return input objects or indexes. Two-row output format "
73
8
                "example (replace placeholders with actual results): [\"row1\",\"row2\"].";
74
8
        return structured_batch ? structured_prompt.c_str() : legacy_prompt.c_str();
75
8
    }
_ZN5doris10AIFunctionINS_19FunctionAISummarizeEE19batch_system_promptEb
Line
Count
Source
60
108
    static const char* batch_system_prompt(bool structured_batch) {
61
        // Cache both complete prompts per function. Requests only select an immutable string;
62
        // changing task wording does not depend on finding/replacing an exact sentence.
63
108
        static const std::string structured_prompt =
64
108
                std::string(Derived::system_prompt) +
65
108
                " Return exactly one JSON object with a single field `results`, an array of "
66
108
                "strings. The results array must have the same length and order as the input "
67
108
                "array. Do not return input objects or indexes. Two-row output format example "
68
108
                "(replace placeholders with actual results): {\"results\":[\"row1\",\"row2\"]}.";
69
108
        static const std::string legacy_prompt =
70
108
                std::string(Derived::system_prompt) +
71
108
                " Return exactly one JSON array of strings, with the same length and order as "
72
108
                "the input array. Do not return input objects or indexes. Two-row output format "
73
108
                "example (replace placeholders with actual results): [\"row1\",\"row2\"].";
74
108
        return structured_batch ? structured_prompt.c_str() : legacy_prompt.c_str();
75
108
    }
_ZN5doris10AIFunctionINS_18FunctionAIClassifyEE19batch_system_promptEb
Line
Count
Source
60
8
    static const char* batch_system_prompt(bool structured_batch) {
61
        // Cache both complete prompts per function. Requests only select an immutable string;
62
        // changing task wording does not depend on finding/replacing an exact sentence.
63
8
        static const std::string structured_prompt =
64
8
                std::string(Derived::system_prompt) +
65
8
                " Return exactly one JSON object with a single field `results`, an array of "
66
8
                "strings. The results array must have the same length and order as the input "
67
8
                "array. Do not return input objects or indexes. Two-row output format example "
68
8
                "(replace placeholders with actual results): {\"results\":[\"row1\",\"row2\"]}.";
69
8
        static const std::string legacy_prompt =
70
8
                std::string(Derived::system_prompt) +
71
8
                " Return exactly one JSON array of strings, with the same length and order as "
72
8
                "the input array. Do not return input objects or indexes. Two-row output format "
73
8
                "example (replace placeholders with actual results): [\"row1\",\"row2\"].";
74
8
        return structured_batch ? structured_prompt.c_str() : legacy_prompt.c_str();
75
8
    }
_ZN5doris10AIFunctionINS_17FunctionAIExtractEE19batch_system_promptEb
Line
Count
Source
60
8
    static const char* batch_system_prompt(bool structured_batch) {
61
        // Cache both complete prompts per function. Requests only select an immutable string;
62
        // changing task wording does not depend on finding/replacing an exact sentence.
63
8
        static const std::string structured_prompt =
64
8
                std::string(Derived::system_prompt) +
65
8
                " Return exactly one JSON object with a single field `results`, an array of "
66
8
                "strings. The results array must have the same length and order as the input "
67
8
                "array. Do not return input objects or indexes. Two-row output format example "
68
8
                "(replace placeholders with actual results): {\"results\":[\"row1\",\"row2\"]}.";
69
8
        static const std::string legacy_prompt =
70
8
                std::string(Derived::system_prompt) +
71
8
                " Return exactly one JSON array of strings, with the same length and order as "
72
8
                "the input array. Do not return input objects or indexes. Two-row output format "
73
8
                "example (replace placeholders with actual results): [\"row1\",\"row2\"].";
74
8
        return structured_batch ? structured_prompt.c_str() : legacy_prompt.c_str();
75
8
    }
_ZN5doris10AIFunctionINS_18FunctionAIGenerateEE19batch_system_promptEb
Line
Count
Source
60
8
    static const char* batch_system_prompt(bool structured_batch) {
61
        // Cache both complete prompts per function. Requests only select an immutable string;
62
        // changing task wording does not depend on finding/replacing an exact sentence.
63
8
        static const std::string structured_prompt =
64
8
                std::string(Derived::system_prompt) +
65
8
                " Return exactly one JSON object with a single field `results`, an array of "
66
8
                "strings. The results array must have the same length and order as the input "
67
8
                "array. Do not return input objects or indexes. Two-row output format example "
68
8
                "(replace placeholders with actual results): {\"results\":[\"row1\",\"row2\"]}.";
69
8
        static const std::string legacy_prompt =
70
8
                std::string(Derived::system_prompt) +
71
8
                " Return exactly one JSON array of strings, with the same length and order as "
72
8
                "the input array. Do not return input objects or indexes. Two-row output format "
73
8
                "example (replace placeholders with actual results): [\"row1\",\"row2\"].";
74
8
        return structured_batch ? structured_prompt.c_str() : legacy_prompt.c_str();
75
8
    }
_ZN5doris10AIFunctionINS_14FunctionAIMaskEE19batch_system_promptEb
Line
Count
Source
60
8
    static const char* batch_system_prompt(bool structured_batch) {
61
        // Cache both complete prompts per function. Requests only select an immutable string;
62
        // changing task wording does not depend on finding/replacing an exact sentence.
63
8
        static const std::string structured_prompt =
64
8
                std::string(Derived::system_prompt) +
65
8
                " Return exactly one JSON object with a single field `results`, an array of "
66
8
                "strings. The results array must have the same length and order as the input "
67
8
                "array. Do not return input objects or indexes. Two-row output format example "
68
8
                "(replace placeholders with actual results): {\"results\":[\"row1\",\"row2\"]}.";
69
8
        static const std::string legacy_prompt =
70
8
                std::string(Derived::system_prompt) +
71
8
                " Return exactly one JSON array of strings, with the same length and order as "
72
8
                "the input array. Do not return input objects or indexes. Two-row output format "
73
8
                "example (replace placeholders with actual results): [\"row1\",\"row2\"].";
74
8
        return structured_batch ? structured_prompt.c_str() : legacy_prompt.c_str();
75
8
    }
_ZN5doris10AIFunctionINS_20FunctionAISimilarityEE19batch_system_promptEb
Line
Count
Source
60
8
    static const char* batch_system_prompt(bool structured_batch) {
61
        // Cache both complete prompts per function. Requests only select an immutable string;
62
        // changing task wording does not depend on finding/replacing an exact sentence.
63
8
        static const std::string structured_prompt =
64
8
                std::string(Derived::system_prompt) +
65
8
                " Return exactly one JSON object with a single field `results`, an array of "
66
8
                "strings. The results array must have the same length and order as the input "
67
8
                "array. Do not return input objects or indexes. Two-row output format example "
68
8
                "(replace placeholders with actual results): {\"results\":[\"row1\",\"row2\"]}.";
69
8
        static const std::string legacy_prompt =
70
8
                std::string(Derived::system_prompt) +
71
8
                " Return exactly one JSON array of strings, with the same length and order as "
72
8
                "the input array. Do not return input objects or indexes. Two-row output format "
73
8
                "example (replace placeholders with actual results): [\"row1\",\"row2\"].";
74
8
        return structured_batch ? structured_prompt.c_str() : legacy_prompt.c_str();
75
8
    }
_ZN5doris10AIFunctionINS_19FunctionAITranslateEE19batch_system_promptEb
Line
Count
Source
60
8
    static const char* batch_system_prompt(bool structured_batch) {
61
        // Cache both complete prompts per function. Requests only select an immutable string;
62
        // changing task wording does not depend on finding/replacing an exact sentence.
63
8
        static const std::string structured_prompt =
64
8
                std::string(Derived::system_prompt) +
65
8
                " Return exactly one JSON object with a single field `results`, an array of "
66
8
                "strings. The results array must have the same length and order as the input "
67
8
                "array. Do not return input objects or indexes. Two-row output format example "
68
8
                "(replace placeholders with actual results): {\"results\":[\"row1\",\"row2\"]}.";
69
8
        static const std::string legacy_prompt =
70
8
                std::string(Derived::system_prompt) +
71
8
                " Return exactly one JSON array of strings, with the same length and order as "
72
8
                "the input array. Do not return input objects or indexes. Two-row output format "
73
8
                "example (replace placeholders with actual results): [\"row1\",\"row2\"].";
74
8
        return structured_batch ? structured_prompt.c_str() : legacy_prompt.c_str();
75
8
    }
76
77
36
    std::string get_name() const override { return assert_cast<const Derived&>(*this).name; }
_ZNK5doris10AIFunctionINS_13FunctionEmbedEE8get_nameB5cxx11Ev
Line
Count
Source
77
2
    std::string get_name() const override { return assert_cast<const Derived&>(*this).name; }
_ZNK5doris10AIFunctionINS_16FunctionAIFilterEE8get_nameB5cxx11Ev
Line
Count
Source
77
12
    std::string get_name() const override { return assert_cast<const Derived&>(*this).name; }
_ZNK5doris10AIFunctionINS_20FunctionAIFixGrammarEE8get_nameB5cxx11Ev
Line
Count
Source
77
2
    std::string get_name() const override { return assert_cast<const Derived&>(*this).name; }
_ZNK5doris10AIFunctionINS_19FunctionAISentimentEE8get_nameB5cxx11Ev
Line
Count
Source
77
2
    std::string get_name() const override { return assert_cast<const Derived&>(*this).name; }
_ZNK5doris10AIFunctionINS_19FunctionAISummarizeEE8get_nameB5cxx11Ev
Line
Count
Source
77
6
    std::string get_name() const override { return assert_cast<const Derived&>(*this).name; }
_ZNK5doris10AIFunctionINS_18FunctionAIClassifyEE8get_nameB5cxx11Ev
Line
Count
Source
77
2
    std::string get_name() const override { return assert_cast<const Derived&>(*this).name; }
_ZNK5doris10AIFunctionINS_17FunctionAIExtractEE8get_nameB5cxx11Ev
Line
Count
Source
77
2
    std::string get_name() const override { return assert_cast<const Derived&>(*this).name; }
_ZNK5doris10AIFunctionINS_18FunctionAIGenerateEE8get_nameB5cxx11Ev
Line
Count
Source
77
2
    std::string get_name() const override { return assert_cast<const Derived&>(*this).name; }
_ZNK5doris10AIFunctionINS_14FunctionAIMaskEE8get_nameB5cxx11Ev
Line
Count
Source
77
2
    std::string get_name() const override { return assert_cast<const Derived&>(*this).name; }
_ZNK5doris10AIFunctionINS_20FunctionAISimilarityEE8get_nameB5cxx11Ev
Line
Count
Source
77
2
    std::string get_name() const override { return assert_cast<const Derived&>(*this).name; }
_ZNK5doris10AIFunctionINS_19FunctionAITranslateEE8get_nameB5cxx11Ev
Line
Count
Source
77
2
    std::string get_name() const override { return assert_cast<const Derived&>(*this).name; }
78
79
    // If the user doesn't provide the first arg, `resource_name`
80
    // FE will add the `resource_name` to the arguments list using the Session Variable.
81
    // So the value here should be the maximum number that the function can accept.
82
38
    size_t get_number_of_arguments() const override {
83
38
        return assert_cast<const Derived&>(*this).number_of_arguments;
84
38
    }
_ZNK5doris10AIFunctionINS_13FunctionEmbedEE23get_number_of_argumentsEv
Line
Count
Source
82
8
    size_t get_number_of_arguments() const override {
83
8
        return assert_cast<const Derived&>(*this).number_of_arguments;
84
8
    }
_ZNK5doris10AIFunctionINS_16FunctionAIFilterEE23get_number_of_argumentsEv
Line
Count
Source
82
2
    size_t get_number_of_arguments() const override {
83
2
        return assert_cast<const Derived&>(*this).number_of_arguments;
84
2
    }
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_20FunctionAIFixGrammarEE23get_number_of_argumentsEv
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_19FunctionAISentimentEE23get_number_of_argumentsEv
_ZNK5doris10AIFunctionINS_19FunctionAISummarizeEE23get_number_of_argumentsEv
Line
Count
Source
82
14
    size_t get_number_of_arguments() const override {
83
14
        return assert_cast<const Derived&>(*this).number_of_arguments;
84
14
    }
_ZNK5doris10AIFunctionINS_18FunctionAIClassifyEE23get_number_of_argumentsEv
Line
Count
Source
82
4
    size_t get_number_of_arguments() const override {
83
4
        return assert_cast<const Derived&>(*this).number_of_arguments;
84
4
    }
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_17FunctionAIExtractEE23get_number_of_argumentsEv
_ZNK5doris10AIFunctionINS_18FunctionAIGenerateEE23get_number_of_argumentsEv
Line
Count
Source
82
8
    size_t get_number_of_arguments() const override {
83
8
        return assert_cast<const Derived&>(*this).number_of_arguments;
84
8
    }
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_14FunctionAIMaskEE23get_number_of_argumentsEv
_ZNK5doris10AIFunctionINS_20FunctionAISimilarityEE23get_number_of_argumentsEv
Line
Count
Source
82
2
    size_t get_number_of_arguments() const override {
83
2
        return assert_cast<const Derived&>(*this).number_of_arguments;
84
2
    }
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_19FunctionAITranslateEE23get_number_of_argumentsEv
85
86
0
    bool is_blockable() const override { return true; }
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_13FunctionEmbedEE12is_blockableEv
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_16FunctionAIFilterEE12is_blockableEv
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_20FunctionAIFixGrammarEE12is_blockableEv
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_19FunctionAISentimentEE12is_blockableEv
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_19FunctionAISummarizeEE12is_blockableEv
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_18FunctionAIClassifyEE12is_blockableEv
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_17FunctionAIExtractEE12is_blockableEv
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_18FunctionAIGenerateEE12is_blockableEv
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_14FunctionAIMaskEE12is_blockableEv
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_20FunctionAISimilarityEE12is_blockableEv
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_19FunctionAITranslateEE12is_blockableEv
87
88
44
    Status close(FunctionContext* context, FunctionContext::FunctionStateScope scope) override {
89
44
        if (scope == FunctionContext::FunctionStateScope::THREAD_LOCAL) {
90
            // Release this execution context's cached clients.
91
30
            context->set_function_state(scope, nullptr);
92
30
        }
93
44
        return Status::OK();
94
44
    }
Unexecuted instantiation: _ZN5doris10AIFunctionINS_13FunctionEmbedEE5closeEPNS_15FunctionContextENS3_18FunctionStateScopeE
Unexecuted instantiation: _ZN5doris10AIFunctionINS_16FunctionAIFilterEE5closeEPNS_15FunctionContextENS3_18FunctionStateScopeE
Unexecuted instantiation: _ZN5doris10AIFunctionINS_20FunctionAIFixGrammarEE5closeEPNS_15FunctionContextENS3_18FunctionStateScopeE
Unexecuted instantiation: _ZN5doris10AIFunctionINS_19FunctionAISentimentEE5closeEPNS_15FunctionContextENS3_18FunctionStateScopeE
_ZN5doris10AIFunctionINS_19FunctionAISummarizeEE5closeEPNS_15FunctionContextENS3_18FunctionStateScopeE
Line
Count
Source
88
44
    Status close(FunctionContext* context, FunctionContext::FunctionStateScope scope) override {
89
44
        if (scope == FunctionContext::FunctionStateScope::THREAD_LOCAL) {
90
            // Release this execution context's cached clients.
91
30
            context->set_function_state(scope, nullptr);
92
30
        }
93
44
        return Status::OK();
94
44
    }
Unexecuted instantiation: _ZN5doris10AIFunctionINS_18FunctionAIClassifyEE5closeEPNS_15FunctionContextENS3_18FunctionStateScopeE
Unexecuted instantiation: _ZN5doris10AIFunctionINS_17FunctionAIExtractEE5closeEPNS_15FunctionContextENS3_18FunctionStateScopeE
Unexecuted instantiation: _ZN5doris10AIFunctionINS_18FunctionAIGenerateEE5closeEPNS_15FunctionContextENS3_18FunctionStateScopeE
Unexecuted instantiation: _ZN5doris10AIFunctionINS_14FunctionAIMaskEE5closeEPNS_15FunctionContextENS3_18FunctionStateScopeE
Unexecuted instantiation: _ZN5doris10AIFunctionINS_20FunctionAISimilarityEE5closeEPNS_15FunctionContextENS3_18FunctionStateScopeE
Unexecuted instantiation: _ZN5doris10AIFunctionINS_19FunctionAITranslateEE5closeEPNS_15FunctionContextENS3_18FunctionStateScopeE
95
96
76
    bool use_default_implementation_for_nulls() const final { return false; }
_ZNK5doris10AIFunctionINS_13FunctionEmbedEE36use_default_implementation_for_nullsEv
Line
Count
Source
96
16
    bool use_default_implementation_for_nulls() const final { return false; }
_ZNK5doris10AIFunctionINS_16FunctionAIFilterEE36use_default_implementation_for_nullsEv
Line
Count
Source
96
4
    bool use_default_implementation_for_nulls() const final { return false; }
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_20FunctionAIFixGrammarEE36use_default_implementation_for_nullsEv
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_19FunctionAISentimentEE36use_default_implementation_for_nullsEv
_ZNK5doris10AIFunctionINS_19FunctionAISummarizeEE36use_default_implementation_for_nullsEv
Line
Count
Source
96
28
    bool use_default_implementation_for_nulls() const final { return false; }
_ZNK5doris10AIFunctionINS_18FunctionAIClassifyEE36use_default_implementation_for_nullsEv
Line
Count
Source
96
8
    bool use_default_implementation_for_nulls() const final { return false; }
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_17FunctionAIExtractEE36use_default_implementation_for_nullsEv
_ZNK5doris10AIFunctionINS_18FunctionAIGenerateEE36use_default_implementation_for_nullsEv
Line
Count
Source
96
16
    bool use_default_implementation_for_nulls() const final { return false; }
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_14FunctionAIMaskEE36use_default_implementation_for_nullsEv
_ZNK5doris10AIFunctionINS_20FunctionAISimilarityEE36use_default_implementation_for_nullsEv
Line
Count
Source
96
4
    bool use_default_implementation_for_nulls() const final { return false; }
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_19FunctionAITranslateEE36use_default_implementation_for_nullsEv
97
98
60
    DataTypePtr get_return_type_impl(const DataTypes& arguments) const final {
99
60
        bool has_nullable_argument = std::ranges::any_of(
100
78
                arguments, [](const auto& argument) { return argument->is_nullable(); });
_ZZNK5doris10AIFunctionINS_13FunctionEmbedEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EEENKUlRKT_E_clIS7_EEDaSE_
Line
Count
Source
100
16
                arguments, [](const auto& argument) { return argument->is_nullable(); });
_ZZNK5doris10AIFunctionINS_16FunctionAIFilterEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EEENKUlRKT_E_clIS7_EEDaSE_
Line
Count
Source
100
4
                arguments, [](const auto& argument) { return argument->is_nullable(); });
Unexecuted instantiation: _ZZNK5doris10AIFunctionINS_20FunctionAIFixGrammarEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EEENKUlRKT_E_clIS7_EEDaSE_
Unexecuted instantiation: _ZZNK5doris10AIFunctionINS_19FunctionAISentimentEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EEENKUlRKT_E_clIS7_EEDaSE_
_ZZNK5doris10AIFunctionINS_19FunctionAISummarizeEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EEENKUlRKT_E_clIS7_EEDaSE_
Line
Count
Source
100
28
                arguments, [](const auto& argument) { return argument->is_nullable(); });
_ZZNK5doris10AIFunctionINS_18FunctionAIClassifyEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EEENKUlRKT_E_clIS7_EEDaSE_
Line
Count
Source
100
12
                arguments, [](const auto& argument) { return argument->is_nullable(); });
Unexecuted instantiation: _ZZNK5doris10AIFunctionINS_17FunctionAIExtractEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EEENKUlRKT_E_clIS7_EEDaSE_
_ZZNK5doris10AIFunctionINS_18FunctionAIGenerateEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EEENKUlRKT_E_clIS7_EEDaSE_
Line
Count
Source
100
14
                arguments, [](const auto& argument) { return argument->is_nullable(); });
Unexecuted instantiation: _ZZNK5doris10AIFunctionINS_14FunctionAIMaskEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EEENKUlRKT_E_clIS7_EEDaSE_
_ZZNK5doris10AIFunctionINS_20FunctionAISimilarityEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EEENKUlRKT_E_clIS7_EEDaSE_
Line
Count
Source
100
4
                arguments, [](const auto& argument) { return argument->is_nullable(); });
Unexecuted instantiation: _ZZNK5doris10AIFunctionINS_19FunctionAITranslateEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EEENKUlRKT_E_clIS7_EEDaSE_
101
60
        DataTypePtr return_type =
102
60
                assert_cast<const Derived&>(*this).get_nested_return_type_impl(arguments);
103
60
        return has_nullable_argument ? make_nullable(return_type) : return_type;
104
60
    }
_ZNK5doris10AIFunctionINS_13FunctionEmbedEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE
Line
Count
Source
98
10
    DataTypePtr get_return_type_impl(const DataTypes& arguments) const final {
99
10
        bool has_nullable_argument = std::ranges::any_of(
100
10
                arguments, [](const auto& argument) { return argument->is_nullable(); });
101
10
        DataTypePtr return_type =
102
10
                assert_cast<const Derived&>(*this).get_nested_return_type_impl(arguments);
103
10
        return has_nullable_argument ? make_nullable(return_type) : return_type;
104
10
    }
_ZNK5doris10AIFunctionINS_16FunctionAIFilterEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE
Line
Count
Source
98
4
    DataTypePtr get_return_type_impl(const DataTypes& arguments) const final {
99
4
        bool has_nullable_argument = std::ranges::any_of(
100
4
                arguments, [](const auto& argument) { return argument->is_nullable(); });
101
4
        DataTypePtr return_type =
102
4
                assert_cast<const Derived&>(*this).get_nested_return_type_impl(arguments);
103
4
        return has_nullable_argument ? make_nullable(return_type) : return_type;
104
4
    }
_ZNK5doris10AIFunctionINS_20FunctionAIFixGrammarEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE
Line
Count
Source
98
2
    DataTypePtr get_return_type_impl(const DataTypes& arguments) const final {
99
2
        bool has_nullable_argument = std::ranges::any_of(
100
2
                arguments, [](const auto& argument) { return argument->is_nullable(); });
101
2
        DataTypePtr return_type =
102
2
                assert_cast<const Derived&>(*this).get_nested_return_type_impl(arguments);
103
2
        return has_nullable_argument ? make_nullable(return_type) : return_type;
104
2
    }
_ZNK5doris10AIFunctionINS_19FunctionAISentimentEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE
Line
Count
Source
98
2
    DataTypePtr get_return_type_impl(const DataTypes& arguments) const final {
99
2
        bool has_nullable_argument = std::ranges::any_of(
100
2
                arguments, [](const auto& argument) { return argument->is_nullable(); });
101
2
        DataTypePtr return_type =
102
2
                assert_cast<const Derived&>(*this).get_nested_return_type_impl(arguments);
103
2
        return has_nullable_argument ? make_nullable(return_type) : return_type;
104
2
    }
_ZNK5doris10AIFunctionINS_19FunctionAISummarizeEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE
Line
Count
Source
98
16
    DataTypePtr get_return_type_impl(const DataTypes& arguments) const final {
99
16
        bool has_nullable_argument = std::ranges::any_of(
100
16
                arguments, [](const auto& argument) { return argument->is_nullable(); });
101
16
        DataTypePtr return_type =
102
16
                assert_cast<const Derived&>(*this).get_nested_return_type_impl(arguments);
103
16
        return has_nullable_argument ? make_nullable(return_type) : return_type;
104
16
    }
_ZNK5doris10AIFunctionINS_18FunctionAIClassifyEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE
Line
Count
Source
98
6
    DataTypePtr get_return_type_impl(const DataTypes& arguments) const final {
99
6
        bool has_nullable_argument = std::ranges::any_of(
100
6
                arguments, [](const auto& argument) { return argument->is_nullable(); });
101
6
        DataTypePtr return_type =
102
6
                assert_cast<const Derived&>(*this).get_nested_return_type_impl(arguments);
103
6
        return has_nullable_argument ? make_nullable(return_type) : return_type;
104
6
    }
_ZNK5doris10AIFunctionINS_17FunctionAIExtractEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE
Line
Count
Source
98
2
    DataTypePtr get_return_type_impl(const DataTypes& arguments) const final {
99
2
        bool has_nullable_argument = std::ranges::any_of(
100
2
                arguments, [](const auto& argument) { return argument->is_nullable(); });
101
2
        DataTypePtr return_type =
102
2
                assert_cast<const Derived&>(*this).get_nested_return_type_impl(arguments);
103
2
        return has_nullable_argument ? make_nullable(return_type) : return_type;
104
2
    }
_ZNK5doris10AIFunctionINS_18FunctionAIGenerateEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE
Line
Count
Source
98
10
    DataTypePtr get_return_type_impl(const DataTypes& arguments) const final {
99
10
        bool has_nullable_argument = std::ranges::any_of(
100
10
                arguments, [](const auto& argument) { return argument->is_nullable(); });
101
10
        DataTypePtr return_type =
102
10
                assert_cast<const Derived&>(*this).get_nested_return_type_impl(arguments);
103
10
        return has_nullable_argument ? make_nullable(return_type) : return_type;
104
10
    }
_ZNK5doris10AIFunctionINS_14FunctionAIMaskEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE
Line
Count
Source
98
2
    DataTypePtr get_return_type_impl(const DataTypes& arguments) const final {
99
2
        bool has_nullable_argument = std::ranges::any_of(
100
2
                arguments, [](const auto& argument) { return argument->is_nullable(); });
101
2
        DataTypePtr return_type =
102
2
                assert_cast<const Derived&>(*this).get_nested_return_type_impl(arguments);
103
2
        return has_nullable_argument ? make_nullable(return_type) : return_type;
104
2
    }
_ZNK5doris10AIFunctionINS_20FunctionAISimilarityEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE
Line
Count
Source
98
4
    DataTypePtr get_return_type_impl(const DataTypes& arguments) const final {
99
4
        bool has_nullable_argument = std::ranges::any_of(
100
4
                arguments, [](const auto& argument) { return argument->is_nullable(); });
101
4
        DataTypePtr return_type =
102
4
                assert_cast<const Derived&>(*this).get_nested_return_type_impl(arguments);
103
4
        return has_nullable_argument ? make_nullable(return_type) : return_type;
104
4
    }
_ZNK5doris10AIFunctionINS_19FunctionAITranslateEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaIS7_EE
Line
Count
Source
98
2
    DataTypePtr get_return_type_impl(const DataTypes& arguments) const final {
99
2
        bool has_nullable_argument = std::ranges::any_of(
100
2
                arguments, [](const auto& argument) { return argument->is_nullable(); });
101
2
        DataTypePtr return_type =
102
2
                assert_cast<const Derived&>(*this).get_nested_return_type_impl(arguments);
103
2
        return has_nullable_argument ? make_nullable(return_type) : return_type;
104
2
    }
105
106
    using PreparedFunctionImpl::execute;
107
108
    virtual Status build_prompt(const Columns& prompt_columns, size_t row_num,
109
228
                                std::string& prompt) const {
110
228
        StringRef text_ref = prompt_columns[0]->get_data_at(row_num);
111
228
        prompt = std::string(text_ref.data, text_ref.size);
112
113
228
        return Status::OK();
114
228
    }
_ZNK5doris10AIFunctionINS_13FunctionEmbedEE12build_promptERKSt6vectorINS_3COWINS_7IColumnEE13immutable_ptrIS5_EESaIS8_EEmRNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
109
50
                                std::string& prompt) const {
110
50
        StringRef text_ref = prompt_columns[0]->get_data_at(row_num);
111
50
        prompt = std::string(text_ref.data, text_ref.size);
112
113
50
        return Status::OK();
114
50
    }
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_18FunctionAIClassifyEE12build_promptERKSt6vectorINS_3COWINS_7IColumnEE13immutable_ptrIS5_EESaIS8_EEmRNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_17FunctionAIExtractEE12build_promptERKSt6vectorINS_3COWINS_7IColumnEE13immutable_ptrIS5_EESaIS8_EEmRNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
_ZNK5doris10AIFunctionINS_16FunctionAIFilterEE12build_promptERKSt6vectorINS_3COWINS_7IColumnEE13immutable_ptrIS5_EESaIS8_EEmRNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
109
130
                                std::string& prompt) const {
110
130
        StringRef text_ref = prompt_columns[0]->get_data_at(row_num);
111
130
        prompt = std::string(text_ref.data, text_ref.size);
112
113
130
        return Status::OK();
114
130
    }
_ZNK5doris10AIFunctionINS_20FunctionAIFixGrammarEE12build_promptERKSt6vectorINS_3COWINS_7IColumnEE13immutable_ptrIS5_EESaIS8_EEmRNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
109
2
                                std::string& prompt) const {
110
2
        StringRef text_ref = prompt_columns[0]->get_data_at(row_num);
111
2
        prompt = std::string(text_ref.data, text_ref.size);
112
113
2
        return Status::OK();
114
2
    }
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_18FunctionAIGenerateEE12build_promptERKSt6vectorINS_3COWINS_7IColumnEE13immutable_ptrIS5_EESaIS8_EEmRNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_14FunctionAIMaskEE12build_promptERKSt6vectorINS_3COWINS_7IColumnEE13immutable_ptrIS5_EESaIS8_EEmRNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
_ZNK5doris10AIFunctionINS_19FunctionAISentimentEE12build_promptERKSt6vectorINS_3COWINS_7IColumnEE13immutable_ptrIS5_EESaIS8_EEmRNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
109
10
                                std::string& prompt) const {
110
10
        StringRef text_ref = prompt_columns[0]->get_data_at(row_num);
111
10
        prompt = std::string(text_ref.data, text_ref.size);
112
113
10
        return Status::OK();
114
10
    }
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_20FunctionAISimilarityEE12build_promptERKSt6vectorINS_3COWINS_7IColumnEE13immutable_ptrIS5_EESaIS8_EEmRNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
_ZNK5doris10AIFunctionINS_19FunctionAISummarizeEE12build_promptERKSt6vectorINS_3COWINS_7IColumnEE13immutable_ptrIS5_EESaIS8_EEmRNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
109
36
                                std::string& prompt) const {
110
36
        StringRef text_ref = prompt_columns[0]->get_data_at(row_num);
111
36
        prompt = std::string(text_ref.data, text_ref.size);
112
113
36
        return Status::OK();
114
36
    }
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_19FunctionAITranslateEE12build_promptERKSt6vectorINS_3COWINS_7IColumnEE13immutable_ptrIS5_EESaIS8_EEmRNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
115
116
    Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
117
198
                        uint32_t result, size_t input_rows_count) const override {
118
198
        auto* executor = get_executor(context);
119
198
        if (block.get_by_position(arguments[0]).column->only_null()) {
120
2
            if (executor->statistics()) {
121
2
                executor->statistics()->record_input(input_rows_count, input_rows_count);
122
2
            }
123
2
            block.get_by_position(result).column =
124
2
                    block.get_by_position(result).type->create_column_const(input_rows_count,
125
2
                                                                            Field());
126
2
            return Status::OK();
127
2
        }
128
129
196
        AIResource config;
130
196
        std::shared_ptr<AIAdapter> adapter;
131
196
        if (Status status = this->_init_from_resource(context, block, arguments, config, adapter);
132
196
            !status.ok()) {
133
0
            return status;
134
0
        }
135
136
196
        return assert_cast<const Derived&>(*this).execute(context, block, arguments, result,
137
196
                                                          input_rows_count, config, adapter);
138
196
    }
_ZNK5doris10AIFunctionINS_13FunctionEmbedEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm
Line
Count
Source
117
30
                        uint32_t result, size_t input_rows_count) const override {
118
30
        auto* executor = get_executor(context);
119
30
        if (block.get_by_position(arguments[0]).column->only_null()) {
120
0
            if (executor->statistics()) {
121
0
                executor->statistics()->record_input(input_rows_count, input_rows_count);
122
0
            }
123
0
            block.get_by_position(result).column =
124
0
                    block.get_by_position(result).type->create_column_const(input_rows_count,
125
0
                                                                            Field());
126
0
            return Status::OK();
127
0
        }
128
129
30
        AIResource config;
130
30
        std::shared_ptr<AIAdapter> adapter;
131
30
        if (Status status = this->_init_from_resource(context, block, arguments, config, adapter);
132
30
            !status.ok()) {
133
0
            return status;
134
0
        }
135
136
30
        return assert_cast<const Derived&>(*this).execute(context, block, arguments, result,
137
30
                                                          input_rows_count, config, adapter);
138
30
    }
_ZNK5doris10AIFunctionINS_16FunctionAIFilterEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm
Line
Count
Source
117
94
                        uint32_t result, size_t input_rows_count) const override {
118
94
        auto* executor = get_executor(context);
119
94
        if (block.get_by_position(arguments[0]).column->only_null()) {
120
0
            if (executor->statistics()) {
121
0
                executor->statistics()->record_input(input_rows_count, input_rows_count);
122
0
            }
123
0
            block.get_by_position(result).column =
124
0
                    block.get_by_position(result).type->create_column_const(input_rows_count,
125
0
                                                                            Field());
126
0
            return Status::OK();
127
0
        }
128
129
94
        AIResource config;
130
94
        std::shared_ptr<AIAdapter> adapter;
131
94
        if (Status status = this->_init_from_resource(context, block, arguments, config, adapter);
132
94
            !status.ok()) {
133
0
            return status;
134
0
        }
135
136
94
        return assert_cast<const Derived&>(*this).execute(context, block, arguments, result,
137
94
                                                          input_rows_count, config, adapter);
138
94
    }
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_20FunctionAIFixGrammarEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm
_ZNK5doris10AIFunctionINS_19FunctionAISentimentEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm
Line
Count
Source
117
4
                        uint32_t result, size_t input_rows_count) const override {
118
4
        auto* executor = get_executor(context);
119
4
        if (block.get_by_position(arguments[0]).column->only_null()) {
120
0
            if (executor->statistics()) {
121
0
                executor->statistics()->record_input(input_rows_count, input_rows_count);
122
0
            }
123
0
            block.get_by_position(result).column =
124
0
                    block.get_by_position(result).type->create_column_const(input_rows_count,
125
0
                                                                            Field());
126
0
            return Status::OK();
127
0
        }
128
129
4
        AIResource config;
130
4
        std::shared_ptr<AIAdapter> adapter;
131
4
        if (Status status = this->_init_from_resource(context, block, arguments, config, adapter);
132
4
            !status.ok()) {
133
0
            return status;
134
0
        }
135
136
4
        return assert_cast<const Derived&>(*this).execute(context, block, arguments, result,
137
4
                                                          input_rows_count, config, adapter);
138
4
    }
_ZNK5doris10AIFunctionINS_19FunctionAISummarizeEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm
Line
Count
Source
117
14
                        uint32_t result, size_t input_rows_count) const override {
118
14
        auto* executor = get_executor(context);
119
14
        if (block.get_by_position(arguments[0]).column->only_null()) {
120
0
            if (executor->statistics()) {
121
0
                executor->statistics()->record_input(input_rows_count, input_rows_count);
122
0
            }
123
0
            block.get_by_position(result).column =
124
0
                    block.get_by_position(result).type->create_column_const(input_rows_count,
125
0
                                                                            Field());
126
0
            return Status::OK();
127
0
        }
128
129
14
        AIResource config;
130
14
        std::shared_ptr<AIAdapter> adapter;
131
14
        if (Status status = this->_init_from_resource(context, block, arguments, config, adapter);
132
14
            !status.ok()) {
133
0
            return status;
134
0
        }
135
136
14
        return assert_cast<const Derived&>(*this).execute(context, block, arguments, result,
137
14
                                                          input_rows_count, config, adapter);
138
14
    }
_ZNK5doris10AIFunctionINS_18FunctionAIClassifyEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm
Line
Count
Source
117
4
                        uint32_t result, size_t input_rows_count) const override {
118
4
        auto* executor = get_executor(context);
119
4
        if (block.get_by_position(arguments[0]).column->only_null()) {
120
0
            if (executor->statistics()) {
121
0
                executor->statistics()->record_input(input_rows_count, input_rows_count);
122
0
            }
123
0
            block.get_by_position(result).column =
124
0
                    block.get_by_position(result).type->create_column_const(input_rows_count,
125
0
                                                                            Field());
126
0
            return Status::OK();
127
0
        }
128
129
4
        AIResource config;
130
4
        std::shared_ptr<AIAdapter> adapter;
131
4
        if (Status status = this->_init_from_resource(context, block, arguments, config, adapter);
132
4
            !status.ok()) {
133
0
            return status;
134
0
        }
135
136
4
        return assert_cast<const Derived&>(*this).execute(context, block, arguments, result,
137
4
                                                          input_rows_count, config, adapter);
138
4
    }
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_17FunctionAIExtractEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm
_ZNK5doris10AIFunctionINS_18FunctionAIGenerateEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm
Line
Count
Source
117
8
                        uint32_t result, size_t input_rows_count) const override {
118
8
        auto* executor = get_executor(context);
119
8
        if (block.get_by_position(arguments[0]).column->only_null()) {
120
2
            if (executor->statistics()) {
121
2
                executor->statistics()->record_input(input_rows_count, input_rows_count);
122
2
            }
123
2
            block.get_by_position(result).column =
124
2
                    block.get_by_position(result).type->create_column_const(input_rows_count,
125
2
                                                                            Field());
126
2
            return Status::OK();
127
2
        }
128
129
6
        AIResource config;
130
6
        std::shared_ptr<AIAdapter> adapter;
131
6
        if (Status status = this->_init_from_resource(context, block, arguments, config, adapter);
132
6
            !status.ok()) {
133
0
            return status;
134
0
        }
135
136
6
        return assert_cast<const Derived&>(*this).execute(context, block, arguments, result,
137
6
                                                          input_rows_count, config, adapter);
138
6
    }
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_14FunctionAIMaskEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm
_ZNK5doris10AIFunctionINS_20FunctionAISimilarityEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm
Line
Count
Source
117
44
                        uint32_t result, size_t input_rows_count) const override {
118
44
        auto* executor = get_executor(context);
119
44
        if (block.get_by_position(arguments[0]).column->only_null()) {
120
0
            if (executor->statistics()) {
121
0
                executor->statistics()->record_input(input_rows_count, input_rows_count);
122
0
            }
123
0
            block.get_by_position(result).column =
124
0
                    block.get_by_position(result).type->create_column_const(input_rows_count,
125
0
                                                                            Field());
126
0
            return Status::OK();
127
0
        }
128
129
44
        AIResource config;
130
44
        std::shared_ptr<AIAdapter> adapter;
131
44
        if (Status status = this->_init_from_resource(context, block, arguments, config, adapter);
132
44
            !status.ok()) {
133
0
            return status;
134
0
        }
135
136
44
        return assert_cast<const Derived&>(*this).execute(context, block, arguments, result,
137
44
                                                          input_rows_count, config, adapter);
138
44
    }
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_19FunctionAITranslateEE12execute_implEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjm
139
140
protected:
141
    // Reads the shared AI context window size from query options. String AI batch functions and
142
    // ai_agg both use the same byte-based session variable so batching behavior stays consistent.
143
196
    static int64_t get_ai_context_window_size(FunctionContext* context) {
144
196
        DORIS_CHECK(context != nullptr);
145
196
        QueryContext* query_ctx = context->state()->get_query_ctx();
146
196
        DORIS_CHECK(query_ctx != nullptr);
147
148
196
        return query_ctx->query_options().ai_context_window_size;
149
196
    }
_ZN5doris10AIFunctionINS_13FunctionEmbedEE26get_ai_context_window_sizeEPNS_15FunctionContextE
Line
Count
Source
143
22
    static int64_t get_ai_context_window_size(FunctionContext* context) {
144
22
        DORIS_CHECK(context != nullptr);
145
22
        QueryContext* query_ctx = context->state()->get_query_ctx();
146
22
        DORIS_CHECK(query_ctx != nullptr);
147
148
22
        return query_ctx->query_options().ai_context_window_size;
149
22
    }
_ZN5doris10AIFunctionINS_16FunctionAIFilterEE26get_ai_context_window_sizeEPNS_15FunctionContextE
Line
Count
Source
143
94
    static int64_t get_ai_context_window_size(FunctionContext* context) {
144
94
        DORIS_CHECK(context != nullptr);
145
94
        QueryContext* query_ctx = context->state()->get_query_ctx();
146
94
        DORIS_CHECK(query_ctx != nullptr);
147
148
94
        return query_ctx->query_options().ai_context_window_size;
149
94
    }
Unexecuted instantiation: _ZN5doris10AIFunctionINS_20FunctionAIFixGrammarEE26get_ai_context_window_sizeEPNS_15FunctionContextE
_ZN5doris10AIFunctionINS_19FunctionAISentimentEE26get_ai_context_window_sizeEPNS_15FunctionContextE
Line
Count
Source
143
4
    static int64_t get_ai_context_window_size(FunctionContext* context) {
144
4
        DORIS_CHECK(context != nullptr);
145
4
        QueryContext* query_ctx = context->state()->get_query_ctx();
146
4
        DORIS_CHECK(query_ctx != nullptr);
147
148
4
        return query_ctx->query_options().ai_context_window_size;
149
4
    }
_ZN5doris10AIFunctionINS_19FunctionAISummarizeEE26get_ai_context_window_sizeEPNS_15FunctionContextE
Line
Count
Source
143
24
    static int64_t get_ai_context_window_size(FunctionContext* context) {
144
24
        DORIS_CHECK(context != nullptr);
145
24
        QueryContext* query_ctx = context->state()->get_query_ctx();
146
24
        DORIS_CHECK(query_ctx != nullptr);
147
148
24
        return query_ctx->query_options().ai_context_window_size;
149
24
    }
_ZN5doris10AIFunctionINS_18FunctionAIClassifyEE26get_ai_context_window_sizeEPNS_15FunctionContextE
Line
Count
Source
143
4
    static int64_t get_ai_context_window_size(FunctionContext* context) {
144
4
        DORIS_CHECK(context != nullptr);
145
4
        QueryContext* query_ctx = context->state()->get_query_ctx();
146
4
        DORIS_CHECK(query_ctx != nullptr);
147
148
4
        return query_ctx->query_options().ai_context_window_size;
149
4
    }
Unexecuted instantiation: _ZN5doris10AIFunctionINS_17FunctionAIExtractEE26get_ai_context_window_sizeEPNS_15FunctionContextE
_ZN5doris10AIFunctionINS_18FunctionAIGenerateEE26get_ai_context_window_sizeEPNS_15FunctionContextE
Line
Count
Source
143
4
    static int64_t get_ai_context_window_size(FunctionContext* context) {
144
4
        DORIS_CHECK(context != nullptr);
145
4
        QueryContext* query_ctx = context->state()->get_query_ctx();
146
4
        DORIS_CHECK(query_ctx != nullptr);
147
148
4
        return query_ctx->query_options().ai_context_window_size;
149
4
    }
Unexecuted instantiation: _ZN5doris10AIFunctionINS_14FunctionAIMaskEE26get_ai_context_window_sizeEPNS_15FunctionContextE
_ZN5doris10AIFunctionINS_20FunctionAISimilarityEE26get_ai_context_window_sizeEPNS_15FunctionContextE
Line
Count
Source
143
44
    static int64_t get_ai_context_window_size(FunctionContext* context) {
144
44
        DORIS_CHECK(context != nullptr);
145
44
        QueryContext* query_ctx = context->state()->get_query_ctx();
146
44
        DORIS_CHECK(query_ctx != nullptr);
147
148
44
        return query_ctx->query_options().ai_context_window_size;
149
44
    }
Unexecuted instantiation: _ZN5doris10AIFunctionINS_19FunctionAITranslateEE26get_ai_context_window_sizeEPNS_15FunctionContextE
150
151
36
    MutableColumnPtr create_result_column() const { return ColumnString::create(); }
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_20FunctionAIFixGrammarEE20create_result_columnEv
_ZNK5doris10AIFunctionINS_19FunctionAISentimentEE20create_result_columnEv
Line
Count
Source
151
4
    MutableColumnPtr create_result_column() const { return ColumnString::create(); }
_ZNK5doris10AIFunctionINS_19FunctionAISummarizeEE20create_result_columnEv
Line
Count
Source
151
24
    MutableColumnPtr create_result_column() const { return ColumnString::create(); }
_ZNK5doris10AIFunctionINS_18FunctionAIClassifyEE20create_result_columnEv
Line
Count
Source
151
4
    MutableColumnPtr create_result_column() const { return ColumnString::create(); }
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_17FunctionAIExtractEE20create_result_columnEv
_ZNK5doris10AIFunctionINS_18FunctionAIGenerateEE20create_result_columnEv
Line
Count
Source
151
4
    MutableColumnPtr create_result_column() const { return ColumnString::create(); }
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_14FunctionAIMaskEE20create_result_columnEv
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_19FunctionAITranslateEE20create_result_columnEv
152
153
    // Provider-reusable hook for AI functions(string) -> string.
154
    Status append_batch_results(const std::vector<std::string>& batch_results,
155
46
                                IColumn& col_result) const {
156
46
        auto& string_col = assert_cast<ColumnString&>(col_result);
157
56
        for (const auto& batch_result : batch_results) {
158
56
            string_col.insert_data(batch_result.data(), batch_result.size());
159
56
        }
160
46
        return Status::OK();
161
46
    }
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_20FunctionAIFixGrammarEE20append_batch_resultsERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERNS_7IColumnE
_ZNK5doris10AIFunctionINS_19FunctionAISentimentEE20append_batch_resultsERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERNS_7IColumnE
Line
Count
Source
155
4
                                IColumn& col_result) const {
156
4
        auto& string_col = assert_cast<ColumnString&>(col_result);
157
8
        for (const auto& batch_result : batch_results) {
158
8
            string_col.insert_data(batch_result.data(), batch_result.size());
159
8
        }
160
4
        return Status::OK();
161
4
    }
_ZNK5doris10AIFunctionINS_19FunctionAISummarizeEE20append_batch_resultsERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERNS_7IColumnE
Line
Count
Source
155
34
                                IColumn& col_result) const {
156
34
        auto& string_col = assert_cast<ColumnString&>(col_result);
157
34
        for (const auto& batch_result : batch_results) {
158
34
            string_col.insert_data(batch_result.data(), batch_result.size());
159
34
        }
160
34
        return Status::OK();
161
34
    }
_ZNK5doris10AIFunctionINS_18FunctionAIClassifyEE20append_batch_resultsERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERNS_7IColumnE
Line
Count
Source
155
4
                                IColumn& col_result) const {
156
4
        auto& string_col = assert_cast<ColumnString&>(col_result);
157
4
        for (const auto& batch_result : batch_results) {
158
4
            string_col.insert_data(batch_result.data(), batch_result.size());
159
4
        }
160
4
        return Status::OK();
161
4
    }
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_17FunctionAIExtractEE20append_batch_resultsERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERNS_7IColumnE
_ZNK5doris10AIFunctionINS_18FunctionAIGenerateEE20append_batch_resultsERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERNS_7IColumnE
Line
Count
Source
155
4
                                IColumn& col_result) const {
156
4
        auto& string_col = assert_cast<ColumnString&>(col_result);
157
10
        for (const auto& batch_result : batch_results) {
158
10
            string_col.insert_data(batch_result.data(), batch_result.size());
159
10
        }
160
4
        return Status::OK();
161
4
    }
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_14FunctionAIMaskEE20append_batch_resultsERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERNS_7IColumnE
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_19FunctionAITranslateEE20append_batch_resultsERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERNS_7IColumnE
162
163
210
    static void normalize_endpoint(AIResource& config) {
164
        // 1. If users configure only the version root like `.../v1` or `.../v1beta`, append
165
        //    `models/<model>:batchEmbedContents` for `embed`, and `models/<model>:generateContent`
166
        //    for other AI scalar functions.
167
        // 2. `:embedContent` -> `:batchEmbedContents`
168
210
        if (iequal(config.provider_type, "GEMINI")) {
169
8
            if (iequal(Derived::name, "embed") && config.endpoint.ends_with(":embedContent")) {
170
2
                static constexpr std::string_view legacy_suffix = ":embedContent";
171
2
                config.endpoint.replace(config.endpoint.size() - legacy_suffix.size(),
172
2
                                        legacy_suffix.size(), ":batchEmbedContents");
173
2
                return;
174
2
            }
175
176
6
            if (!config.endpoint.ends_with("v1") && !config.endpoint.ends_with("v1beta")) {
177
2
                return;
178
2
            }
179
180
4
            std::string model_name = config.model_name;
181
4
            if (!model_name.starts_with("models/")) {
182
4
                model_name = "models/" + model_name;
183
4
            }
184
185
4
            config.endpoint += "/";
186
4
            config.endpoint += model_name;
187
4
            config.endpoint +=
188
4
                    iequal(Derived::name, "embed") ? ":batchEmbedContents" : ":generateContent";
189
4
            return;
190
6
        }
191
192
        // The endpoint `v1/completions` does not support `system_prompt`.
193
        // To ensure a clear structure and stable AI results.
194
        // Convert from `v1/completions` to `v1/chat/completions`
195
202
        if (config.endpoint.ends_with("v1/completions")) {
196
2
            static constexpr std::string_view legacy_suffix = "v1/completions";
197
2
            config.endpoint.replace(config.endpoint.size() - legacy_suffix.size(),
198
2
                                    legacy_suffix.size(), "v1/chat/completions");
199
2
        }
200
202
    }
_ZN5doris10AIFunctionINS_13FunctionEmbedEE18normalize_endpointERNS_10AIResourceE
Line
Count
Source
163
34
    static void normalize_endpoint(AIResource& config) {
164
        // 1. If users configure only the version root like `.../v1` or `.../v1beta`, append
165
        //    `models/<model>:batchEmbedContents` for `embed`, and `models/<model>:generateContent`
166
        //    for other AI scalar functions.
167
        // 2. `:embedContent` -> `:batchEmbedContents`
168
34
        if (iequal(config.provider_type, "GEMINI")) {
169
4
            if (iequal(Derived::name, "embed") && config.endpoint.ends_with(":embedContent")) {
170
2
                static constexpr std::string_view legacy_suffix = ":embedContent";
171
2
                config.endpoint.replace(config.endpoint.size() - legacy_suffix.size(),
172
2
                                        legacy_suffix.size(), ":batchEmbedContents");
173
2
                return;
174
2
            }
175
176
2
            if (!config.endpoint.ends_with("v1") && !config.endpoint.ends_with("v1beta")) {
177
0
                return;
178
0
            }
179
180
2
            std::string model_name = config.model_name;
181
2
            if (!model_name.starts_with("models/")) {
182
2
                model_name = "models/" + model_name;
183
2
            }
184
185
2
            config.endpoint += "/";
186
2
            config.endpoint += model_name;
187
2
            config.endpoint +=
188
2
                    iequal(Derived::name, "embed") ? ":batchEmbedContents" : ":generateContent";
189
2
            return;
190
2
        }
191
192
        // The endpoint `v1/completions` does not support `system_prompt`.
193
        // To ensure a clear structure and stable AI results.
194
        // Convert from `v1/completions` to `v1/chat/completions`
195
30
        if (config.endpoint.ends_with("v1/completions")) {
196
0
            static constexpr std::string_view legacy_suffix = "v1/completions";
197
0
            config.endpoint.replace(config.endpoint.size() - legacy_suffix.size(),
198
0
                                    legacy_suffix.size(), "v1/chat/completions");
199
0
        }
200
30
    }
_ZN5doris10AIFunctionINS_16FunctionAIFilterEE18normalize_endpointERNS_10AIResourceE
Line
Count
Source
163
94
    static void normalize_endpoint(AIResource& config) {
164
        // 1. If users configure only the version root like `.../v1` or `.../v1beta`, append
165
        //    `models/<model>:batchEmbedContents` for `embed`, and `models/<model>:generateContent`
166
        //    for other AI scalar functions.
167
        // 2. `:embedContent` -> `:batchEmbedContents`
168
94
        if (iequal(config.provider_type, "GEMINI")) {
169
0
            if (iequal(Derived::name, "embed") && config.endpoint.ends_with(":embedContent")) {
170
0
                static constexpr std::string_view legacy_suffix = ":embedContent";
171
0
                config.endpoint.replace(config.endpoint.size() - legacy_suffix.size(),
172
0
                                        legacy_suffix.size(), ":batchEmbedContents");
173
0
                return;
174
0
            }
175
176
0
            if (!config.endpoint.ends_with("v1") && !config.endpoint.ends_with("v1beta")) {
177
0
                return;
178
0
            }
179
180
0
            std::string model_name = config.model_name;
181
0
            if (!model_name.starts_with("models/")) {
182
0
                model_name = "models/" + model_name;
183
0
            }
184
185
0
            config.endpoint += "/";
186
0
            config.endpoint += model_name;
187
0
            config.endpoint +=
188
0
                    iequal(Derived::name, "embed") ? ":batchEmbedContents" : ":generateContent";
189
0
            return;
190
0
        }
191
192
        // The endpoint `v1/completions` does not support `system_prompt`.
193
        // To ensure a clear structure and stable AI results.
194
        // Convert from `v1/completions` to `v1/chat/completions`
195
94
        if (config.endpoint.ends_with("v1/completions")) {
196
0
            static constexpr std::string_view legacy_suffix = "v1/completions";
197
0
            config.endpoint.replace(config.endpoint.size() - legacy_suffix.size(),
198
0
                                    legacy_suffix.size(), "v1/chat/completions");
199
0
        }
200
94
    }
Unexecuted instantiation: _ZN5doris10AIFunctionINS_20FunctionAIFixGrammarEE18normalize_endpointERNS_10AIResourceE
_ZN5doris10AIFunctionINS_19FunctionAISentimentEE18normalize_endpointERNS_10AIResourceE
Line
Count
Source
163
14
    static void normalize_endpoint(AIResource& config) {
164
        // 1. If users configure only the version root like `.../v1` or `.../v1beta`, append
165
        //    `models/<model>:batchEmbedContents` for `embed`, and `models/<model>:generateContent`
166
        //    for other AI scalar functions.
167
        // 2. `:embedContent` -> `:batchEmbedContents`
168
14
        if (iequal(config.provider_type, "GEMINI")) {
169
4
            if (iequal(Derived::name, "embed") && config.endpoint.ends_with(":embedContent")) {
170
0
                static constexpr std::string_view legacy_suffix = ":embedContent";
171
0
                config.endpoint.replace(config.endpoint.size() - legacy_suffix.size(),
172
0
                                        legacy_suffix.size(), ":batchEmbedContents");
173
0
                return;
174
0
            }
175
176
4
            if (!config.endpoint.ends_with("v1") && !config.endpoint.ends_with("v1beta")) {
177
2
                return;
178
2
            }
179
180
2
            std::string model_name = config.model_name;
181
2
            if (!model_name.starts_with("models/")) {
182
2
                model_name = "models/" + model_name;
183
2
            }
184
185
2
            config.endpoint += "/";
186
2
            config.endpoint += model_name;
187
2
            config.endpoint +=
188
2
                    iequal(Derived::name, "embed") ? ":batchEmbedContents" : ":generateContent";
189
2
            return;
190
4
        }
191
192
        // The endpoint `v1/completions` does not support `system_prompt`.
193
        // To ensure a clear structure and stable AI results.
194
        // Convert from `v1/completions` to `v1/chat/completions`
195
10
        if (config.endpoint.ends_with("v1/completions")) {
196
2
            static constexpr std::string_view legacy_suffix = "v1/completions";
197
2
            config.endpoint.replace(config.endpoint.size() - legacy_suffix.size(),
198
2
                                    legacy_suffix.size(), "v1/chat/completions");
199
2
        }
200
10
    }
_ZN5doris10AIFunctionINS_19FunctionAISummarizeEE18normalize_endpointERNS_10AIResourceE
Line
Count
Source
163
14
    static void normalize_endpoint(AIResource& config) {
164
        // 1. If users configure only the version root like `.../v1` or `.../v1beta`, append
165
        //    `models/<model>:batchEmbedContents` for `embed`, and `models/<model>:generateContent`
166
        //    for other AI scalar functions.
167
        // 2. `:embedContent` -> `:batchEmbedContents`
168
14
        if (iequal(config.provider_type, "GEMINI")) {
169
0
            if (iequal(Derived::name, "embed") && config.endpoint.ends_with(":embedContent")) {
170
0
                static constexpr std::string_view legacy_suffix = ":embedContent";
171
0
                config.endpoint.replace(config.endpoint.size() - legacy_suffix.size(),
172
0
                                        legacy_suffix.size(), ":batchEmbedContents");
173
0
                return;
174
0
            }
175
176
0
            if (!config.endpoint.ends_with("v1") && !config.endpoint.ends_with("v1beta")) {
177
0
                return;
178
0
            }
179
180
0
            std::string model_name = config.model_name;
181
0
            if (!model_name.starts_with("models/")) {
182
0
                model_name = "models/" + model_name;
183
0
            }
184
185
0
            config.endpoint += "/";
186
0
            config.endpoint += model_name;
187
0
            config.endpoint +=
188
0
                    iequal(Derived::name, "embed") ? ":batchEmbedContents" : ":generateContent";
189
0
            return;
190
0
        }
191
192
        // The endpoint `v1/completions` does not support `system_prompt`.
193
        // To ensure a clear structure and stable AI results.
194
        // Convert from `v1/completions` to `v1/chat/completions`
195
14
        if (config.endpoint.ends_with("v1/completions")) {
196
0
            static constexpr std::string_view legacy_suffix = "v1/completions";
197
0
            config.endpoint.replace(config.endpoint.size() - legacy_suffix.size(),
198
0
                                    legacy_suffix.size(), "v1/chat/completions");
199
0
        }
200
14
    }
_ZN5doris10AIFunctionINS_18FunctionAIClassifyEE18normalize_endpointERNS_10AIResourceE
Line
Count
Source
163
4
    static void normalize_endpoint(AIResource& config) {
164
        // 1. If users configure only the version root like `.../v1` or `.../v1beta`, append
165
        //    `models/<model>:batchEmbedContents` for `embed`, and `models/<model>:generateContent`
166
        //    for other AI scalar functions.
167
        // 2. `:embedContent` -> `:batchEmbedContents`
168
4
        if (iequal(config.provider_type, "GEMINI")) {
169
0
            if (iequal(Derived::name, "embed") && config.endpoint.ends_with(":embedContent")) {
170
0
                static constexpr std::string_view legacy_suffix = ":embedContent";
171
0
                config.endpoint.replace(config.endpoint.size() - legacy_suffix.size(),
172
0
                                        legacy_suffix.size(), ":batchEmbedContents");
173
0
                return;
174
0
            }
175
176
0
            if (!config.endpoint.ends_with("v1") && !config.endpoint.ends_with("v1beta")) {
177
0
                return;
178
0
            }
179
180
0
            std::string model_name = config.model_name;
181
0
            if (!model_name.starts_with("models/")) {
182
0
                model_name = "models/" + model_name;
183
0
            }
184
185
0
            config.endpoint += "/";
186
0
            config.endpoint += model_name;
187
0
            config.endpoint +=
188
0
                    iequal(Derived::name, "embed") ? ":batchEmbedContents" : ":generateContent";
189
0
            return;
190
0
        }
191
192
        // The endpoint `v1/completions` does not support `system_prompt`.
193
        // To ensure a clear structure and stable AI results.
194
        // Convert from `v1/completions` to `v1/chat/completions`
195
4
        if (config.endpoint.ends_with("v1/completions")) {
196
0
            static constexpr std::string_view legacy_suffix = "v1/completions";
197
0
            config.endpoint.replace(config.endpoint.size() - legacy_suffix.size(),
198
0
                                    legacy_suffix.size(), "v1/chat/completions");
199
0
        }
200
4
    }
Unexecuted instantiation: _ZN5doris10AIFunctionINS_17FunctionAIExtractEE18normalize_endpointERNS_10AIResourceE
_ZN5doris10AIFunctionINS_18FunctionAIGenerateEE18normalize_endpointERNS_10AIResourceE
Line
Count
Source
163
6
    static void normalize_endpoint(AIResource& config) {
164
        // 1. If users configure only the version root like `.../v1` or `.../v1beta`, append
165
        //    `models/<model>:batchEmbedContents` for `embed`, and `models/<model>:generateContent`
166
        //    for other AI scalar functions.
167
        // 2. `:embedContent` -> `:batchEmbedContents`
168
6
        if (iequal(config.provider_type, "GEMINI")) {
169
0
            if (iequal(Derived::name, "embed") && config.endpoint.ends_with(":embedContent")) {
170
0
                static constexpr std::string_view legacy_suffix = ":embedContent";
171
0
                config.endpoint.replace(config.endpoint.size() - legacy_suffix.size(),
172
0
                                        legacy_suffix.size(), ":batchEmbedContents");
173
0
                return;
174
0
            }
175
176
0
            if (!config.endpoint.ends_with("v1") && !config.endpoint.ends_with("v1beta")) {
177
0
                return;
178
0
            }
179
180
0
            std::string model_name = config.model_name;
181
0
            if (!model_name.starts_with("models/")) {
182
0
                model_name = "models/" + model_name;
183
0
            }
184
185
0
            config.endpoint += "/";
186
0
            config.endpoint += model_name;
187
0
            config.endpoint +=
188
0
                    iequal(Derived::name, "embed") ? ":batchEmbedContents" : ":generateContent";
189
0
            return;
190
0
        }
191
192
        // The endpoint `v1/completions` does not support `system_prompt`.
193
        // To ensure a clear structure and stable AI results.
194
        // Convert from `v1/completions` to `v1/chat/completions`
195
6
        if (config.endpoint.ends_with("v1/completions")) {
196
0
            static constexpr std::string_view legacy_suffix = "v1/completions";
197
0
            config.endpoint.replace(config.endpoint.size() - legacy_suffix.size(),
198
0
                                    legacy_suffix.size(), "v1/chat/completions");
199
0
        }
200
6
    }
Unexecuted instantiation: _ZN5doris10AIFunctionINS_14FunctionAIMaskEE18normalize_endpointERNS_10AIResourceE
_ZN5doris10AIFunctionINS_20FunctionAISimilarityEE18normalize_endpointERNS_10AIResourceE
Line
Count
Source
163
44
    static void normalize_endpoint(AIResource& config) {
164
        // 1. If users configure only the version root like `.../v1` or `.../v1beta`, append
165
        //    `models/<model>:batchEmbedContents` for `embed`, and `models/<model>:generateContent`
166
        //    for other AI scalar functions.
167
        // 2. `:embedContent` -> `:batchEmbedContents`
168
44
        if (iequal(config.provider_type, "GEMINI")) {
169
0
            if (iequal(Derived::name, "embed") && config.endpoint.ends_with(":embedContent")) {
170
0
                static constexpr std::string_view legacy_suffix = ":embedContent";
171
0
                config.endpoint.replace(config.endpoint.size() - legacy_suffix.size(),
172
0
                                        legacy_suffix.size(), ":batchEmbedContents");
173
0
                return;
174
0
            }
175
176
0
            if (!config.endpoint.ends_with("v1") && !config.endpoint.ends_with("v1beta")) {
177
0
                return;
178
0
            }
179
180
0
            std::string model_name = config.model_name;
181
0
            if (!model_name.starts_with("models/")) {
182
0
                model_name = "models/" + model_name;
183
0
            }
184
185
0
            config.endpoint += "/";
186
0
            config.endpoint += model_name;
187
0
            config.endpoint +=
188
0
                    iequal(Derived::name, "embed") ? ":batchEmbedContents" : ":generateContent";
189
0
            return;
190
0
        }
191
192
        // The endpoint `v1/completions` does not support `system_prompt`.
193
        // To ensure a clear structure and stable AI results.
194
        // Convert from `v1/completions` to `v1/chat/completions`
195
44
        if (config.endpoint.ends_with("v1/completions")) {
196
0
            static constexpr std::string_view legacy_suffix = "v1/completions";
197
0
            config.endpoint.replace(config.endpoint.size() - legacy_suffix.size(),
198
0
                                    legacy_suffix.size(), "v1/chat/completions");
199
0
        }
200
44
    }
Unexecuted instantiation: _ZN5doris10AIFunctionINS_19FunctionAITranslateEE18normalize_endpointERNS_10AIResourceE
201
202
1.00k
    static AIRequestExecutor* get_executor(FunctionContext* context) {
203
        // Retain the cache across batches/Blocks, including Blocks with only NULL inputs.
204
1.00k
        auto* executor = static_cast<AIRequestExecutor*>(
205
1.00k
                context->get_function_state(FunctionContext::FunctionStateScope::THREAD_LOCAL));
206
1.00k
        if (executor == nullptr) {
207
132
            auto* runtime_state = context->state();
208
            // Disabled profiles need the connection cache, but no statistics owner.
209
132
            auto statistics = runtime_state->enable_profile()
210
132
                                      ? runtime_state->get_query_ctx()->get_ai_statistics(
211
24
                                                runtime_state->fragment_id())
212
132
                                      : nullptr;
213
132
            auto state = std::make_shared<AIRequestExecutor>(std::move(statistics));
214
132
            executor = state.get();
215
132
            context->set_function_state(FunctionContext::FunctionStateScope::THREAD_LOCAL,
216
132
                                        std::move(state));
217
132
        }
218
1.00k
        return executor;
219
1.00k
    }
_ZN5doris10AIFunctionINS_13FunctionEmbedEE12get_executorEPNS_15FunctionContextE
Line
Count
Source
202
224
    static AIRequestExecutor* get_executor(FunctionContext* context) {
203
        // Retain the cache across batches/Blocks, including Blocks with only NULL inputs.
204
224
        auto* executor = static_cast<AIRequestExecutor*>(
205
224
                context->get_function_state(FunctionContext::FunctionStateScope::THREAD_LOCAL));
206
224
        if (executor == nullptr) {
207
52
            auto* runtime_state = context->state();
208
            // Disabled profiles need the connection cache, but no statistics owner.
209
52
            auto statistics = runtime_state->enable_profile()
210
52
                                      ? runtime_state->get_query_ctx()->get_ai_statistics(
211
10
                                                runtime_state->fragment_id())
212
52
                                      : nullptr;
213
52
            auto state = std::make_shared<AIRequestExecutor>(std::move(statistics));
214
52
            executor = state.get();
215
52
            context->set_function_state(FunctionContext::FunctionStateScope::THREAD_LOCAL,
216
52
                                        std::move(state));
217
52
        }
218
224
        return executor;
219
224
    }
_ZN5doris10AIFunctionINS_16FunctionAIFilterEE12get_executorEPNS_15FunctionContextE
Line
Count
Source
202
380
    static AIRequestExecutor* get_executor(FunctionContext* context) {
203
        // Retain the cache across batches/Blocks, including Blocks with only NULL inputs.
204
380
        auto* executor = static_cast<AIRequestExecutor*>(
205
380
                context->get_function_state(FunctionContext::FunctionStateScope::THREAD_LOCAL));
206
380
        if (executor == nullptr) {
207
26
            auto* runtime_state = context->state();
208
            // Disabled profiles need the connection cache, but no statistics owner.
209
26
            auto statistics = runtime_state->enable_profile()
210
26
                                      ? runtime_state->get_query_ctx()->get_ai_statistics(
211
0
                                                runtime_state->fragment_id())
212
26
                                      : nullptr;
213
26
            auto state = std::make_shared<AIRequestExecutor>(std::move(statistics));
214
26
            executor = state.get();
215
26
            context->set_function_state(FunctionContext::FunctionStateScope::THREAD_LOCAL,
216
26
                                        std::move(state));
217
26
        }
218
380
        return executor;
219
380
    }
Unexecuted instantiation: _ZN5doris10AIFunctionINS_20FunctionAIFixGrammarEE12get_executorEPNS_15FunctionContextE
_ZN5doris10AIFunctionINS_19FunctionAISentimentEE12get_executorEPNS_15FunctionContextE
Line
Count
Source
202
20
    static AIRequestExecutor* get_executor(FunctionContext* context) {
203
        // Retain the cache across batches/Blocks, including Blocks with only NULL inputs.
204
20
        auto* executor = static_cast<AIRequestExecutor*>(
205
20
                context->get_function_state(FunctionContext::FunctionStateScope::THREAD_LOCAL));
206
20
        if (executor == nullptr) {
207
10
            auto* runtime_state = context->state();
208
            // Disabled profiles need the connection cache, but no statistics owner.
209
10
            auto statistics = runtime_state->enable_profile()
210
10
                                      ? runtime_state->get_query_ctx()->get_ai_statistics(
211
0
                                                runtime_state->fragment_id())
212
10
                                      : nullptr;
213
10
            auto state = std::make_shared<AIRequestExecutor>(std::move(statistics));
214
10
            executor = state.get();
215
10
            context->set_function_state(FunctionContext::FunctionStateScope::THREAD_LOCAL,
216
10
                                        std::move(state));
217
10
        }
218
20
        return executor;
219
20
    }
_ZN5doris10AIFunctionINS_19FunctionAISummarizeEE12get_executorEPNS_15FunctionContextE
Line
Count
Source
202
170
    static AIRequestExecutor* get_executor(FunctionContext* context) {
203
        // Retain the cache across batches/Blocks, including Blocks with only NULL inputs.
204
170
        auto* executor = static_cast<AIRequestExecutor*>(
205
170
                context->get_function_state(FunctionContext::FunctionStateScope::THREAD_LOCAL));
206
170
        if (executor == nullptr) {
207
22
            auto* runtime_state = context->state();
208
            // Disabled profiles need the connection cache, but no statistics owner.
209
22
            auto statistics = runtime_state->enable_profile()
210
22
                                      ? runtime_state->get_query_ctx()->get_ai_statistics(
211
6
                                                runtime_state->fragment_id())
212
22
                                      : nullptr;
213
22
            auto state = std::make_shared<AIRequestExecutor>(std::move(statistics));
214
22
            executor = state.get();
215
22
            context->set_function_state(FunctionContext::FunctionStateScope::THREAD_LOCAL,
216
22
                                        std::move(state));
217
22
        }
218
170
        return executor;
219
170
    }
_ZN5doris10AIFunctionINS_18FunctionAIClassifyEE12get_executorEPNS_15FunctionContextE
Line
Count
Source
202
16
    static AIRequestExecutor* get_executor(FunctionContext* context) {
203
        // Retain the cache across batches/Blocks, including Blocks with only NULL inputs.
204
16
        auto* executor = static_cast<AIRequestExecutor*>(
205
16
                context->get_function_state(FunctionContext::FunctionStateScope::THREAD_LOCAL));
206
16
        if (executor == nullptr) {
207
4
            auto* runtime_state = context->state();
208
            // Disabled profiles need the connection cache, but no statistics owner.
209
4
            auto statistics = runtime_state->enable_profile()
210
4
                                      ? runtime_state->get_query_ctx()->get_ai_statistics(
211
0
                                                runtime_state->fragment_id())
212
4
                                      : nullptr;
213
4
            auto state = std::make_shared<AIRequestExecutor>(std::move(statistics));
214
4
            executor = state.get();
215
4
            context->set_function_state(FunctionContext::FunctionStateScope::THREAD_LOCAL,
216
4
                                        std::move(state));
217
4
        }
218
16
        return executor;
219
16
    }
Unexecuted instantiation: _ZN5doris10AIFunctionINS_17FunctionAIExtractEE12get_executorEPNS_15FunctionContextE
_ZN5doris10AIFunctionINS_18FunctionAIGenerateEE12get_executorEPNS_15FunctionContextE
Line
Count
Source
202
22
    static AIRequestExecutor* get_executor(FunctionContext* context) {
203
        // Retain the cache across batches/Blocks, including Blocks with only NULL inputs.
204
22
        auto* executor = static_cast<AIRequestExecutor*>(
205
22
                context->get_function_state(FunctionContext::FunctionStateScope::THREAD_LOCAL));
206
22
        if (executor == nullptr) {
207
8
            auto* runtime_state = context->state();
208
            // Disabled profiles need the connection cache, but no statistics owner.
209
8
            auto statistics = runtime_state->enable_profile()
210
8
                                      ? runtime_state->get_query_ctx()->get_ai_statistics(
211
4
                                                runtime_state->fragment_id())
212
8
                                      : nullptr;
213
8
            auto state = std::make_shared<AIRequestExecutor>(std::move(statistics));
214
8
            executor = state.get();
215
8
            context->set_function_state(FunctionContext::FunctionStateScope::THREAD_LOCAL,
216
8
                                        std::move(state));
217
8
        }
218
22
        return executor;
219
22
    }
Unexecuted instantiation: _ZN5doris10AIFunctionINS_14FunctionAIMaskEE12get_executorEPNS_15FunctionContextE
_ZN5doris10AIFunctionINS_20FunctionAISimilarityEE12get_executorEPNS_15FunctionContextE
Line
Count
Source
202
176
    static AIRequestExecutor* get_executor(FunctionContext* context) {
203
        // Retain the cache across batches/Blocks, including Blocks with only NULL inputs.
204
176
        auto* executor = static_cast<AIRequestExecutor*>(
205
176
                context->get_function_state(FunctionContext::FunctionStateScope::THREAD_LOCAL));
206
176
        if (executor == nullptr) {
207
10
            auto* runtime_state = context->state();
208
            // Disabled profiles need the connection cache, but no statistics owner.
209
10
            auto statistics = runtime_state->enable_profile()
210
10
                                      ? runtime_state->get_query_ctx()->get_ai_statistics(
211
4
                                                runtime_state->fragment_id())
212
10
                                      : nullptr;
213
10
            auto state = std::make_shared<AIRequestExecutor>(std::move(statistics));
214
10
            executor = state.get();
215
10
            context->set_function_state(FunctionContext::FunctionStateScope::THREAD_LOCAL,
216
10
                                        std::move(state));
217
10
        }
218
176
        return executor;
219
176
    }
Unexecuted instantiation: _ZN5doris10AIFunctionINS_19FunctionAITranslateEE12get_executorEPNS_15FunctionContextE
220
221
    static void record_input(FunctionContext* context, size_t rows,
222
234
                             const ColumnUInt8::MutablePtr& null_map) {
223
234
        if (const auto& statistics = get_executor(context)->statistics()) {
224
54
            const int64_t skipped = null_map ? std::count_if(null_map->get_data().begin(),
225
32
                                                             null_map->get_data().end(),
226
98
                                                             [](UInt8 value) { return value != 0; })
_ZZN5doris10AIFunctionINS_13FunctionEmbedEE12record_inputEPNS_15FunctionContextEmRKNS_3COWINS_7IColumnEE11mutable_ptrINS_12ColumnVectorILNS_13PrimitiveTypeE2EEEEEENKUlhE_clEh
Line
Count
Source
226
54
                                                             [](UInt8 value) { return value != 0; })
Unexecuted instantiation: _ZZN5doris10AIFunctionINS_16FunctionAIFilterEE12record_inputEPNS_15FunctionContextEmRKNS_3COWINS_7IColumnEE11mutable_ptrINS_12ColumnVectorILNS_13PrimitiveTypeE2EEEEEENKUlhE_clEh
Unexecuted instantiation: _ZZN5doris10AIFunctionINS_20FunctionAIFixGrammarEE12record_inputEPNS_15FunctionContextEmRKNS_3COWINS_7IColumnEE11mutable_ptrINS_12ColumnVectorILNS_13PrimitiveTypeE2EEEEEENKUlhE_clEh
Unexecuted instantiation: _ZZN5doris10AIFunctionINS_19FunctionAISentimentEE12record_inputEPNS_15FunctionContextEmRKNS_3COWINS_7IColumnEE11mutable_ptrINS_12ColumnVectorILNS_13PrimitiveTypeE2EEEEEENKUlhE_clEh
_ZZN5doris10AIFunctionINS_19FunctionAISummarizeEE12record_inputEPNS_15FunctionContextEmRKNS_3COWINS_7IColumnEE11mutable_ptrINS_12ColumnVectorILNS_13PrimitiveTypeE2EEEEEENKUlhE_clEh
Line
Count
Source
226
34
                                                             [](UInt8 value) { return value != 0; })
Unexecuted instantiation: _ZZN5doris10AIFunctionINS_18FunctionAIClassifyEE12record_inputEPNS_15FunctionContextEmRKNS_3COWINS_7IColumnEE11mutable_ptrINS_12ColumnVectorILNS_13PrimitiveTypeE2EEEEEENKUlhE_clEh
Unexecuted instantiation: _ZZN5doris10AIFunctionINS_17FunctionAIExtractEE12record_inputEPNS_15FunctionContextEmRKNS_3COWINS_7IColumnEE11mutable_ptrINS_12ColumnVectorILNS_13PrimitiveTypeE2EEEEEENKUlhE_clEh
_ZZN5doris10AIFunctionINS_18FunctionAIGenerateEE12record_inputEPNS_15FunctionContextEmRKNS_3COWINS_7IColumnEE11mutable_ptrINS_12ColumnVectorILNS_13PrimitiveTypeE2EEEEEENKUlhE_clEh
Line
Count
Source
226
2
                                                             [](UInt8 value) { return value != 0; })
Unexecuted instantiation: _ZZN5doris10AIFunctionINS_14FunctionAIMaskEE12record_inputEPNS_15FunctionContextEmRKNS_3COWINS_7IColumnEE11mutable_ptrINS_12ColumnVectorILNS_13PrimitiveTypeE2EEEEEENKUlhE_clEh
_ZZN5doris10AIFunctionINS_20FunctionAISimilarityEE12record_inputEPNS_15FunctionContextEmRKNS_3COWINS_7IColumnEE11mutable_ptrINS_12ColumnVectorILNS_13PrimitiveTypeE2EEEEEENKUlhE_clEh
Line
Count
Source
226
8
                                                             [](UInt8 value) { return value != 0; })
Unexecuted instantiation: _ZZN5doris10AIFunctionINS_19FunctionAITranslateEE12record_inputEPNS_15FunctionContextEmRKNS_3COWINS_7IColumnEE11mutable_ptrINS_12ColumnVectorILNS_13PrimitiveTypeE2EEEEEENKUlhE_clEh
227
54
                                             : 0;
228
54
            statistics->record_input(rows, skipped);
229
54
        }
230
234
    }
_ZN5doris10AIFunctionINS_13FunctionEmbedEE12record_inputEPNS_15FunctionContextEmRKNS_3COWINS_7IColumnEE11mutable_ptrINS_12ColumnVectorILNS_13PrimitiveTypeE2EEEEE
Line
Count
Source
222
56
                             const ColumnUInt8::MutablePtr& null_map) {
223
56
        if (const auto& statistics = get_executor(context)->statistics()) {
224
26
            const int64_t skipped = null_map ? std::count_if(null_map->get_data().begin(),
225
16
                                                             null_map->get_data().end(),
226
16
                                                             [](UInt8 value) { return value != 0; })
227
26
                                             : 0;
228
26
            statistics->record_input(rows, skipped);
229
26
        }
230
56
    }
_ZN5doris10AIFunctionINS_16FunctionAIFilterEE12record_inputEPNS_15FunctionContextEmRKNS_3COWINS_7IColumnEE11mutable_ptrINS_12ColumnVectorILNS_13PrimitiveTypeE2EEEEE
Line
Count
Source
222
94
                             const ColumnUInt8::MutablePtr& null_map) {
223
94
        if (const auto& statistics = get_executor(context)->statistics()) {
224
0
            const int64_t skipped = null_map ? std::count_if(null_map->get_data().begin(),
225
0
                                                             null_map->get_data().end(),
226
0
                                                             [](UInt8 value) { return value != 0; })
227
0
                                             : 0;
228
0
            statistics->record_input(rows, skipped);
229
0
        }
230
94
    }
Unexecuted instantiation: _ZN5doris10AIFunctionINS_20FunctionAIFixGrammarEE12record_inputEPNS_15FunctionContextEmRKNS_3COWINS_7IColumnEE11mutable_ptrINS_12ColumnVectorILNS_13PrimitiveTypeE2EEEEE
_ZN5doris10AIFunctionINS_19FunctionAISentimentEE12record_inputEPNS_15FunctionContextEmRKNS_3COWINS_7IColumnEE11mutable_ptrINS_12ColumnVectorILNS_13PrimitiveTypeE2EEEEE
Line
Count
Source
222
4
                             const ColumnUInt8::MutablePtr& null_map) {
223
4
        if (const auto& statistics = get_executor(context)->statistics()) {
224
0
            const int64_t skipped = null_map ? std::count_if(null_map->get_data().begin(),
225
0
                                                             null_map->get_data().end(),
226
0
                                                             [](UInt8 value) { return value != 0; })
227
0
                                             : 0;
228
0
            statistics->record_input(rows, skipped);
229
0
        }
230
4
    }
_ZN5doris10AIFunctionINS_19FunctionAISummarizeEE12record_inputEPNS_15FunctionContextEmRKNS_3COWINS_7IColumnEE11mutable_ptrINS_12ColumnVectorILNS_13PrimitiveTypeE2EEEEE
Line
Count
Source
222
26
                             const ColumnUInt8::MutablePtr& null_map) {
223
26
        if (const auto& statistics = get_executor(context)->statistics()) {
224
12
            const int64_t skipped = null_map ? std::count_if(null_map->get_data().begin(),
225
12
                                                             null_map->get_data().end(),
226
12
                                                             [](UInt8 value) { return value != 0; })
227
12
                                             : 0;
228
12
            statistics->record_input(rows, skipped);
229
12
        }
230
26
    }
_ZN5doris10AIFunctionINS_18FunctionAIClassifyEE12record_inputEPNS_15FunctionContextEmRKNS_3COWINS_7IColumnEE11mutable_ptrINS_12ColumnVectorILNS_13PrimitiveTypeE2EEEEE
Line
Count
Source
222
4
                             const ColumnUInt8::MutablePtr& null_map) {
223
4
        if (const auto& statistics = get_executor(context)->statistics()) {
224
0
            const int64_t skipped = null_map ? std::count_if(null_map->get_data().begin(),
225
0
                                                             null_map->get_data().end(),
226
0
                                                             [](UInt8 value) { return value != 0; })
227
0
                                             : 0;
228
0
            statistics->record_input(rows, skipped);
229
0
        }
230
4
    }
Unexecuted instantiation: _ZN5doris10AIFunctionINS_17FunctionAIExtractEE12record_inputEPNS_15FunctionContextEmRKNS_3COWINS_7IColumnEE11mutable_ptrINS_12ColumnVectorILNS_13PrimitiveTypeE2EEEEE
_ZN5doris10AIFunctionINS_18FunctionAIGenerateEE12record_inputEPNS_15FunctionContextEmRKNS_3COWINS_7IColumnEE11mutable_ptrINS_12ColumnVectorILNS_13PrimitiveTypeE2EEEEE
Line
Count
Source
222
6
                             const ColumnUInt8::MutablePtr& null_map) {
223
6
        if (const auto& statistics = get_executor(context)->statistics()) {
224
2
            const int64_t skipped = null_map ? std::count_if(null_map->get_data().begin(),
225
2
                                                             null_map->get_data().end(),
226
2
                                                             [](UInt8 value) { return value != 0; })
227
2
                                             : 0;
228
2
            statistics->record_input(rows, skipped);
229
2
        }
230
6
    }
Unexecuted instantiation: _ZN5doris10AIFunctionINS_14FunctionAIMaskEE12record_inputEPNS_15FunctionContextEmRKNS_3COWINS_7IColumnEE11mutable_ptrINS_12ColumnVectorILNS_13PrimitiveTypeE2EEEEE
_ZN5doris10AIFunctionINS_20FunctionAISimilarityEE12record_inputEPNS_15FunctionContextEmRKNS_3COWINS_7IColumnEE11mutable_ptrINS_12ColumnVectorILNS_13PrimitiveTypeE2EEEEE
Line
Count
Source
222
44
                             const ColumnUInt8::MutablePtr& null_map) {
223
44
        if (const auto& statistics = get_executor(context)->statistics()) {
224
14
            const int64_t skipped = null_map ? std::count_if(null_map->get_data().begin(),
225
2
                                                             null_map->get_data().end(),
226
2
                                                             [](UInt8 value) { return value != 0; })
227
14
                                             : 0;
228
14
            statistics->record_input(rows, skipped);
229
14
        }
230
44
    }
Unexecuted instantiation: _ZN5doris10AIFunctionINS_19FunctionAITranslateEE12record_inputEPNS_15FunctionContextEmRKNS_3COWINS_7IColumnEE11mutable_ptrINS_12ColumnVectorILNS_13PrimitiveTypeE2EEEEE
231
232
    Status send_request_to_llm(const std::string& request_body, std::string& response,
233
                               const AIResource& config, std::shared_ptr<AIAdapter>& adapter,
234
134
                               FunctionContext* context) const {
235
134
        return get_executor(context)->execute(request_body, response, config, *adapter,
236
134
                                              context->state()->get_query_ctx());
237
134
    }
_ZNK5doris10AIFunctionINS_13FunctionEmbedEE19send_request_to_llmERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERS8_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextE
Line
Count
Source
234
74
                               FunctionContext* context) const {
235
74
        return get_executor(context)->execute(request_body, response, config, *adapter,
236
74
                                              context->state()->get_query_ctx());
237
74
    }
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_16FunctionAIFilterEE19send_request_to_llmERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERS8_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextE
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_20FunctionAIFixGrammarEE19send_request_to_llmERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERS8_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextE
_ZNK5doris10AIFunctionINS_19FunctionAISentimentEE19send_request_to_llmERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERS8_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextE
Line
Count
Source
234
6
                               FunctionContext* context) const {
235
6
        return get_executor(context)->execute(request_body, response, config, *adapter,
236
6
                                              context->state()->get_query_ctx());
237
6
    }
_ZNK5doris10AIFunctionINS_19FunctionAISummarizeEE19send_request_to_llmERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERS8_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextE
Line
Count
Source
234
54
                               FunctionContext* context) const {
235
54
        return get_executor(context)->execute(request_body, response, config, *adapter,
236
54
                                              context->state()->get_query_ctx());
237
54
    }
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_18FunctionAIClassifyEE19send_request_to_llmERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERS8_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextE
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_17FunctionAIExtractEE19send_request_to_llmERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERS8_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextE
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_18FunctionAIGenerateEE19send_request_to_llmERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERS8_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextE
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_14FunctionAIMaskEE19send_request_to_llmERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERS8_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextE
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_20FunctionAISimilarityEE19send_request_to_llmERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERS8_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextE
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_19FunctionAITranslateEE19send_request_to_llmERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERS8_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextE
238
239
    // Provider-reusable helper for string-returning functions.
240
    // Estimates one batch entry size using the raw prompt length plus the fixed JSON wrapper cost.
241
234
    size_t estimate_batch_entry_size(size_t idx, const std::string& prompt) const {
242
234
        static constexpr size_t json_wrapper_size = 20;
243
234
        return prompt.size() + std::to_string(idx).size() + json_wrapper_size;
244
234
    }
_ZNK5doris10AIFunctionINS_16FunctionAIFilterEE25estimate_batch_entry_sizeEmRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
241
128
    size_t estimate_batch_entry_size(size_t idx, const std::string& prompt) const {
242
128
        static constexpr size_t json_wrapper_size = 20;
243
128
        return prompt.size() + std::to_string(idx).size() + json_wrapper_size;
244
128
    }
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_20FunctionAIFixGrammarEE25estimate_batch_entry_sizeEmRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
_ZNK5doris10AIFunctionINS_19FunctionAISentimentEE25estimate_batch_entry_sizeEmRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
241
8
    size_t estimate_batch_entry_size(size_t idx, const std::string& prompt) const {
242
8
        static constexpr size_t json_wrapper_size = 20;
243
8
        return prompt.size() + std::to_string(idx).size() + json_wrapper_size;
244
8
    }
_ZNK5doris10AIFunctionINS_19FunctionAISummarizeEE25estimate_batch_entry_sizeEmRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
241
34
    size_t estimate_batch_entry_size(size_t idx, const std::string& prompt) const {
242
34
        static constexpr size_t json_wrapper_size = 20;
243
34
        return prompt.size() + std::to_string(idx).size() + json_wrapper_size;
244
34
    }
_ZNK5doris10AIFunctionINS_18FunctionAIClassifyEE25estimate_batch_entry_sizeEmRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
241
4
    size_t estimate_batch_entry_size(size_t idx, const std::string& prompt) const {
242
4
        static constexpr size_t json_wrapper_size = 20;
243
4
        return prompt.size() + std::to_string(idx).size() + json_wrapper_size;
244
4
    }
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_17FunctionAIExtractEE25estimate_batch_entry_sizeEmRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
_ZNK5doris10AIFunctionINS_18FunctionAIGenerateEE25estimate_batch_entry_sizeEmRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
241
10
    size_t estimate_batch_entry_size(size_t idx, const std::string& prompt) const {
242
10
        static constexpr size_t json_wrapper_size = 20;
243
10
        return prompt.size() + std::to_string(idx).size() + json_wrapper_size;
244
10
    }
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_14FunctionAIMaskEE25estimate_batch_entry_sizeEmRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
_ZNK5doris10AIFunctionINS_20FunctionAISimilarityEE25estimate_batch_entry_sizeEmRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
241
50
    size_t estimate_batch_entry_size(size_t idx, const std::string& prompt) const {
242
50
        static constexpr size_t json_wrapper_size = 20;
243
50
        return prompt.size() + std::to_string(idx).size() + json_wrapper_size;
244
50
    }
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_19FunctionAITranslateEE25estimate_batch_entry_sizeEmRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
245
246
    // Provider-reusable helper for string-returning functions.
247
    // Executes one batch request and parses the provider result into one string per input row.
248
    Status execute_batch_request(const std::vector<std::string>& batch_prompts,
249
                                 std::vector<std::string>& results, const AIResource& config,
250
                                 std::shared_ptr<AIAdapter>& adapter,
251
14
                                 FunctionContext* context) const {
252
#ifdef BE_TEST
253
        const char* test_result = std::getenv("AI_TEST_RESULT");
254
        if (test_result != nullptr) {
255
            const auto& statistics = get_executor(context)->statistics();
256
            const auto parse_start = statistics ? MonotonicNanos() : 0;
257
            bool parse_failed = true;
258
            Defer record_parse([&] {
259
                if (statistics) {
260
                    statistics->record_parse(MonotonicNanos() - parse_start, parse_failed);
261
                }
262
            });
263
            std::vector<std::string> parsed_test_response;
264
            RETURN_IF_ERROR(
265
                    adapter->parse_response(std::string(test_result), parsed_test_response));
266
            if (parsed_test_response.empty()) {
267
                return Status::InternalError("AI returned empty result");
268
            }
269
            if (parsed_test_response.size() != batch_prompts.size()) {
270
                return Status::RuntimeError(
271
                        "Failed to parse {} batch result, expected {} items but got {}", get_name(),
272
                        batch_prompts.size(), parsed_test_response.size());
273
            }
274
            results = std::move(parsed_test_response);
275
            parse_failed = false;
276
            return Status::OK();
277
        }
278
        if (config.provider_type == "MOCK") {
279
            results.clear();
280
            results.reserve(batch_prompts.size());
281
            for (const auto& prompt : batch_prompts) {
282
                results.emplace_back("this is a mock response. " + prompt);
283
            }
284
            return Status::OK();
285
        }
286
#endif
287
288
14
        std::string batch_prompt;
289
14
        RETURN_IF_ERROR(build_batch_prompt(batch_prompts, batch_prompt));
290
291
14
        std::vector<std::string> inputs = {batch_prompt};
292
14
        std::vector<std::string> parsed_response;
293
294
14
        std::string request_body;
295
        // Disabling provider format constraints keeps batching and the output protocol intact.
296
14
        RETURN_IF_ERROR(adapter->build_request_payload(
297
14
                inputs, batch_system_prompt(adapter->supports_structured_batch()), request_body,
298
14
                config.enable_structured_output && adapter->supports_structured_batch()));
299
300
14
        std::string response;
301
14
        RETURN_IF_ERROR(send_request_to_llm(request_body, response, config, adapter, context));
302
14
        const auto& statistics = get_executor(context)->statistics();
303
14
        const auto parse_start = statistics ? MonotonicNanos() : 0;
304
14
        bool parse_failed = true;
305
170
        Defer record_parse([&] {
306
170
            if (statistics) {
307
14
                statistics->record_parse(MonotonicNanos() - parse_start, parse_failed);
308
14
            }
309
170
        });
_ZZNK5doris10AIFunctionINS_16FunctionAIFilterEE21execute_batch_requestERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERSB_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextEENKUlvE_clEv
Line
Count
Source
305
102
        Defer record_parse([&] {
306
102
            if (statistics) {
307
0
                statistics->record_parse(MonotonicNanos() - parse_start, parse_failed);
308
0
            }
309
102
        });
Unexecuted instantiation: _ZZNK5doris10AIFunctionINS_20FunctionAIFixGrammarEE21execute_batch_requestERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERSB_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextEENKUlvE_clEv
_ZZNK5doris10AIFunctionINS_19FunctionAISentimentEE21execute_batch_requestERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERSB_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextEENKUlvE_clEv
Line
Count
Source
305
2
        Defer record_parse([&] {
306
2
            if (statistics) {
307
0
                statistics->record_parse(MonotonicNanos() - parse_start, parse_failed);
308
0
            }
309
2
        });
_ZZNK5doris10AIFunctionINS_19FunctionAISummarizeEE21execute_batch_requestERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERSB_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextEENKUlvE_clEv
Line
Count
Source
305
14
        Defer record_parse([&] {
306
14
            if (statistics) {
307
0
                statistics->record_parse(MonotonicNanos() - parse_start, parse_failed);
308
0
            }
309
14
        });
_ZZNK5doris10AIFunctionINS_18FunctionAIClassifyEE21execute_batch_requestERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERSB_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextEENKUlvE_clEv
Line
Count
Source
305
4
        Defer record_parse([&] {
306
4
            if (statistics) {
307
0
                statistics->record_parse(MonotonicNanos() - parse_start, parse_failed);
308
0
            }
309
4
        });
Unexecuted instantiation: _ZZNK5doris10AIFunctionINS_17FunctionAIExtractEE21execute_batch_requestERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERSB_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextEENKUlvE_clEv
_ZZNK5doris10AIFunctionINS_18FunctionAIGenerateEE21execute_batch_requestERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERSB_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextEENKUlvE_clEv
Line
Count
Source
305
4
        Defer record_parse([&] {
306
4
            if (statistics) {
307
0
                statistics->record_parse(MonotonicNanos() - parse_start, parse_failed);
308
0
            }
309
4
        });
Unexecuted instantiation: _ZZNK5doris10AIFunctionINS_14FunctionAIMaskEE21execute_batch_requestERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERSB_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextEENKUlvE_clEv
_ZZNK5doris10AIFunctionINS_20FunctionAISimilarityEE21execute_batch_requestERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERSB_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextEENKUlvE_clEv
Line
Count
Source
305
44
        Defer record_parse([&] {
306
44
            if (statistics) {
307
14
                statistics->record_parse(MonotonicNanos() - parse_start, parse_failed);
308
14
            }
309
44
        });
Unexecuted instantiation: _ZZNK5doris10AIFunctionINS_19FunctionAITranslateEE21execute_batch_requestERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERSB_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextEENKUlvE_clEv
310
14
        RETURN_IF_ERROR(adapter->parse_batch_response(response, parsed_response));
311
14
        if (parsed_response.empty()) {
312
0
            return Status::InternalError("AI returned empty result");
313
0
        }
314
14
        if (parsed_response.size() != batch_prompts.size()) {
315
0
            LOG(WARNING) << "AI batch result size mismatch, function=" << get_name()
316
0
                         << ", provider=" << config.provider_type << ", model=" << config.model_name
317
0
                         << ", expected_rows=" << batch_prompts.size()
318
0
                         << ", actual_rows=" << parsed_response.size()
319
0
                         << ", response_body=" << response;
320
0
            return Status::RuntimeError(
321
0
                    "Failed to parse {} batch result, expected {} items but got {}", get_name(),
322
0
                    batch_prompts.size(), parsed_response.size());
323
0
        }
324
14
        results = std::move(parsed_response);
325
14
        parse_failed = false;
326
14
        return Status::OK();
327
14
    }
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_16FunctionAIFilterEE21execute_batch_requestERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERSB_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextE
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_20FunctionAIFixGrammarEE21execute_batch_requestERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERSB_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextE
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_19FunctionAISentimentEE21execute_batch_requestERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERSB_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextE
_ZNK5doris10AIFunctionINS_19FunctionAISummarizeEE21execute_batch_requestERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERSB_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextE
Line
Count
Source
251
14
                                 FunctionContext* context) const {
252
#ifdef BE_TEST
253
        const char* test_result = std::getenv("AI_TEST_RESULT");
254
        if (test_result != nullptr) {
255
            const auto& statistics = get_executor(context)->statistics();
256
            const auto parse_start = statistics ? MonotonicNanos() : 0;
257
            bool parse_failed = true;
258
            Defer record_parse([&] {
259
                if (statistics) {
260
                    statistics->record_parse(MonotonicNanos() - parse_start, parse_failed);
261
                }
262
            });
263
            std::vector<std::string> parsed_test_response;
264
            RETURN_IF_ERROR(
265
                    adapter->parse_response(std::string(test_result), parsed_test_response));
266
            if (parsed_test_response.empty()) {
267
                return Status::InternalError("AI returned empty result");
268
            }
269
            if (parsed_test_response.size() != batch_prompts.size()) {
270
                return Status::RuntimeError(
271
                        "Failed to parse {} batch result, expected {} items but got {}", get_name(),
272
                        batch_prompts.size(), parsed_test_response.size());
273
            }
274
            results = std::move(parsed_test_response);
275
            parse_failed = false;
276
            return Status::OK();
277
        }
278
        if (config.provider_type == "MOCK") {
279
            results.clear();
280
            results.reserve(batch_prompts.size());
281
            for (const auto& prompt : batch_prompts) {
282
                results.emplace_back("this is a mock response. " + prompt);
283
            }
284
            return Status::OK();
285
        }
286
#endif
287
288
14
        std::string batch_prompt;
289
14
        RETURN_IF_ERROR(build_batch_prompt(batch_prompts, batch_prompt));
290
291
14
        std::vector<std::string> inputs = {batch_prompt};
292
14
        std::vector<std::string> parsed_response;
293
294
14
        std::string request_body;
295
        // Disabling provider format constraints keeps batching and the output protocol intact.
296
14
        RETURN_IF_ERROR(adapter->build_request_payload(
297
14
                inputs, batch_system_prompt(adapter->supports_structured_batch()), request_body,
298
14
                config.enable_structured_output && adapter->supports_structured_batch()));
299
300
14
        std::string response;
301
14
        RETURN_IF_ERROR(send_request_to_llm(request_body, response, config, adapter, context));
302
14
        const auto& statistics = get_executor(context)->statistics();
303
14
        const auto parse_start = statistics ? MonotonicNanos() : 0;
304
14
        bool parse_failed = true;
305
14
        Defer record_parse([&] {
306
14
            if (statistics) {
307
14
                statistics->record_parse(MonotonicNanos() - parse_start, parse_failed);
308
14
            }
309
14
        });
310
14
        RETURN_IF_ERROR(adapter->parse_batch_response(response, parsed_response));
311
14
        if (parsed_response.empty()) {
312
0
            return Status::InternalError("AI returned empty result");
313
0
        }
314
14
        if (parsed_response.size() != batch_prompts.size()) {
315
0
            LOG(WARNING) << "AI batch result size mismatch, function=" << get_name()
316
0
                         << ", provider=" << config.provider_type << ", model=" << config.model_name
317
0
                         << ", expected_rows=" << batch_prompts.size()
318
0
                         << ", actual_rows=" << parsed_response.size()
319
0
                         << ", response_body=" << response;
320
0
            return Status::RuntimeError(
321
0
                    "Failed to parse {} batch result, expected {} items but got {}", get_name(),
322
0
                    batch_prompts.size(), parsed_response.size());
323
0
        }
324
14
        results = std::move(parsed_response);
325
14
        parse_failed = false;
326
14
        return Status::OK();
327
14
    }
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_18FunctionAIClassifyEE21execute_batch_requestERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERSB_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextE
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_17FunctionAIExtractEE21execute_batch_requestERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERSB_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextE
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_18FunctionAIGenerateEE21execute_batch_requestERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERSB_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextE
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_14FunctionAIMaskEE21execute_batch_requestERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERSB_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextE
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_20FunctionAISimilarityEE21execute_batch_requestERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERSB_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextE
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_19FunctionAITranslateEE21execute_batch_requestERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERSB_RKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEEPNS_15FunctionContextE
328
329
    Status append_results_with_statistics(FunctionContext* context,
330
                                          const std::vector<std::string>& results,
331
180
                                          IColumn& column) const {
332
180
        const auto& statistics = get_executor(context)->statistics();
333
180
        const auto parse_start = statistics ? MonotonicNanos() : 0;
334
180
        Status status = assert_cast<const Derived&>(*this).append_batch_results(results, column);
335
180
        if (statistics) {
336
34
            statistics->record_parse(MonotonicNanos() - parse_start, !status.ok());
337
34
        }
338
180
        return status;
339
180
    }
_ZNK5doris10AIFunctionINS_16FunctionAIFilterEE30append_results_with_statisticsEPNS_15FunctionContextERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaISB_EERNS_7IColumnE
Line
Count
Source
331
90
                                          IColumn& column) const {
332
90
        const auto& statistics = get_executor(context)->statistics();
333
90
        const auto parse_start = statistics ? MonotonicNanos() : 0;
334
90
        Status status = assert_cast<const Derived&>(*this).append_batch_results(results, column);
335
90
        if (statistics) {
336
0
            statistics->record_parse(MonotonicNanos() - parse_start, !status.ok());
337
0
        }
338
90
        return status;
339
90
    }
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_20FunctionAIFixGrammarEE30append_results_with_statisticsEPNS_15FunctionContextERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaISB_EERNS_7IColumnE
_ZNK5doris10AIFunctionINS_19FunctionAISentimentEE30append_results_with_statisticsEPNS_15FunctionContextERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaISB_EERNS_7IColumnE
Line
Count
Source
331
4
                                          IColumn& column) const {
332
4
        const auto& statistics = get_executor(context)->statistics();
333
4
        const auto parse_start = statistics ? MonotonicNanos() : 0;
334
4
        Status status = assert_cast<const Derived&>(*this).append_batch_results(results, column);
335
4
        if (statistics) {
336
0
            statistics->record_parse(MonotonicNanos() - parse_start, !status.ok());
337
0
        }
338
4
        return status;
339
4
    }
_ZNK5doris10AIFunctionINS_19FunctionAISummarizeEE30append_results_with_statisticsEPNS_15FunctionContextERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaISB_EERNS_7IColumnE
Line
Count
Source
331
34
                                          IColumn& column) const {
332
34
        const auto& statistics = get_executor(context)->statistics();
333
34
        const auto parse_start = statistics ? MonotonicNanos() : 0;
334
34
        Status status = assert_cast<const Derived&>(*this).append_batch_results(results, column);
335
34
        if (statistics) {
336
20
            statistics->record_parse(MonotonicNanos() - parse_start, !status.ok());
337
20
        }
338
34
        return status;
339
34
    }
_ZNK5doris10AIFunctionINS_18FunctionAIClassifyEE30append_results_with_statisticsEPNS_15FunctionContextERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaISB_EERNS_7IColumnE
Line
Count
Source
331
4
                                          IColumn& column) const {
332
4
        const auto& statistics = get_executor(context)->statistics();
333
4
        const auto parse_start = statistics ? MonotonicNanos() : 0;
334
4
        Status status = assert_cast<const Derived&>(*this).append_batch_results(results, column);
335
4
        if (statistics) {
336
0
            statistics->record_parse(MonotonicNanos() - parse_start, !status.ok());
337
0
        }
338
4
        return status;
339
4
    }
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_17FunctionAIExtractEE30append_results_with_statisticsEPNS_15FunctionContextERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaISB_EERNS_7IColumnE
_ZNK5doris10AIFunctionINS_18FunctionAIGenerateEE30append_results_with_statisticsEPNS_15FunctionContextERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaISB_EERNS_7IColumnE
Line
Count
Source
331
4
                                          IColumn& column) const {
332
4
        const auto& statistics = get_executor(context)->statistics();
333
4
        const auto parse_start = statistics ? MonotonicNanos() : 0;
334
4
        Status status = assert_cast<const Derived&>(*this).append_batch_results(results, column);
335
4
        if (statistics) {
336
0
            statistics->record_parse(MonotonicNanos() - parse_start, !status.ok());
337
0
        }
338
4
        return status;
339
4
    }
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_14FunctionAIMaskEE30append_results_with_statisticsEPNS_15FunctionContextERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaISB_EERNS_7IColumnE
_ZNK5doris10AIFunctionINS_20FunctionAISimilarityEE30append_results_with_statisticsEPNS_15FunctionContextERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaISB_EERNS_7IColumnE
Line
Count
Source
331
44
                                          IColumn& column) const {
332
44
        const auto& statistics = get_executor(context)->statistics();
333
44
        const auto parse_start = statistics ? MonotonicNanos() : 0;
334
44
        Status status = assert_cast<const Derived&>(*this).append_batch_results(results, column);
335
44
        if (statistics) {
336
14
            statistics->record_parse(MonotonicNanos() - parse_start, !status.ok());
337
14
        }
338
44
        return status;
339
44
    }
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_19FunctionAITranslateEE30append_results_with_statisticsEPNS_15FunctionContextERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaISB_EERNS_7IColumnE
340
341
    // Provider-reusable helper for string-returning functions.
342
    // Runs the common batch execution flow; derived classes only need to define how one batch of
343
    // string results is inserted into the final output column.
344
    Status execute(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
345
                   uint32_t result, size_t input_rows_count, const AIResource& config,
346
178
                   std::shared_ptr<AIAdapter>& adapter) const {
347
178
        Columns prompt_columns;
348
178
        prompt_columns.reserve(arguments.size() - 1);
349
178
        ColumnUInt8::MutablePtr result_null_map;
350
404
        for (size_t i = 1; i < arguments.size(); ++i) {
351
226
            const auto& argument = block.get_by_position(arguments[i]);
352
226
            if (argument.type->is_nullable()) {
353
28
                const auto& [column, is_const] = unpack_if_const(argument.column);
354
28
                const auto& nullable =
355
28
                        assert_cast<const ColumnNullable&, TypeCheckOnRelease::DISABLE>(*column);
356
28
                if (!result_null_map) {
357
26
                    result_null_map = ColumnUInt8::create(input_rows_count, 0);
358
26
                }
359
28
                VectorizedUtils::update_null_map(result_null_map->get_data(),
360
28
                                                 nullable.get_null_map_data(), is_const);
361
28
            }
362
226
            prompt_columns.emplace_back(
363
226
                    argument.unnest_nullable(argument.type->is_nullable()
364
226
                                                     ? argument.get_nullable_column_info()
365
226
                                                     : NullableColumnInfo {},
366
226
                                             false)
367
226
                            .column);
368
226
        }
369
370
178
        record_input(context, input_rows_count, result_null_map);
371
372
178
        if (result_null_map &&
373
178
            !simd::contain_zero(result_null_map->get_data().data(), input_rows_count)) {
374
4
            block.get_by_position(result).column =
375
4
                    block.get_by_position(result).type->create_column_const(input_rows_count,
376
4
                                                                            Field());
377
4
            return Status::OK();
378
4
        }
379
380
174
        auto col_result = assert_cast<const Derived&>(*this).create_result_column();
381
174
        std::vector<std::string> batch_prompts;
382
174
        size_t current_batch_size = 2; // []
383
174
        const size_t max_batch_prompt_size =
384
174
                static_cast<size_t>(get_ai_context_window_size(context));
385
174
        const NullMap* null_map = result_null_map ? &result_null_map->get_data() : nullptr;
386
387
436
        for (size_t i = 0; i < input_rows_count; ++i) {
388
262
            if (null_map && (*null_map)[i]) {
389
28
                continue;
390
28
            }
391
392
234
            std::string prompt;
393
234
            RETURN_IF_ERROR(
394
234
                    assert_cast<const Derived&>(*this).build_prompt(prompt_columns, i, prompt));
395
396
234
            size_t entry_size = estimate_batch_entry_size(batch_prompts.size(), prompt);
397
234
            if (entry_size > max_batch_prompt_size) {
398
28
                if (!batch_prompts.empty()) {
399
2
                    std::vector<std::string> batch_results;
400
2
                    RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results,
401
2
                                                                config, adapter, context));
402
2
                    RETURN_IF_ERROR(
403
2
                            append_results_with_statistics(context, batch_results, *col_result));
404
2
                    batch_prompts.clear();
405
2
                    current_batch_size = 2;
406
2
                }
407
408
28
                std::vector<std::string> single_prompts;
409
28
                single_prompts.emplace_back(std::move(prompt));
410
28
                std::vector<std::string> single_results;
411
28
                RETURN_IF_ERROR(this->execute_batch_request(single_prompts, single_results, config,
412
28
                                                            adapter, context));
413
28
                RETURN_IF_ERROR(
414
28
                        append_results_with_statistics(context, single_results, *col_result));
415
28
                continue;
416
28
            }
417
418
206
            size_t additional_size = entry_size + (batch_prompts.empty() ? 0 : 1);
419
206
            if (!batch_prompts.empty() &&
420
206
                current_batch_size + additional_size > max_batch_prompt_size) {
421
4
                std::vector<std::string> batch_results;
422
4
                RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results, config,
423
4
                                                            adapter, context));
424
4
                RETURN_IF_ERROR(
425
4
                        append_results_with_statistics(context, batch_results, *col_result));
426
4
                batch_prompts.clear();
427
4
                current_batch_size = 2;
428
4
                additional_size = entry_size;
429
4
            }
430
431
206
            batch_prompts.emplace_back(std::move(prompt));
432
206
            current_batch_size += additional_size;
433
206
        }
434
435
174
        if (!batch_prompts.empty()) {
436
158
            std::vector<std::string> batch_results;
437
158
            RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results, config,
438
158
                                                        adapter, context));
439
146
            RETURN_IF_ERROR(append_results_with_statistics(context, batch_results, *col_result));
440
146
        }
441
442
108
        if (!result_null_map) {
443
86
            block.replace_by_position(result, std::move(col_result));
444
86
            return Status::OK();
445
86
        }
446
447
22
        if (!simd::contain_one(result_null_map->get_data().data(), input_rows_count)) {
448
4
            block.replace_by_position(result, ColumnNullable::create(std::move(col_result),
449
4
                                                                     std::move(result_null_map)));
450
4
            return Status::OK();
451
4
        }
452
453
18
        auto nested_result = col_result->clone_empty();
454
18
        size_t result_row = 0;
455
62
        for (UInt8 is_null : result_null_map->get_data()) {
456
62
            if (is_null) {
457
28
                nested_result->insert_default();
458
34
            } else {
459
34
                nested_result->insert_from(*col_result, result_row++);
460
34
            }
461
62
        }
462
463
18
        block.replace_by_position(result, ColumnNullable::create(std::move(nested_result),
464
18
                                                                 std::move(result_null_map)));
465
18
        return Status::OK();
466
22
    }
_ZNK5doris10AIFunctionINS_16FunctionAIFilterEE7executeEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmRKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEE
Line
Count
Source
346
94
                   std::shared_ptr<AIAdapter>& adapter) const {
347
94
        Columns prompt_columns;
348
94
        prompt_columns.reserve(arguments.size() - 1);
349
94
        ColumnUInt8::MutablePtr result_null_map;
350
188
        for (size_t i = 1; i < arguments.size(); ++i) {
351
94
            const auto& argument = block.get_by_position(arguments[i]);
352
94
            if (argument.type->is_nullable()) {
353
2
                const auto& [column, is_const] = unpack_if_const(argument.column);
354
2
                const auto& nullable =
355
2
                        assert_cast<const ColumnNullable&, TypeCheckOnRelease::DISABLE>(*column);
356
2
                if (!result_null_map) {
357
2
                    result_null_map = ColumnUInt8::create(input_rows_count, 0);
358
2
                }
359
2
                VectorizedUtils::update_null_map(result_null_map->get_data(),
360
2
                                                 nullable.get_null_map_data(), is_const);
361
2
            }
362
94
            prompt_columns.emplace_back(
363
94
                    argument.unnest_nullable(argument.type->is_nullable()
364
94
                                                     ? argument.get_nullable_column_info()
365
94
                                                     : NullableColumnInfo {},
366
94
                                             false)
367
94
                            .column);
368
94
        }
369
370
94
        record_input(context, input_rows_count, result_null_map);
371
372
94
        if (result_null_map &&
373
94
            !simd::contain_zero(result_null_map->get_data().data(), input_rows_count)) {
374
0
            block.get_by_position(result).column =
375
0
                    block.get_by_position(result).type->create_column_const(input_rows_count,
376
0
                                                                            Field());
377
0
            return Status::OK();
378
0
        }
379
380
94
        auto col_result = assert_cast<const Derived&>(*this).create_result_column();
381
94
        std::vector<std::string> batch_prompts;
382
94
        size_t current_batch_size = 2; // []
383
94
        const size_t max_batch_prompt_size =
384
94
                static_cast<size_t>(get_ai_context_window_size(context));
385
94
        const NullMap* null_map = result_null_map ? &result_null_map->get_data() : nullptr;
386
387
226
        for (size_t i = 0; i < input_rows_count; ++i) {
388
132
            if (null_map && (*null_map)[i]) {
389
4
                continue;
390
4
            }
391
392
128
            std::string prompt;
393
128
            RETURN_IF_ERROR(
394
128
                    assert_cast<const Derived&>(*this).build_prompt(prompt_columns, i, prompt));
395
396
128
            size_t entry_size = estimate_batch_entry_size(batch_prompts.size(), prompt);
397
128
            if (entry_size > max_batch_prompt_size) {
398
8
                if (!batch_prompts.empty()) {
399
2
                    std::vector<std::string> batch_results;
400
2
                    RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results,
401
2
                                                                config, adapter, context));
402
2
                    RETURN_IF_ERROR(
403
2
                            append_results_with_statistics(context, batch_results, *col_result));
404
2
                    batch_prompts.clear();
405
2
                    current_batch_size = 2;
406
2
                }
407
408
8
                std::vector<std::string> single_prompts;
409
8
                single_prompts.emplace_back(std::move(prompt));
410
8
                std::vector<std::string> single_results;
411
8
                RETURN_IF_ERROR(this->execute_batch_request(single_prompts, single_results, config,
412
8
                                                            adapter, context));
413
8
                RETURN_IF_ERROR(
414
8
                        append_results_with_statistics(context, single_results, *col_result));
415
8
                continue;
416
8
            }
417
418
120
            size_t additional_size = entry_size + (batch_prompts.empty() ? 0 : 1);
419
120
            if (!batch_prompts.empty() &&
420
120
                current_batch_size + additional_size > max_batch_prompt_size) {
421
4
                std::vector<std::string> batch_results;
422
4
                RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results, config,
423
4
                                                            adapter, context));
424
4
                RETURN_IF_ERROR(
425
4
                        append_results_with_statistics(context, batch_results, *col_result));
426
4
                batch_prompts.clear();
427
4
                current_batch_size = 2;
428
4
                additional_size = entry_size;
429
4
            }
430
431
120
            batch_prompts.emplace_back(std::move(prompt));
432
120
            current_batch_size += additional_size;
433
120
        }
434
435
94
        if (!batch_prompts.empty()) {
436
88
            std::vector<std::string> batch_results;
437
88
            RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results, config,
438
88
                                                        adapter, context));
439
76
            RETURN_IF_ERROR(append_results_with_statistics(context, batch_results, *col_result));
440
76
        }
441
442
40
        if (!result_null_map) {
443
38
            block.replace_by_position(result, std::move(col_result));
444
38
            return Status::OK();
445
38
        }
446
447
2
        if (!simd::contain_one(result_null_map->get_data().data(), input_rows_count)) {
448
0
            block.replace_by_position(result, ColumnNullable::create(std::move(col_result),
449
0
                                                                     std::move(result_null_map)));
450
0
            return Status::OK();
451
0
        }
452
453
2
        auto nested_result = col_result->clone_empty();
454
2
        size_t result_row = 0;
455
8
        for (UInt8 is_null : result_null_map->get_data()) {
456
8
            if (is_null) {
457
4
                nested_result->insert_default();
458
4
            } else {
459
4
                nested_result->insert_from(*col_result, result_row++);
460
4
            }
461
8
        }
462
463
2
        block.replace_by_position(result, ColumnNullable::create(std::move(nested_result),
464
2
                                                                 std::move(result_null_map)));
465
2
        return Status::OK();
466
2
    }
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_20FunctionAIFixGrammarEE7executeEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmRKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEE
_ZNK5doris10AIFunctionINS_19FunctionAISentimentEE7executeEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmRKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEE
Line
Count
Source
346
4
                   std::shared_ptr<AIAdapter>& adapter) const {
347
4
        Columns prompt_columns;
348
4
        prompt_columns.reserve(arguments.size() - 1);
349
4
        ColumnUInt8::MutablePtr result_null_map;
350
8
        for (size_t i = 1; i < arguments.size(); ++i) {
351
4
            const auto& argument = block.get_by_position(arguments[i]);
352
4
            if (argument.type->is_nullable()) {
353
0
                const auto& [column, is_const] = unpack_if_const(argument.column);
354
0
                const auto& nullable =
355
0
                        assert_cast<const ColumnNullable&, TypeCheckOnRelease::DISABLE>(*column);
356
0
                if (!result_null_map) {
357
0
                    result_null_map = ColumnUInt8::create(input_rows_count, 0);
358
0
                }
359
0
                VectorizedUtils::update_null_map(result_null_map->get_data(),
360
0
                                                 nullable.get_null_map_data(), is_const);
361
0
            }
362
4
            prompt_columns.emplace_back(
363
4
                    argument.unnest_nullable(argument.type->is_nullable()
364
4
                                                     ? argument.get_nullable_column_info()
365
4
                                                     : NullableColumnInfo {},
366
4
                                             false)
367
4
                            .column);
368
4
        }
369
370
4
        record_input(context, input_rows_count, result_null_map);
371
372
4
        if (result_null_map &&
373
4
            !simd::contain_zero(result_null_map->get_data().data(), input_rows_count)) {
374
0
            block.get_by_position(result).column =
375
0
                    block.get_by_position(result).type->create_column_const(input_rows_count,
376
0
                                                                            Field());
377
0
            return Status::OK();
378
0
        }
379
380
4
        auto col_result = assert_cast<const Derived&>(*this).create_result_column();
381
4
        std::vector<std::string> batch_prompts;
382
4
        size_t current_batch_size = 2; // []
383
4
        const size_t max_batch_prompt_size =
384
4
                static_cast<size_t>(get_ai_context_window_size(context));
385
4
        const NullMap* null_map = result_null_map ? &result_null_map->get_data() : nullptr;
386
387
12
        for (size_t i = 0; i < input_rows_count; ++i) {
388
8
            if (null_map && (*null_map)[i]) {
389
0
                continue;
390
0
            }
391
392
8
            std::string prompt;
393
8
            RETURN_IF_ERROR(
394
8
                    assert_cast<const Derived&>(*this).build_prompt(prompt_columns, i, prompt));
395
396
8
            size_t entry_size = estimate_batch_entry_size(batch_prompts.size(), prompt);
397
8
            if (entry_size > max_batch_prompt_size) {
398
0
                if (!batch_prompts.empty()) {
399
0
                    std::vector<std::string> batch_results;
400
0
                    RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results,
401
0
                                                                config, adapter, context));
402
0
                    RETURN_IF_ERROR(
403
0
                            append_results_with_statistics(context, batch_results, *col_result));
404
0
                    batch_prompts.clear();
405
0
                    current_batch_size = 2;
406
0
                }
407
408
0
                std::vector<std::string> single_prompts;
409
0
                single_prompts.emplace_back(std::move(prompt));
410
0
                std::vector<std::string> single_results;
411
0
                RETURN_IF_ERROR(this->execute_batch_request(single_prompts, single_results, config,
412
0
                                                            adapter, context));
413
0
                RETURN_IF_ERROR(
414
0
                        append_results_with_statistics(context, single_results, *col_result));
415
0
                continue;
416
0
            }
417
418
8
            size_t additional_size = entry_size + (batch_prompts.empty() ? 0 : 1);
419
8
            if (!batch_prompts.empty() &&
420
8
                current_batch_size + additional_size > max_batch_prompt_size) {
421
0
                std::vector<std::string> batch_results;
422
0
                RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results, config,
423
0
                                                            adapter, context));
424
0
                RETURN_IF_ERROR(
425
0
                        append_results_with_statistics(context, batch_results, *col_result));
426
0
                batch_prompts.clear();
427
0
                current_batch_size = 2;
428
0
                additional_size = entry_size;
429
0
            }
430
431
8
            batch_prompts.emplace_back(std::move(prompt));
432
8
            current_batch_size += additional_size;
433
8
        }
434
435
4
        if (!batch_prompts.empty()) {
436
4
            std::vector<std::string> batch_results;
437
4
            RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results, config,
438
4
                                                        adapter, context));
439
4
            RETURN_IF_ERROR(append_results_with_statistics(context, batch_results, *col_result));
440
4
        }
441
442
4
        if (!result_null_map) {
443
4
            block.replace_by_position(result, std::move(col_result));
444
4
            return Status::OK();
445
4
        }
446
447
0
        if (!simd::contain_one(result_null_map->get_data().data(), input_rows_count)) {
448
0
            block.replace_by_position(result, ColumnNullable::create(std::move(col_result),
449
0
                                                                     std::move(result_null_map)));
450
0
            return Status::OK();
451
0
        }
452
453
0
        auto nested_result = col_result->clone_empty();
454
0
        size_t result_row = 0;
455
0
        for (UInt8 is_null : result_null_map->get_data()) {
456
0
            if (is_null) {
457
0
                nested_result->insert_default();
458
0
            } else {
459
0
                nested_result->insert_from(*col_result, result_row++);
460
0
            }
461
0
        }
462
463
0
        block.replace_by_position(result, ColumnNullable::create(std::move(nested_result),
464
0
                                                                 std::move(result_null_map)));
465
0
        return Status::OK();
466
0
    }
_ZNK5doris10AIFunctionINS_19FunctionAISummarizeEE7executeEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmRKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEE
Line
Count
Source
346
26
                   std::shared_ptr<AIAdapter>& adapter) const {
347
26
        Columns prompt_columns;
348
26
        prompt_columns.reserve(arguments.size() - 1);
349
26
        ColumnUInt8::MutablePtr result_null_map;
350
52
        for (size_t i = 1; i < arguments.size(); ++i) {
351
26
            const auto& argument = block.get_by_position(arguments[i]);
352
26
            if (argument.type->is_nullable()) {
353
14
                const auto& [column, is_const] = unpack_if_const(argument.column);
354
14
                const auto& nullable =
355
14
                        assert_cast<const ColumnNullable&, TypeCheckOnRelease::DISABLE>(*column);
356
14
                if (!result_null_map) {
357
14
                    result_null_map = ColumnUInt8::create(input_rows_count, 0);
358
14
                }
359
14
                VectorizedUtils::update_null_map(result_null_map->get_data(),
360
14
                                                 nullable.get_null_map_data(), is_const);
361
14
            }
362
26
            prompt_columns.emplace_back(
363
26
                    argument.unnest_nullable(argument.type->is_nullable()
364
26
                                                     ? argument.get_nullable_column_info()
365
26
                                                     : NullableColumnInfo {},
366
26
                                             false)
367
26
                            .column);
368
26
        }
369
370
26
        record_input(context, input_rows_count, result_null_map);
371
372
26
        if (result_null_map &&
373
26
            !simd::contain_zero(result_null_map->get_data().data(), input_rows_count)) {
374
2
            block.get_by_position(result).column =
375
2
                    block.get_by_position(result).type->create_column_const(input_rows_count,
376
2
                                                                            Field());
377
2
            return Status::OK();
378
2
        }
379
380
24
        auto col_result = assert_cast<const Derived&>(*this).create_result_column();
381
24
        std::vector<std::string> batch_prompts;
382
24
        size_t current_batch_size = 2; // []
383
24
        const size_t max_batch_prompt_size =
384
24
                static_cast<size_t>(get_ai_context_window_size(context));
385
24
        const NullMap* null_map = result_null_map ? &result_null_map->get_data() : nullptr;
386
387
68
        for (size_t i = 0; i < input_rows_count; ++i) {
388
44
            if (null_map && (*null_map)[i]) {
389
10
                continue;
390
10
            }
391
392
34
            std::string prompt;
393
34
            RETURN_IF_ERROR(
394
34
                    assert_cast<const Derived&>(*this).build_prompt(prompt_columns, i, prompt));
395
396
34
            size_t entry_size = estimate_batch_entry_size(batch_prompts.size(), prompt);
397
34
            if (entry_size > max_batch_prompt_size) {
398
20
                if (!batch_prompts.empty()) {
399
0
                    std::vector<std::string> batch_results;
400
0
                    RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results,
401
0
                                                                config, adapter, context));
402
0
                    RETURN_IF_ERROR(
403
0
                            append_results_with_statistics(context, batch_results, *col_result));
404
0
                    batch_prompts.clear();
405
0
                    current_batch_size = 2;
406
0
                }
407
408
20
                std::vector<std::string> single_prompts;
409
20
                single_prompts.emplace_back(std::move(prompt));
410
20
                std::vector<std::string> single_results;
411
20
                RETURN_IF_ERROR(this->execute_batch_request(single_prompts, single_results, config,
412
20
                                                            adapter, context));
413
20
                RETURN_IF_ERROR(
414
20
                        append_results_with_statistics(context, single_results, *col_result));
415
20
                continue;
416
20
            }
417
418
14
            size_t additional_size = entry_size + (batch_prompts.empty() ? 0 : 1);
419
14
            if (!batch_prompts.empty() &&
420
14
                current_batch_size + additional_size > max_batch_prompt_size) {
421
0
                std::vector<std::string> batch_results;
422
0
                RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results, config,
423
0
                                                            adapter, context));
424
0
                RETURN_IF_ERROR(
425
0
                        append_results_with_statistics(context, batch_results, *col_result));
426
0
                batch_prompts.clear();
427
0
                current_batch_size = 2;
428
0
                additional_size = entry_size;
429
0
            }
430
431
14
            batch_prompts.emplace_back(std::move(prompt));
432
14
            current_batch_size += additional_size;
433
14
        }
434
435
24
        if (!batch_prompts.empty()) {
436
14
            std::vector<std::string> batch_results;
437
14
            RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results, config,
438
14
                                                        adapter, context));
439
14
            RETURN_IF_ERROR(append_results_with_statistics(context, batch_results, *col_result));
440
14
        }
441
442
24
        if (!result_null_map) {
443
12
            block.replace_by_position(result, std::move(col_result));
444
12
            return Status::OK();
445
12
        }
446
447
12
        if (!simd::contain_one(result_null_map->get_data().data(), input_rows_count)) {
448
2
            block.replace_by_position(result, ColumnNullable::create(std::move(col_result),
449
2
                                                                     std::move(result_null_map)));
450
2
            return Status::OK();
451
2
        }
452
453
10
        auto nested_result = col_result->clone_empty();
454
10
        size_t result_row = 0;
455
30
        for (UInt8 is_null : result_null_map->get_data()) {
456
30
            if (is_null) {
457
10
                nested_result->insert_default();
458
20
            } else {
459
20
                nested_result->insert_from(*col_result, result_row++);
460
20
            }
461
30
        }
462
463
10
        block.replace_by_position(result, ColumnNullable::create(std::move(nested_result),
464
10
                                                                 std::move(result_null_map)));
465
10
        return Status::OK();
466
12
    }
_ZNK5doris10AIFunctionINS_18FunctionAIClassifyEE7executeEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmRKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEE
Line
Count
Source
346
4
                   std::shared_ptr<AIAdapter>& adapter) const {
347
4
        Columns prompt_columns;
348
4
        prompt_columns.reserve(arguments.size() - 1);
349
4
        ColumnUInt8::MutablePtr result_null_map;
350
12
        for (size_t i = 1; i < arguments.size(); ++i) {
351
8
            const auto& argument = block.get_by_position(arguments[i]);
352
8
            if (argument.type->is_nullable()) {
353
2
                const auto& [column, is_const] = unpack_if_const(argument.column);
354
2
                const auto& nullable =
355
2
                        assert_cast<const ColumnNullable&, TypeCheckOnRelease::DISABLE>(*column);
356
2
                if (!result_null_map) {
357
2
                    result_null_map = ColumnUInt8::create(input_rows_count, 0);
358
2
                }
359
2
                VectorizedUtils::update_null_map(result_null_map->get_data(),
360
2
                                                 nullable.get_null_map_data(), is_const);
361
2
            }
362
8
            prompt_columns.emplace_back(
363
8
                    argument.unnest_nullable(argument.type->is_nullable()
364
8
                                                     ? argument.get_nullable_column_info()
365
8
                                                     : NullableColumnInfo {},
366
8
                                             false)
367
8
                            .column);
368
8
        }
369
370
4
        record_input(context, input_rows_count, result_null_map);
371
372
4
        if (result_null_map &&
373
4
            !simd::contain_zero(result_null_map->get_data().data(), input_rows_count)) {
374
0
            block.get_by_position(result).column =
375
0
                    block.get_by_position(result).type->create_column_const(input_rows_count,
376
0
                                                                            Field());
377
0
            return Status::OK();
378
0
        }
379
380
4
        auto col_result = assert_cast<const Derived&>(*this).create_result_column();
381
4
        std::vector<std::string> batch_prompts;
382
4
        size_t current_batch_size = 2; // []
383
4
        const size_t max_batch_prompt_size =
384
4
                static_cast<size_t>(get_ai_context_window_size(context));
385
4
        const NullMap* null_map = result_null_map ? &result_null_map->get_data() : nullptr;
386
387
12
        for (size_t i = 0; i < input_rows_count; ++i) {
388
8
            if (null_map && (*null_map)[i]) {
389
4
                continue;
390
4
            }
391
392
4
            std::string prompt;
393
4
            RETURN_IF_ERROR(
394
4
                    assert_cast<const Derived&>(*this).build_prompt(prompt_columns, i, prompt));
395
396
4
            size_t entry_size = estimate_batch_entry_size(batch_prompts.size(), prompt);
397
4
            if (entry_size > max_batch_prompt_size) {
398
0
                if (!batch_prompts.empty()) {
399
0
                    std::vector<std::string> batch_results;
400
0
                    RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results,
401
0
                                                                config, adapter, context));
402
0
                    RETURN_IF_ERROR(
403
0
                            append_results_with_statistics(context, batch_results, *col_result));
404
0
                    batch_prompts.clear();
405
0
                    current_batch_size = 2;
406
0
                }
407
408
0
                std::vector<std::string> single_prompts;
409
0
                single_prompts.emplace_back(std::move(prompt));
410
0
                std::vector<std::string> single_results;
411
0
                RETURN_IF_ERROR(this->execute_batch_request(single_prompts, single_results, config,
412
0
                                                            adapter, context));
413
0
                RETURN_IF_ERROR(
414
0
                        append_results_with_statistics(context, single_results, *col_result));
415
0
                continue;
416
0
            }
417
418
4
            size_t additional_size = entry_size + (batch_prompts.empty() ? 0 : 1);
419
4
            if (!batch_prompts.empty() &&
420
4
                current_batch_size + additional_size > max_batch_prompt_size) {
421
0
                std::vector<std::string> batch_results;
422
0
                RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results, config,
423
0
                                                            adapter, context));
424
0
                RETURN_IF_ERROR(
425
0
                        append_results_with_statistics(context, batch_results, *col_result));
426
0
                batch_prompts.clear();
427
0
                current_batch_size = 2;
428
0
                additional_size = entry_size;
429
0
            }
430
431
4
            batch_prompts.emplace_back(std::move(prompt));
432
4
            current_batch_size += additional_size;
433
4
        }
434
435
4
        if (!batch_prompts.empty()) {
436
4
            std::vector<std::string> batch_results;
437
4
            RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results, config,
438
4
                                                        adapter, context));
439
4
            RETURN_IF_ERROR(append_results_with_statistics(context, batch_results, *col_result));
440
4
        }
441
442
4
        if (!result_null_map) {
443
2
            block.replace_by_position(result, std::move(col_result));
444
2
            return Status::OK();
445
2
        }
446
447
2
        if (!simd::contain_one(result_null_map->get_data().data(), input_rows_count)) {
448
0
            block.replace_by_position(result, ColumnNullable::create(std::move(col_result),
449
0
                                                                     std::move(result_null_map)));
450
0
            return Status::OK();
451
0
        }
452
453
2
        auto nested_result = col_result->clone_empty();
454
2
        size_t result_row = 0;
455
6
        for (UInt8 is_null : result_null_map->get_data()) {
456
6
            if (is_null) {
457
4
                nested_result->insert_default();
458
4
            } else {
459
2
                nested_result->insert_from(*col_result, result_row++);
460
2
            }
461
6
        }
462
463
2
        block.replace_by_position(result, ColumnNullable::create(std::move(nested_result),
464
2
                                                                 std::move(result_null_map)));
465
2
        return Status::OK();
466
2
    }
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_17FunctionAIExtractEE7executeEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmRKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEE
_ZNK5doris10AIFunctionINS_18FunctionAIGenerateEE7executeEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmRKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEE
Line
Count
Source
346
6
                   std::shared_ptr<AIAdapter>& adapter) const {
347
6
        Columns prompt_columns;
348
6
        prompt_columns.reserve(arguments.size() - 1);
349
6
        ColumnUInt8::MutablePtr result_null_map;
350
12
        for (size_t i = 1; i < arguments.size(); ++i) {
351
6
            const auto& argument = block.get_by_position(arguments[i]);
352
6
            if (argument.type->is_nullable()) {
353
6
                const auto& [column, is_const] = unpack_if_const(argument.column);
354
6
                const auto& nullable =
355
6
                        assert_cast<const ColumnNullable&, TypeCheckOnRelease::DISABLE>(*column);
356
6
                if (!result_null_map) {
357
6
                    result_null_map = ColumnUInt8::create(input_rows_count, 0);
358
6
                }
359
6
                VectorizedUtils::update_null_map(result_null_map->get_data(),
360
6
                                                 nullable.get_null_map_data(), is_const);
361
6
            }
362
6
            prompt_columns.emplace_back(
363
6
                    argument.unnest_nullable(argument.type->is_nullable()
364
6
                                                     ? argument.get_nullable_column_info()
365
6
                                                     : NullableColumnInfo {},
366
6
                                             false)
367
6
                            .column);
368
6
        }
369
370
6
        record_input(context, input_rows_count, result_null_map);
371
372
6
        if (result_null_map &&
373
6
            !simd::contain_zero(result_null_map->get_data().data(), input_rows_count)) {
374
2
            block.get_by_position(result).column =
375
2
                    block.get_by_position(result).type->create_column_const(input_rows_count,
376
2
                                                                            Field());
377
2
            return Status::OK();
378
2
        }
379
380
4
        auto col_result = assert_cast<const Derived&>(*this).create_result_column();
381
4
        std::vector<std::string> batch_prompts;
382
4
        size_t current_batch_size = 2; // []
383
4
        const size_t max_batch_prompt_size =
384
4
                static_cast<size_t>(get_ai_context_window_size(context));
385
4
        const NullMap* null_map = result_null_map ? &result_null_map->get_data() : nullptr;
386
387
20
        for (size_t i = 0; i < input_rows_count; ++i) {
388
16
            if (null_map && (*null_map)[i]) {
389
6
                continue;
390
6
            }
391
392
10
            std::string prompt;
393
10
            RETURN_IF_ERROR(
394
10
                    assert_cast<const Derived&>(*this).build_prompt(prompt_columns, i, prompt));
395
396
10
            size_t entry_size = estimate_batch_entry_size(batch_prompts.size(), prompt);
397
10
            if (entry_size > max_batch_prompt_size) {
398
0
                if (!batch_prompts.empty()) {
399
0
                    std::vector<std::string> batch_results;
400
0
                    RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results,
401
0
                                                                config, adapter, context));
402
0
                    RETURN_IF_ERROR(
403
0
                            append_results_with_statistics(context, batch_results, *col_result));
404
0
                    batch_prompts.clear();
405
0
                    current_batch_size = 2;
406
0
                }
407
408
0
                std::vector<std::string> single_prompts;
409
0
                single_prompts.emplace_back(std::move(prompt));
410
0
                std::vector<std::string> single_results;
411
0
                RETURN_IF_ERROR(this->execute_batch_request(single_prompts, single_results, config,
412
0
                                                            adapter, context));
413
0
                RETURN_IF_ERROR(
414
0
                        append_results_with_statistics(context, single_results, *col_result));
415
0
                continue;
416
0
            }
417
418
10
            size_t additional_size = entry_size + (batch_prompts.empty() ? 0 : 1);
419
10
            if (!batch_prompts.empty() &&
420
10
                current_batch_size + additional_size > max_batch_prompt_size) {
421
0
                std::vector<std::string> batch_results;
422
0
                RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results, config,
423
0
                                                            adapter, context));
424
0
                RETURN_IF_ERROR(
425
0
                        append_results_with_statistics(context, batch_results, *col_result));
426
0
                batch_prompts.clear();
427
0
                current_batch_size = 2;
428
0
                additional_size = entry_size;
429
0
            }
430
431
10
            batch_prompts.emplace_back(std::move(prompt));
432
10
            current_batch_size += additional_size;
433
10
        }
434
435
4
        if (!batch_prompts.empty()) {
436
4
            std::vector<std::string> batch_results;
437
4
            RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results, config,
438
4
                                                        adapter, context));
439
4
            RETURN_IF_ERROR(append_results_with_statistics(context, batch_results, *col_result));
440
4
        }
441
442
4
        if (!result_null_map) {
443
0
            block.replace_by_position(result, std::move(col_result));
444
0
            return Status::OK();
445
0
        }
446
447
4
        if (!simd::contain_one(result_null_map->get_data().data(), input_rows_count)) {
448
2
            block.replace_by_position(result, ColumnNullable::create(std::move(col_result),
449
2
                                                                     std::move(result_null_map)));
450
2
            return Status::OK();
451
2
        }
452
453
2
        auto nested_result = col_result->clone_empty();
454
2
        size_t result_row = 0;
455
10
        for (UInt8 is_null : result_null_map->get_data()) {
456
10
            if (is_null) {
457
6
                nested_result->insert_default();
458
6
            } else {
459
4
                nested_result->insert_from(*col_result, result_row++);
460
4
            }
461
10
        }
462
463
2
        block.replace_by_position(result, ColumnNullable::create(std::move(nested_result),
464
2
                                                                 std::move(result_null_map)));
465
2
        return Status::OK();
466
4
    }
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_14FunctionAIMaskEE7executeEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmRKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEE
_ZNK5doris10AIFunctionINS_20FunctionAISimilarityEE7executeEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmRKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEE
Line
Count
Source
346
44
                   std::shared_ptr<AIAdapter>& adapter) const {
347
44
        Columns prompt_columns;
348
44
        prompt_columns.reserve(arguments.size() - 1);
349
44
        ColumnUInt8::MutablePtr result_null_map;
350
132
        for (size_t i = 1; i < arguments.size(); ++i) {
351
88
            const auto& argument = block.get_by_position(arguments[i]);
352
88
            if (argument.type->is_nullable()) {
353
4
                const auto& [column, is_const] = unpack_if_const(argument.column);
354
4
                const auto& nullable =
355
4
                        assert_cast<const ColumnNullable&, TypeCheckOnRelease::DISABLE>(*column);
356
4
                if (!result_null_map) {
357
2
                    result_null_map = ColumnUInt8::create(input_rows_count, 0);
358
2
                }
359
4
                VectorizedUtils::update_null_map(result_null_map->get_data(),
360
4
                                                 nullable.get_null_map_data(), is_const);
361
4
            }
362
88
            prompt_columns.emplace_back(
363
88
                    argument.unnest_nullable(argument.type->is_nullable()
364
88
                                                     ? argument.get_nullable_column_info()
365
88
                                                     : NullableColumnInfo {},
366
88
                                             false)
367
88
                            .column);
368
88
        }
369
370
44
        record_input(context, input_rows_count, result_null_map);
371
372
44
        if (result_null_map &&
373
44
            !simd::contain_zero(result_null_map->get_data().data(), input_rows_count)) {
374
0
            block.get_by_position(result).column =
375
0
                    block.get_by_position(result).type->create_column_const(input_rows_count,
376
0
                                                                            Field());
377
0
            return Status::OK();
378
0
        }
379
380
44
        auto col_result = assert_cast<const Derived&>(*this).create_result_column();
381
44
        std::vector<std::string> batch_prompts;
382
44
        size_t current_batch_size = 2; // []
383
44
        const size_t max_batch_prompt_size =
384
44
                static_cast<size_t>(get_ai_context_window_size(context));
385
44
        const NullMap* null_map = result_null_map ? &result_null_map->get_data() : nullptr;
386
387
98
        for (size_t i = 0; i < input_rows_count; ++i) {
388
54
            if (null_map && (*null_map)[i]) {
389
4
                continue;
390
4
            }
391
392
50
            std::string prompt;
393
50
            RETURN_IF_ERROR(
394
50
                    assert_cast<const Derived&>(*this).build_prompt(prompt_columns, i, prompt));
395
396
50
            size_t entry_size = estimate_batch_entry_size(batch_prompts.size(), prompt);
397
50
            if (entry_size > max_batch_prompt_size) {
398
0
                if (!batch_prompts.empty()) {
399
0
                    std::vector<std::string> batch_results;
400
0
                    RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results,
401
0
                                                                config, adapter, context));
402
0
                    RETURN_IF_ERROR(
403
0
                            append_results_with_statistics(context, batch_results, *col_result));
404
0
                    batch_prompts.clear();
405
0
                    current_batch_size = 2;
406
0
                }
407
408
0
                std::vector<std::string> single_prompts;
409
0
                single_prompts.emplace_back(std::move(prompt));
410
0
                std::vector<std::string> single_results;
411
0
                RETURN_IF_ERROR(this->execute_batch_request(single_prompts, single_results, config,
412
0
                                                            adapter, context));
413
0
                RETURN_IF_ERROR(
414
0
                        append_results_with_statistics(context, single_results, *col_result));
415
0
                continue;
416
0
            }
417
418
50
            size_t additional_size = entry_size + (batch_prompts.empty() ? 0 : 1);
419
50
            if (!batch_prompts.empty() &&
420
50
                current_batch_size + additional_size > max_batch_prompt_size) {
421
0
                std::vector<std::string> batch_results;
422
0
                RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results, config,
423
0
                                                            adapter, context));
424
0
                RETURN_IF_ERROR(
425
0
                        append_results_with_statistics(context, batch_results, *col_result));
426
0
                batch_prompts.clear();
427
0
                current_batch_size = 2;
428
0
                additional_size = entry_size;
429
0
            }
430
431
50
            batch_prompts.emplace_back(std::move(prompt));
432
50
            current_batch_size += additional_size;
433
50
        }
434
435
44
        if (!batch_prompts.empty()) {
436
44
            std::vector<std::string> batch_results;
437
44
            RETURN_IF_ERROR(this->execute_batch_request(batch_prompts, batch_results, config,
438
44
                                                        adapter, context));
439
44
            RETURN_IF_ERROR(append_results_with_statistics(context, batch_results, *col_result));
440
44
        }
441
442
32
        if (!result_null_map) {
443
30
            block.replace_by_position(result, std::move(col_result));
444
30
            return Status::OK();
445
30
        }
446
447
2
        if (!simd::contain_one(result_null_map->get_data().data(), input_rows_count)) {
448
0
            block.replace_by_position(result, ColumnNullable::create(std::move(col_result),
449
0
                                                                     std::move(result_null_map)));
450
0
            return Status::OK();
451
0
        }
452
453
2
        auto nested_result = col_result->clone_empty();
454
2
        size_t result_row = 0;
455
8
        for (UInt8 is_null : result_null_map->get_data()) {
456
8
            if (is_null) {
457
4
                nested_result->insert_default();
458
4
            } else {
459
4
                nested_result->insert_from(*col_result, result_row++);
460
4
            }
461
8
        }
462
463
2
        block.replace_by_position(result, ColumnNullable::create(std::move(nested_result),
464
2
                                                                 std::move(result_null_map)));
465
2
        return Status::OK();
466
2
    }
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_19FunctionAITranslateEE7executeEPNS_15FunctionContextERNS_5BlockERKSt6vectorIjSaIjEEjmRKNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEE
467
468
private:
469
    // The ai resource must be literal
470
    Status _init_from_resource(FunctionContext* context, const Block& block,
471
                               const ColumnNumbers& arguments, AIResource& config,
472
196
                               std::shared_ptr<AIAdapter>& adapter) const {
473
196
        const ColumnWithTypeAndName& resource_column = block.get_by_position(arguments[0]);
474
196
        StringRef resource_name_ref = resource_column.column->get_data_at(0);
475
196
        std::string resource_name = std::string(resource_name_ref.data, resource_name_ref.size);
476
477
196
        const std::shared_ptr<std::map<std::string, TAIResource>>& ai_resources =
478
196
                context->state()->get_query_ctx()->get_ai_resources();
479
196
        DORIS_CHECK(ai_resources);
480
196
        auto it = ai_resources->find(resource_name);
481
196
        DORIS_CHECK(it != ai_resources->end());
482
196
        PrimitiveType input_type = INVALID_TYPE;
483
196
        if (arguments.size() > 1) {
484
194
            input_type =
485
194
                    remove_nullable(block.get_by_position(arguments[1]).type)->get_primitive_type();
486
194
        }
487
196
        config = assert_cast<const Derived&>(*this).select_ai_resource(it->second, input_type);
488
489
196
        normalize_endpoint(config);
490
491
196
        adapter = AIAdapterFactory::create_adapter(config.provider_type);
492
196
        DORIS_CHECK(adapter);
493
494
196
        adapter->init(config);
495
196
        return Status::OK();
496
196
    }
_ZNK5doris10AIFunctionINS_13FunctionEmbedEE19_init_from_resourceEPNS_15FunctionContextERKNS_5BlockERKSt6vectorIjSaIjEERNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEE
Line
Count
Source
472
30
                               std::shared_ptr<AIAdapter>& adapter) const {
473
30
        const ColumnWithTypeAndName& resource_column = block.get_by_position(arguments[0]);
474
30
        StringRef resource_name_ref = resource_column.column->get_data_at(0);
475
30
        std::string resource_name = std::string(resource_name_ref.data, resource_name_ref.size);
476
477
30
        const std::shared_ptr<std::map<std::string, TAIResource>>& ai_resources =
478
30
                context->state()->get_query_ctx()->get_ai_resources();
479
30
        DORIS_CHECK(ai_resources);
480
30
        auto it = ai_resources->find(resource_name);
481
30
        DORIS_CHECK(it != ai_resources->end());
482
30
        PrimitiveType input_type = INVALID_TYPE;
483
30
        if (arguments.size() > 1) {
484
28
            input_type =
485
28
                    remove_nullable(block.get_by_position(arguments[1]).type)->get_primitive_type();
486
28
        }
487
30
        config = assert_cast<const Derived&>(*this).select_ai_resource(it->second, input_type);
488
489
30
        normalize_endpoint(config);
490
491
30
        adapter = AIAdapterFactory::create_adapter(config.provider_type);
492
30
        DORIS_CHECK(adapter);
493
494
30
        adapter->init(config);
495
30
        return Status::OK();
496
30
    }
_ZNK5doris10AIFunctionINS_16FunctionAIFilterEE19_init_from_resourceEPNS_15FunctionContextERKNS_5BlockERKSt6vectorIjSaIjEERNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEE
Line
Count
Source
472
94
                               std::shared_ptr<AIAdapter>& adapter) const {
473
94
        const ColumnWithTypeAndName& resource_column = block.get_by_position(arguments[0]);
474
94
        StringRef resource_name_ref = resource_column.column->get_data_at(0);
475
94
        std::string resource_name = std::string(resource_name_ref.data, resource_name_ref.size);
476
477
94
        const std::shared_ptr<std::map<std::string, TAIResource>>& ai_resources =
478
94
                context->state()->get_query_ctx()->get_ai_resources();
479
94
        DORIS_CHECK(ai_resources);
480
94
        auto it = ai_resources->find(resource_name);
481
94
        DORIS_CHECK(it != ai_resources->end());
482
94
        PrimitiveType input_type = INVALID_TYPE;
483
94
        if (arguments.size() > 1) {
484
94
            input_type =
485
94
                    remove_nullable(block.get_by_position(arguments[1]).type)->get_primitive_type();
486
94
        }
487
94
        config = assert_cast<const Derived&>(*this).select_ai_resource(it->second, input_type);
488
489
94
        normalize_endpoint(config);
490
491
94
        adapter = AIAdapterFactory::create_adapter(config.provider_type);
492
94
        DORIS_CHECK(adapter);
493
494
94
        adapter->init(config);
495
94
        return Status::OK();
496
94
    }
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_20FunctionAIFixGrammarEE19_init_from_resourceEPNS_15FunctionContextERKNS_5BlockERKSt6vectorIjSaIjEERNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEE
_ZNK5doris10AIFunctionINS_19FunctionAISentimentEE19_init_from_resourceEPNS_15FunctionContextERKNS_5BlockERKSt6vectorIjSaIjEERNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEE
Line
Count
Source
472
4
                               std::shared_ptr<AIAdapter>& adapter) const {
473
4
        const ColumnWithTypeAndName& resource_column = block.get_by_position(arguments[0]);
474
4
        StringRef resource_name_ref = resource_column.column->get_data_at(0);
475
4
        std::string resource_name = std::string(resource_name_ref.data, resource_name_ref.size);
476
477
4
        const std::shared_ptr<std::map<std::string, TAIResource>>& ai_resources =
478
4
                context->state()->get_query_ctx()->get_ai_resources();
479
4
        DORIS_CHECK(ai_resources);
480
4
        auto it = ai_resources->find(resource_name);
481
4
        DORIS_CHECK(it != ai_resources->end());
482
4
        PrimitiveType input_type = INVALID_TYPE;
483
4
        if (arguments.size() > 1) {
484
4
            input_type =
485
4
                    remove_nullable(block.get_by_position(arguments[1]).type)->get_primitive_type();
486
4
        }
487
4
        config = assert_cast<const Derived&>(*this).select_ai_resource(it->second, input_type);
488
489
4
        normalize_endpoint(config);
490
491
4
        adapter = AIAdapterFactory::create_adapter(config.provider_type);
492
4
        DORIS_CHECK(adapter);
493
494
4
        adapter->init(config);
495
4
        return Status::OK();
496
4
    }
_ZNK5doris10AIFunctionINS_19FunctionAISummarizeEE19_init_from_resourceEPNS_15FunctionContextERKNS_5BlockERKSt6vectorIjSaIjEERNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEE
Line
Count
Source
472
14
                               std::shared_ptr<AIAdapter>& adapter) const {
473
14
        const ColumnWithTypeAndName& resource_column = block.get_by_position(arguments[0]);
474
14
        StringRef resource_name_ref = resource_column.column->get_data_at(0);
475
14
        std::string resource_name = std::string(resource_name_ref.data, resource_name_ref.size);
476
477
14
        const std::shared_ptr<std::map<std::string, TAIResource>>& ai_resources =
478
14
                context->state()->get_query_ctx()->get_ai_resources();
479
14
        DORIS_CHECK(ai_resources);
480
14
        auto it = ai_resources->find(resource_name);
481
14
        DORIS_CHECK(it != ai_resources->end());
482
14
        PrimitiveType input_type = INVALID_TYPE;
483
14
        if (arguments.size() > 1) {
484
14
            input_type =
485
14
                    remove_nullable(block.get_by_position(arguments[1]).type)->get_primitive_type();
486
14
        }
487
14
        config = assert_cast<const Derived&>(*this).select_ai_resource(it->second, input_type);
488
489
14
        normalize_endpoint(config);
490
491
14
        adapter = AIAdapterFactory::create_adapter(config.provider_type);
492
14
        DORIS_CHECK(adapter);
493
494
14
        adapter->init(config);
495
14
        return Status::OK();
496
14
    }
_ZNK5doris10AIFunctionINS_18FunctionAIClassifyEE19_init_from_resourceEPNS_15FunctionContextERKNS_5BlockERKSt6vectorIjSaIjEERNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEE
Line
Count
Source
472
4
                               std::shared_ptr<AIAdapter>& adapter) const {
473
4
        const ColumnWithTypeAndName& resource_column = block.get_by_position(arguments[0]);
474
4
        StringRef resource_name_ref = resource_column.column->get_data_at(0);
475
4
        std::string resource_name = std::string(resource_name_ref.data, resource_name_ref.size);
476
477
4
        const std::shared_ptr<std::map<std::string, TAIResource>>& ai_resources =
478
4
                context->state()->get_query_ctx()->get_ai_resources();
479
4
        DORIS_CHECK(ai_resources);
480
4
        auto it = ai_resources->find(resource_name);
481
4
        DORIS_CHECK(it != ai_resources->end());
482
4
        PrimitiveType input_type = INVALID_TYPE;
483
4
        if (arguments.size() > 1) {
484
4
            input_type =
485
4
                    remove_nullable(block.get_by_position(arguments[1]).type)->get_primitive_type();
486
4
        }
487
4
        config = assert_cast<const Derived&>(*this).select_ai_resource(it->second, input_type);
488
489
4
        normalize_endpoint(config);
490
491
4
        adapter = AIAdapterFactory::create_adapter(config.provider_type);
492
4
        DORIS_CHECK(adapter);
493
494
4
        adapter->init(config);
495
4
        return Status::OK();
496
4
    }
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_17FunctionAIExtractEE19_init_from_resourceEPNS_15FunctionContextERKNS_5BlockERKSt6vectorIjSaIjEERNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEE
_ZNK5doris10AIFunctionINS_18FunctionAIGenerateEE19_init_from_resourceEPNS_15FunctionContextERKNS_5BlockERKSt6vectorIjSaIjEERNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEE
Line
Count
Source
472
6
                               std::shared_ptr<AIAdapter>& adapter) const {
473
6
        const ColumnWithTypeAndName& resource_column = block.get_by_position(arguments[0]);
474
6
        StringRef resource_name_ref = resource_column.column->get_data_at(0);
475
6
        std::string resource_name = std::string(resource_name_ref.data, resource_name_ref.size);
476
477
6
        const std::shared_ptr<std::map<std::string, TAIResource>>& ai_resources =
478
6
                context->state()->get_query_ctx()->get_ai_resources();
479
6
        DORIS_CHECK(ai_resources);
480
6
        auto it = ai_resources->find(resource_name);
481
6
        DORIS_CHECK(it != ai_resources->end());
482
6
        PrimitiveType input_type = INVALID_TYPE;
483
6
        if (arguments.size() > 1) {
484
6
            input_type =
485
6
                    remove_nullable(block.get_by_position(arguments[1]).type)->get_primitive_type();
486
6
        }
487
6
        config = assert_cast<const Derived&>(*this).select_ai_resource(it->second, input_type);
488
489
6
        normalize_endpoint(config);
490
491
6
        adapter = AIAdapterFactory::create_adapter(config.provider_type);
492
6
        DORIS_CHECK(adapter);
493
494
6
        adapter->init(config);
495
6
        return Status::OK();
496
6
    }
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_14FunctionAIMaskEE19_init_from_resourceEPNS_15FunctionContextERKNS_5BlockERKSt6vectorIjSaIjEERNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEE
_ZNK5doris10AIFunctionINS_20FunctionAISimilarityEE19_init_from_resourceEPNS_15FunctionContextERKNS_5BlockERKSt6vectorIjSaIjEERNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEE
Line
Count
Source
472
44
                               std::shared_ptr<AIAdapter>& adapter) const {
473
44
        const ColumnWithTypeAndName& resource_column = block.get_by_position(arguments[0]);
474
44
        StringRef resource_name_ref = resource_column.column->get_data_at(0);
475
44
        std::string resource_name = std::string(resource_name_ref.data, resource_name_ref.size);
476
477
44
        const std::shared_ptr<std::map<std::string, TAIResource>>& ai_resources =
478
44
                context->state()->get_query_ctx()->get_ai_resources();
479
44
        DORIS_CHECK(ai_resources);
480
44
        auto it = ai_resources->find(resource_name);
481
44
        DORIS_CHECK(it != ai_resources->end());
482
44
        PrimitiveType input_type = INVALID_TYPE;
483
44
        if (arguments.size() > 1) {
484
44
            input_type =
485
44
                    remove_nullable(block.get_by_position(arguments[1]).type)->get_primitive_type();
486
44
        }
487
44
        config = assert_cast<const Derived&>(*this).select_ai_resource(it->second, input_type);
488
489
44
        normalize_endpoint(config);
490
491
44
        adapter = AIAdapterFactory::create_adapter(config.provider_type);
492
44
        DORIS_CHECK(adapter);
493
494
44
        adapter->init(config);
495
44
        return Status::OK();
496
44
    }
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_19FunctionAITranslateEE19_init_from_resourceEPNS_15FunctionContextERKNS_5BlockERKSt6vectorIjSaIjEERNS_10AIResourceERSt10shared_ptrINS_9AIAdapterEE
497
498
166
    AIResource select_ai_resource(const TAIResource& resource, PrimitiveType /*input_type*/) const {
499
166
        return AIResource(resource);
500
166
    }
_ZNK5doris10AIFunctionINS_16FunctionAIFilterEE18select_ai_resourceERKNS_11TAIResourceENS_13PrimitiveTypeE
Line
Count
Source
498
94
    AIResource select_ai_resource(const TAIResource& resource, PrimitiveType /*input_type*/) const {
499
94
        return AIResource(resource);
500
94
    }
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_20FunctionAIFixGrammarEE18select_ai_resourceERKNS_11TAIResourceENS_13PrimitiveTypeE
_ZNK5doris10AIFunctionINS_19FunctionAISentimentEE18select_ai_resourceERKNS_11TAIResourceENS_13PrimitiveTypeE
Line
Count
Source
498
4
    AIResource select_ai_resource(const TAIResource& resource, PrimitiveType /*input_type*/) const {
499
4
        return AIResource(resource);
500
4
    }
_ZNK5doris10AIFunctionINS_19FunctionAISummarizeEE18select_ai_resourceERKNS_11TAIResourceENS_13PrimitiveTypeE
Line
Count
Source
498
14
    AIResource select_ai_resource(const TAIResource& resource, PrimitiveType /*input_type*/) const {
499
14
        return AIResource(resource);
500
14
    }
_ZNK5doris10AIFunctionINS_18FunctionAIClassifyEE18select_ai_resourceERKNS_11TAIResourceENS_13PrimitiveTypeE
Line
Count
Source
498
4
    AIResource select_ai_resource(const TAIResource& resource, PrimitiveType /*input_type*/) const {
499
4
        return AIResource(resource);
500
4
    }
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_17FunctionAIExtractEE18select_ai_resourceERKNS_11TAIResourceENS_13PrimitiveTypeE
_ZNK5doris10AIFunctionINS_18FunctionAIGenerateEE18select_ai_resourceERKNS_11TAIResourceENS_13PrimitiveTypeE
Line
Count
Source
498
6
    AIResource select_ai_resource(const TAIResource& resource, PrimitiveType /*input_type*/) const {
499
6
        return AIResource(resource);
500
6
    }
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_14FunctionAIMaskEE18select_ai_resourceERKNS_11TAIResourceENS_13PrimitiveTypeE
_ZNK5doris10AIFunctionINS_20FunctionAISimilarityEE18select_ai_resourceERKNS_11TAIResourceENS_13PrimitiveTypeE
Line
Count
Source
498
44
    AIResource select_ai_resource(const TAIResource& resource, PrimitiveType /*input_type*/) const {
499
44
        return AIResource(resource);
500
44
    }
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_19FunctionAITranslateEE18select_ai_resourceERKNS_11TAIResourceENS_13PrimitiveTypeE
501
502
    // Serializes one text batch into the shared JSON-array prompt format consumed by LLM
503
    // providers for batch string functions.
504
    Status build_batch_prompt(const std::vector<std::string>& batch_prompts,
505
44
                              std::string& prompt) const {
506
44
        rapidjson::StringBuffer buffer;
507
44
        rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
508
509
44
        writer.StartArray();
510
98
        for (size_t i = 0; i < batch_prompts.size(); ++i) {
511
54
            writer.StartObject();
512
54
            writer.Key("idx");
513
54
            writer.Uint64(i);
514
54
            writer.Key("input");
515
54
            writer.String(batch_prompts[i].data(),
516
54
                          static_cast<rapidjson::SizeType>(batch_prompts[i].size()));
517
54
            writer.EndObject();
518
54
        }
519
44
        writer.EndArray();
520
521
44
        prompt = buffer.GetString();
522
44
        return Status::OK();
523
44
    }
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_16FunctionAIFilterEE18build_batch_promptERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERS9_
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_20FunctionAIFixGrammarEE18build_batch_promptERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERS9_
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_19FunctionAISentimentEE18build_batch_promptERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERS9_
_ZNK5doris10AIFunctionINS_19FunctionAISummarizeEE18build_batch_promptERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERS9_
Line
Count
Source
505
44
                              std::string& prompt) const {
506
44
        rapidjson::StringBuffer buffer;
507
44
        rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
508
509
44
        writer.StartArray();
510
98
        for (size_t i = 0; i < batch_prompts.size(); ++i) {
511
54
            writer.StartObject();
512
54
            writer.Key("idx");
513
54
            writer.Uint64(i);
514
54
            writer.Key("input");
515
54
            writer.String(batch_prompts[i].data(),
516
54
                          static_cast<rapidjson::SizeType>(batch_prompts[i].size()));
517
54
            writer.EndObject();
518
54
        }
519
44
        writer.EndArray();
520
521
44
        prompt = buffer.GetString();
522
44
        return Status::OK();
523
44
    }
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_18FunctionAIClassifyEE18build_batch_promptERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERS9_
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_17FunctionAIExtractEE18build_batch_promptERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERS9_
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_18FunctionAIGenerateEE18build_batch_promptERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERS9_
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_14FunctionAIMaskEE18build_batch_promptERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERS9_
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_20FunctionAISimilarityEE18build_batch_promptERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERS9_
Unexecuted instantiation: _ZNK5doris10AIFunctionINS_19FunctionAITranslateEE18build_batch_promptERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS9_EERS9_
524
};
525
526
} // namespace doris