[ 
https://issues.apache.org/jira/browse/PHOENIX-7144?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17795896#comment-17795896
 ] 

ASF GitHub Bot commented on PHOENIX-7144:
-----------------------------------------

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


##########
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);
+                }
+                //assert BaseTable is not being queried
+                for (PhoenixTableMetric metric : 
getPhoenixTableClientMetrics().get(dataTable)) {
+                    assertMetricValue(metric, SELECT_SQL_COUNTER, 0, 
CompareOp.EQ);

Review Comment:
   Same comment as above





> TableLevel Phoenix Metrics returns base tableName when queried for Index 
> Table.
> -------------------------------------------------------------------------------
>
>                 Key: PHOENIX-7144
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-7144
>             Project: Phoenix
>          Issue Type: Improvement
>            Reporter: vikas meka
>            Assignee: vikas meka
>            Priority: Major
>             Fix For: 5.2.0
>
>
> TableClient Metrics returns BaseTable Name when Indexes are used. Phoenix 
> Result set uses Index TableName while storing as DDL queries use BaseTable 
> Name while storing metrics in HashMap.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to