@@ -29,6 +29,7 @@ enum FeatureSignatureType {
29
29
kFeatureSignatureBinaryLabel = 200 ,
30
30
kFeatureSignatureMulticlassLabel = 201 ,
31
31
kFeatureSignatureRegressionLabel = 202 ,
32
+ kFeatureSignatureIndex = 300 ,
32
33
};
33
34
34
35
template <typename T>
@@ -115,6 +116,17 @@ struct MulticlassLabel {
115
116
}
116
117
};
117
118
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
+ };
118
130
119
131
template <typename T>
120
132
struct RegressionLabel {
@@ -246,6 +258,12 @@ struct GCFormat {
246
258
}
247
259
break ;
248
260
}
261
+ case kFeatureSignatureIndex : {
262
+ if (!is_null) {
263
+ instance_index = input;
264
+ }
265
+ break ;
266
+ }
249
267
default : {
250
268
++slot_number;
251
269
break ;
@@ -258,12 +276,18 @@ struct GCFormat {
258
276
}
259
277
260
278
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;
262
285
}
263
286
264
287
size_t slot_number = 1 ;
265
288
std::string instance_label;
266
289
std::string instance_feature;
290
+ int64_t instance_index = -1 ;
267
291
};
268
292
269
293
struct CSV {
@@ -473,6 +497,19 @@ void DefaultUdfLibrary::InitFeatureSignature() {
473
497
)" )
474
498
.args_in <bool , int16_t , int32_t , int64_t >();
475
499
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
+
476
513
RegisterExternalTemplate<v1::RegressionLabel>(" regression_label" )
477
514
.doc (R"(
478
515
@brief Set the column signature to regression label.
0 commit comments