@@ -29,6 +29,7 @@ enum FeatureSignatureType {
2929 kFeatureSignatureBinaryLabel = 200 ,
3030 kFeatureSignatureMulticlassLabel = 201 ,
3131 kFeatureSignatureRegressionLabel = 202 ,
32+ kFeatureSignatureIndex = 300 ,
3233};
3334
3435template <typename T>
@@ -115,6 +116,17 @@ struct MulticlassLabel {
115116 }
116117};
117118
119+ template <typename T>
120+ struct GCFormatIndex {
121+ using Args = Tuple<int32_t , Nullable<T>>(Nullable<T>);
122+ void operator ()(T v, bool is_null, int32_t * feature_signature, T* ret, bool * null_flag) {
123+ *feature_signature = kFeatureSignatureIndex ;
124+ *null_flag = is_null;
125+ if (!is_null) {
126+ *ret = v;
127+ }
128+ }
129+ };
118130
119131template <typename T>
120132struct RegressionLabel {
@@ -246,6 +258,12 @@ struct GCFormat {
246258 }
247259 break ;
248260 }
261+ case kFeatureSignatureIndex : {
262+ if (!is_null) {
263+ instance_index = input;
264+ }
265+ break ;
266+ }
249267 default : {
250268 ++slot_number;
251269 break ;
@@ -258,12 +276,18 @@ struct GCFormat {
258276 }
259277
260278 std::string Output () {
261- return instance_label + " | " + instance_feature;
279+ std::string instance_index_str = " " ;
280+ if (instance_index >= 0 ) {
281+ instance_index_str = " " + std::to_string (instance_index);
282+ }
283+ return instance_label + instance_index_str + " | " +
284+ instance_feature;
262285 }
263286
264287 size_t slot_number = 1 ;
265288 std::string instance_label;
266289 std::string instance_feature;
290+ int64_t instance_index = -1 ;
267291};
268292
269293struct CSV {
@@ -473,6 +497,19 @@ void DefaultUdfLibrary::InitFeatureSignature() {
473497 )" )
474498 .args_in <bool , int16_t , int32_t , int64_t >();
475499
500+ RegisterExternalTemplate<v1::GCFormatIndex>(" gcformat_index" )
501+ .doc (R"(
502+ @brief Set the index/lineno of gcformat output.
503+ Example:
504+ @code{.sql}
505+ select gcformat(gcformat_index(6));
506+ -- output 6
507+ @endcode
508+
509+ @since 0.9.3
510+ )" )
511+ .args_in <int16_t , int32_t , int64_t >();
512+
476513 RegisterExternalTemplate<v1::RegressionLabel>(" regression_label" )
477514 .doc (R"(
478515 @brief Set the column signature to regression label.
0 commit comments