tkhurana commented on code in PR #1755:
URL: https://github.com/apache/phoenix/pull/1755#discussion_r1424439330


##########
phoenix-core/src/it/java/org/apache/phoenix/monitoring/PhoenixTableLevelMetricsIT.java:
##########
@@ -1218,6 +1216,62 @@ private static void assertMetricValue(Metric m, 
MetricType checkType, long compa
         }
     }
 
+    @Test  public void testMetricsWithIndexUsage() throws Exception {
+        // Generate unique names for the table and index
+        String dataTable = generateUniqueName();
+        String indexName = generateUniqueName() + "_IDX";
+
+
+        try (Connection conn = getConnFromTestDriver()) {
+            // Create a mutable table with one key and one column
+            String tableDdl = "CREATE TABLE "
+                    + dataTable
+                    + " (K VARCHAR NOT NULL, V INTEGER, CONSTRAINT PK PRIMARY 
KEY(K))" + " IMMUTABLE_ROWS = true";
+            conn.createStatement().execute(tableDdl);
+
+            // Create an index for the column 'V'
+            String indexDdl = "CREATE INDEX " + indexName + " ON " + dataTable 
+ " (V)";
+            conn.createStatement().execute(indexDdl);
+        }
+
+        // Insert data into the table
+        String insertData = "UPSERT INTO " + dataTable + " VALUES (?, ?)";
+        try (Connection conn = getConnFromTestDriver();
+             PreparedStatement stmt = conn.prepareStatement(insertData)) {
+            for (int i = 1; i <= 10; i++) {
+                stmt.setString(1, "key" + i);
+                stmt.setInt(2, i);
+                stmt.executeUpdate();
+            }
+            conn.commit();
+        }
+
+        // Check if the index is being used
+        try (Connection conn = getConnFromTestDriver()) {
+            String query = "SELECT * FROM " + dataTable + " WHERE V = ?";
+            try (PreparedStatement stmt = conn.prepareStatement(query)) {
+                // Set a parameter value that corresponds to the data inserted
+                stmt.setInt(1, 5);
+                clearTableLevelMetrics();
+                // Execute the query
+                try (ResultSet resultSet = stmt.executeQuery()) {
+                    while (resultSet.next()) {
+
+                    }
+                }
+                
assertTrue(!getPhoenixTableClientMetrics().get(indexName).isEmpty());
+                // Assert that the index is used
+                for (PhoenixTableMetric metric : 
getPhoenixTableClientMetrics().get(indexName)) {
+                    assertMetricValue(metric, SELECT_SQL_COUNTER, 1, 
CompareOp.EQ);

Review Comment:
   Since we are only checking one metric it might be better to replace the for 
loop with an explicit check for that metric. That will improve the code 
readability since the loop is creating confusion.



-- 
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