nicusX commented on code in PR #22:
URL: 
https://github.com/apache/flink-connector-prometheus/pull/22#discussion_r2121683685


##########
flink-connector-prometheus/src/main/java/org/apache/flink/connector/prometheus/table/RowDataToPrometheusTimeSeriesConverter.java:
##########
@@ -0,0 +1,116 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.flink.connector.prometheus.table;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.connector.prometheus.sink.PrometheusTimeSeries;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.data.TimestampData;
+import org.apache.flink.table.types.DataType;
+
+import java.util.Arrays;
+import java.util.List;
+
+import static org.apache.flink.table.data.RowData.createFieldGetter;
+
+/**
+ * Converts from Flink Table API internal type of {@link RowData} to {@link 
PrometheusTimeSeries}.
+ */
+@Internal
+public class RowDataToPrometheusTimeSeriesConverter {
+
+    private final DataType physicalDataType;
+    private final PrometheusConfig prometheusConfig;
+
+    public RowDataToPrometheusTimeSeriesConverter(
+            DataType physicalDataType, PrometheusConfig prometheusConfig) {
+        this.physicalDataType = physicalDataType;
+        this.prometheusConfig = prometheusConfig;
+    }
+
+    public PrometheusTimeSeries convertRowData(RowData row) {
+        List<DataTypes.Field> fields = DataType.getFields(physicalDataType);
+
+        PrometheusTimeSeries.Builder builder = PrometheusTimeSeries.builder();
+        Double sampleValue = null;
+        Long sampleTimestamp = null;
+
+        for (int i = 0; i < fields.size(); i++) {
+            DataTypes.Field field = fields.get(i);
+            RowData.FieldGetter fieldGetter =
+                    
createFieldGetter(fields.get(i).getDataType().getLogicalType(), i);
+            FieldValue fieldValue = new 
FieldValue(fieldGetter.getFieldOrNull(row));
+            String fieldName = field.getName();
+
+            if (fieldName.equals(prometheusConfig.getMetricName())) {
+                builder.withMetricName(fieldValue.getStringValue());
+            } else if 
(fieldName.equals(prometheusConfig.getMetricSampleKey())) {
+                sampleValue = fieldValue.getDoubleValue();
+            } else if (prometheusConfig.getLabelKeys().contains(fieldName)) {

Review Comment:
   Labels in Prometheus are {key, value}
   you are adding the fieldName as key, and the content of the field as value
   ```
   builder.addLabel(fieldName, fieldValue.getStringValue())
   ```
   Which is fine. But it means all records will have the same set of Label 
keys, because in a table abstraction all records have the same fields by 
definition. Label values will be different, being the content of the fields.
   As I mentioned, it's limited compared to DataStream but acceptable



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to