Copilot commented on code in PR #7843:
URL: https://github.com/apache/incubator-seata/pull/7843#discussion_r2616192128


##########
rm-datasource/src/main/java/org/apache/seata/rm/datasource/sql/struct/cache/DmTableMetaCache.java:
##########
@@ -121,19 +124,35 @@ protected void processIndexes(TableMeta tableMeta, 
ResultSet rs) throws SQLExcep
     }
 
     protected void processPrimaries(TableMeta tableMeta, ResultSet rs) throws 
SQLException {
+        List<String> primaryKeyColumns = new ArrayList<>();
         while (rs.next()) {
             String pkColName;
             try {
                 pkColName = rs.getString("COLUMN_NAME");
             } catch (Exception e) {
                 pkColName = rs.getString("PK_NAME");
             }
+            if (StringUtils.isNotBlank(pkColName)) {
+                primaryKeyColumns.add(pkColName);
+            }

Review Comment:
   The primary key columns are collected in the order they appear in the 
ResultSet from getPrimaryKeys(), but there's no guarantee this matches the 
actual primary key definition order. According to JDBC specification, 
getPrimaryKeys() returns results ordered by COLUMN_NAME, not by KEY_SEQ (the 
ordinal position within the primary key). This means for composite primary 
keys, the order might not match the index column order, leading to incorrect 
comparisons at line 154.
   
   Consider reading the KEY_SEQ column from the ResultSet and sorting the 
primaryKeyColumns list by this ordinal position to ensure correct order 
matching with index columns.



##########
rm-datasource/src/main/java/org/apache/seata/rm/datasource/sql/struct/cache/KingbaseTableMetaCache.java:
##########
@@ -120,19 +123,35 @@ protected void processIndexes(TableMeta tableMeta, 
ResultSet rs) throws SQLExcep
     }
 
     protected void processPrimaries(TableMeta tableMeta, ResultSet rs) throws 
SQLException {
+        List<String> primaryKeyColumns = new ArrayList<>();
         while (rs.next()) {
             String pkColName;
             try {
                 pkColName = rs.getString("COLUMN_NAME");
             } catch (Exception e) {
                 pkColName = rs.getString("PK_NAME");
             }
+            if (StringUtils.isNotBlank(pkColName)) {
+                primaryKeyColumns.add(pkColName);
+            }

Review Comment:
   The primary key columns are collected in the order they appear in the 
ResultSet from getPrimaryKeys(), but there's no guarantee this matches the 
actual primary key definition order. According to JDBC specification, 
getPrimaryKeys() returns results ordered by COLUMN_NAME, not by KEY_SEQ (the 
ordinal position within the primary key). This means for composite primary 
keys, the order might not match the index column order, leading to incorrect 
comparisons at line 153.
   
   Consider reading the KEY_SEQ column from the ResultSet and sorting the 
primaryKeyColumns list by this ordinal position to ensure correct order 
matching with index columns.



##########
rm-datasource/src/test/java/org/apache/seata/rm/datasource/sql/struct/cache/DmTableMetaCacheTest.java:
##########
@@ -39,35 +42,294 @@ public class DmTableMetaCacheTest {
         new Object[] {"", "", "dt1", "name3", Types.VARCHAR, "VARCHAR", 64, 0, 
10, 0, "", "", 0, 0, 64, 4, "YES", "NO"}
     };
 
-    private static Object[][] indexMetas = new Object[][] {
-        new Object[] {"id", "id", false, "", 3, 0, "A", 34},
-        new Object[] {"name1", "name1", false, "", 3, 1, "A", 34},
-        new Object[] {"name2", "name2", true, "", 3, 2, "A", 34},
+    private static final Object[][] indexMetas = new Object[][] {
+        new Object[] {"IDX_ID", "id", false, "", 3, 0, "A", 34},
+        new Object[] {"IDX_NAME1", "name1", false, "", 3, 1, "A", 34},
+        new Object[] {"IDX_NAME2", "name2", true, "", 3, 2, "A", 34},
     };
 
     private static Object[][] pkMetas = new Object[][] {new Object[] {"id"}};
 
     private static Object[][] tableMetas = new Object[][] {new Object[] {"", 
"t", "dt1"}};
 
     @Test
-    public void getTableMetaTest() throws SQLException {
+    public void testGetTableMetaBasic() throws SQLException {
         MockDriver mockDriver = new MockDriver(columnMetas, indexMetas, 
pkMetas, tableMetas);
         DruidDataSource dataSource = new DruidDataSource();
-        dataSource.setUrl("jdbc:mock:xxx");
+        dataSource.setUrl("jdbc:mock:dm");
         dataSource.setDriver(mockDriver);
 
         DataSourceProxy proxy = 
DataSourceProxyTest.getDataSourceProxy(dataSource);
+        TableMetaCache tableMetaCache = 
TableMetaCacheFactory.getTableMetaCache(JdbcConstants.DM);
+
+        TableMeta tableMeta = 
tableMetaCache.getTableMeta(proxy.getPlainConnection(), "t.dt1", 
proxy.getResourceId());
+
+        Assertions.assertNotNull(tableMeta);
+        Assertions.assertEquals(4, tableMeta.getAllColumns().size());
+        Assertions.assertEquals(3, tableMeta.getAllIndexes().size());
+    }
+
+    @Test
+    public void testGetTableMetaWithSchemaPrefix() throws SQLException {
+        MockDriver mockDriver = new MockDriver(columnMetas, indexMetas, 
pkMetas, tableMetas);
+        DruidDataSource dataSource = new DruidDataSource();
+        dataSource.setUrl("jdbc:mock:dm");
+        dataSource.setDriver(mockDriver);
+
+        DataSourceProxy proxy = 
DataSourceProxyTest.getDataSourceProxy(dataSource);
+        TableMetaCache tableMetaCache = 
TableMetaCacheFactory.getTableMetaCache(JdbcConstants.DM);
+
+        TableMeta tableMeta = 
tableMetaCache.getTableMeta(proxy.getPlainConnection(), "t.dt1", 
proxy.getResourceId());
+
+        Assertions.assertNotNull(tableMeta);
+        Assertions.assertEquals("DT1", tableMeta.getTableName());
+        Assertions.assertEquals("t.dt1", tableMeta.getOriginalTableName());
+    }
+
+    @Test
+    public void testGetTableMetaWithQuotedIdentifiers() throws SQLException {
+        Object[][] quotedTableMetas = new Object[][] {new Object[] {"", "t", 
"MixedCase"}};
+        Object[][] quotedColumnMetas = new Object[][] {
+            new Object[] {
+                "", "", "MixedCase", "Id", Types.INTEGER, "INTEGER", 64, 0, 
10, 1, "", "", 0, 0, 64, 1, "NO", "YES"
+            },
+            new Object[] {
+                "", "", "MixedCase", "Name", Types.VARCHAR, "VARCHAR", 64, 0, 
10, 0, "", "", 0, 0, 64, 2, "YES", "NO"
+            }
+        };
+        Object[][] quotedIndexMetas = new Object[][] {new Object[] {"idx_id", 
"Id", false, "", 3, 0, "A", 34}};
+        Object[][] quotedPKMetas = new Object[][] {new Object[] {"Id"}};
+
+        MockDriver mockDriver = new MockDriver(quotedColumnMetas, 
quotedIndexMetas, quotedPKMetas, quotedTableMetas);
+        DruidDataSource dataSource = new DruidDataSource();
+        dataSource.setUrl("jdbc:mock:dm");
+        dataSource.setDriver(mockDriver);
+
+        DataSourceProxy proxy = 
DataSourceProxyTest.getDataSourceProxy(dataSource);
+        TableMetaCache tableMetaCache = 
TableMetaCacheFactory.getTableMetaCache(JdbcConstants.DM);
+
+        TableMeta tableMeta =
+                tableMetaCache.getTableMeta(proxy.getPlainConnection(), 
"t.\"MixedCase\"", proxy.getResourceId());
+
+        Assertions.assertNotNull(tableMeta);
+        Assertions.assertEquals("MixedCase", tableMeta.getTableName());
+    }
+
+    @Test
+    public void testGetTableMetaThrowsExceptionWhenNoIndex() throws 
SQLException {
+        Object[][] emptyIndexMetas = new Object[][] {};
+        Object[][] emptyTableMetas = new Object[][] {new Object[] {"", "t", 
"dt1"}};
+
+        MockDriver mockDriver = new MockDriver(columnMetas, emptyIndexMetas, 
pkMetas, emptyTableMetas);
+        DruidDataSource dataSource = new DruidDataSource();
+        dataSource.setUrl("jdbc:mock:dm");
+        dataSource.setDriver(mockDriver);
+
+        DataSourceProxy proxy = 
DataSourceProxyTest.getDataSourceProxy(dataSource);
+        TableMetaCache tableMetaCache = 
TableMetaCacheFactory.getTableMetaCache(JdbcConstants.DM);
+
+        Assertions.assertThrows(ShouldNeverHappenException.class, () -> {
+            tableMetaCache.getTableMeta(proxy.getPlainConnection(), "dt1", 
proxy.getResourceId());
+        });
+    }
+
+    @Test
+    public void testGetTableMetaWithCompositeIndex() throws SQLException {
+        Object[][] compositeIndexMetas = new Object[][] {
+            new Object[] {"idx_pk", "id", false, "", 3, 1, "A", 34},
+            new Object[] {"idx_composite", "name1", false, "", 3, 1, "A", 34},
+            new Object[] {"idx_composite", "name2", false, "", 3, 2, "A", 34}
+        };
+
+        MockDriver mockDriver = new MockDriver(columnMetas, 
compositeIndexMetas, pkMetas, tableMetas);
+        DruidDataSource dataSource = new DruidDataSource();
+        dataSource.setUrl("jdbc:mock:dm");
+        dataSource.setDriver(mockDriver);
+
+        DataSourceProxy proxy = 
DataSourceProxyTest.getDataSourceProxy(dataSource);
+        TableMetaCache tableMetaCache = 
TableMetaCacheFactory.getTableMetaCache(JdbcConstants.DM);
+
+        TableMeta tableMeta = 
tableMetaCache.getTableMeta(proxy.getPlainConnection(), "t.dt1", 
proxy.getResourceId());
+
+        Assertions.assertNotNull(tableMeta);
+        Assertions.assertTrue(tableMeta.getAllIndexes().size() >= 1);
+        Assertions.assertEquals(4, tableMeta.getAllColumns().size());
+    }

Review Comment:
   This test creates an index "idx_pk" on the "id" column which matches the 
primary key, but doesn't verify that it's correctly identified as 
IndexType.PRIMARY. The test should assert that idx_pk has PRIMARY index type to 
ensure the fix works correctly for composite index scenarios where one index 
happens to match the primary key.
   
   Consider adding:
   IndexMeta pkIndex = tableMeta.getAllIndexes().get("idx_pk");
   Assertions.assertEquals(IndexType.PRIMARY, pkIndex.getIndextype());



##########
rm-datasource/src/test/java/org/apache/seata/rm/datasource/sql/struct/cache/DmTableMetaCacheTest.java:
##########
@@ -39,35 +42,294 @@ public class DmTableMetaCacheTest {
         new Object[] {"", "", "dt1", "name3", Types.VARCHAR, "VARCHAR", 64, 0, 
10, 0, "", "", 0, 0, 64, 4, "YES", "NO"}
     };
 
-    private static Object[][] indexMetas = new Object[][] {
-        new Object[] {"id", "id", false, "", 3, 0, "A", 34},
-        new Object[] {"name1", "name1", false, "", 3, 1, "A", 34},
-        new Object[] {"name2", "name2", true, "", 3, 2, "A", 34},
+    private static final Object[][] indexMetas = new Object[][] {

Review Comment:
   The variable declaration was changed from non-final to final, but this 
inconsistency exists with `columnMetas` (line 38) which remains non-final. For 
consistency, either all test data arrays should be final, or none should be. 
Since these are test fixtures that shouldn't be modified, making all of them 
final would be the better choice.



##########
rm-datasource/src/test/java/org/apache/seata/rm/datasource/sql/struct/cache/DmTableMetaCacheTest.java:
##########
@@ -39,35 +42,294 @@ public class DmTableMetaCacheTest {
         new Object[] {"", "", "dt1", "name3", Types.VARCHAR, "VARCHAR", 64, 0, 
10, 0, "", "", 0, 0, 64, 4, "YES", "NO"}
     };
 
-    private static Object[][] indexMetas = new Object[][] {
-        new Object[] {"id", "id", false, "", 3, 0, "A", 34},
-        new Object[] {"name1", "name1", false, "", 3, 1, "A", 34},
-        new Object[] {"name2", "name2", true, "", 3, 2, "A", 34},
+    private static final Object[][] indexMetas = new Object[][] {
+        new Object[] {"IDX_ID", "id", false, "", 3, 0, "A", 34},
+        new Object[] {"IDX_NAME1", "name1", false, "", 3, 1, "A", 34},
+        new Object[] {"IDX_NAME2", "name2", true, "", 3, 2, "A", 34},
     };
 
     private static Object[][] pkMetas = new Object[][] {new Object[] {"id"}};
 
     private static Object[][] tableMetas = new Object[][] {new Object[] {"", 
"t", "dt1"}};
 
     @Test
-    public void getTableMetaTest() throws SQLException {
+    public void testGetTableMetaBasic() throws SQLException {
         MockDriver mockDriver = new MockDriver(columnMetas, indexMetas, 
pkMetas, tableMetas);
         DruidDataSource dataSource = new DruidDataSource();
-        dataSource.setUrl("jdbc:mock:xxx");
+        dataSource.setUrl("jdbc:mock:dm");
         dataSource.setDriver(mockDriver);
 
         DataSourceProxy proxy = 
DataSourceProxyTest.getDataSourceProxy(dataSource);
+        TableMetaCache tableMetaCache = 
TableMetaCacheFactory.getTableMetaCache(JdbcConstants.DM);
+
+        TableMeta tableMeta = 
tableMetaCache.getTableMeta(proxy.getPlainConnection(), "t.dt1", 
proxy.getResourceId());
+
+        Assertions.assertNotNull(tableMeta);
+        Assertions.assertEquals(4, tableMeta.getAllColumns().size());
+        Assertions.assertEquals(3, tableMeta.getAllIndexes().size());
+    }
+
+    @Test
+    public void testGetTableMetaWithSchemaPrefix() throws SQLException {
+        MockDriver mockDriver = new MockDriver(columnMetas, indexMetas, 
pkMetas, tableMetas);
+        DruidDataSource dataSource = new DruidDataSource();
+        dataSource.setUrl("jdbc:mock:dm");
+        dataSource.setDriver(mockDriver);
+
+        DataSourceProxy proxy = 
DataSourceProxyTest.getDataSourceProxy(dataSource);
+        TableMetaCache tableMetaCache = 
TableMetaCacheFactory.getTableMetaCache(JdbcConstants.DM);
+
+        TableMeta tableMeta = 
tableMetaCache.getTableMeta(proxy.getPlainConnection(), "t.dt1", 
proxy.getResourceId());
+
+        Assertions.assertNotNull(tableMeta);
+        Assertions.assertEquals("DT1", tableMeta.getTableName());
+        Assertions.assertEquals("t.dt1", tableMeta.getOriginalTableName());
+    }
+
+    @Test
+    public void testGetTableMetaWithQuotedIdentifiers() throws SQLException {
+        Object[][] quotedTableMetas = new Object[][] {new Object[] {"", "t", 
"MixedCase"}};
+        Object[][] quotedColumnMetas = new Object[][] {
+            new Object[] {
+                "", "", "MixedCase", "Id", Types.INTEGER, "INTEGER", 64, 0, 
10, 1, "", "", 0, 0, 64, 1, "NO", "YES"
+            },
+            new Object[] {
+                "", "", "MixedCase", "Name", Types.VARCHAR, "VARCHAR", 64, 0, 
10, 0, "", "", 0, 0, 64, 2, "YES", "NO"
+            }
+        };
+        Object[][] quotedIndexMetas = new Object[][] {new Object[] {"idx_id", 
"Id", false, "", 3, 0, "A", 34}};
+        Object[][] quotedPKMetas = new Object[][] {new Object[] {"Id"}};
+
+        MockDriver mockDriver = new MockDriver(quotedColumnMetas, 
quotedIndexMetas, quotedPKMetas, quotedTableMetas);
+        DruidDataSource dataSource = new DruidDataSource();
+        dataSource.setUrl("jdbc:mock:dm");
+        dataSource.setDriver(mockDriver);
+
+        DataSourceProxy proxy = 
DataSourceProxyTest.getDataSourceProxy(dataSource);
+        TableMetaCache tableMetaCache = 
TableMetaCacheFactory.getTableMetaCache(JdbcConstants.DM);
+
+        TableMeta tableMeta =
+                tableMetaCache.getTableMeta(proxy.getPlainConnection(), 
"t.\"MixedCase\"", proxy.getResourceId());
+
+        Assertions.assertNotNull(tableMeta);
+        Assertions.assertEquals("MixedCase", tableMeta.getTableName());
+    }
+
+    @Test
+    public void testGetTableMetaThrowsExceptionWhenNoIndex() throws 
SQLException {
+        Object[][] emptyIndexMetas = new Object[][] {};
+        Object[][] emptyTableMetas = new Object[][] {new Object[] {"", "t", 
"dt1"}};
+
+        MockDriver mockDriver = new MockDriver(columnMetas, emptyIndexMetas, 
pkMetas, emptyTableMetas);
+        DruidDataSource dataSource = new DruidDataSource();
+        dataSource.setUrl("jdbc:mock:dm");
+        dataSource.setDriver(mockDriver);
+
+        DataSourceProxy proxy = 
DataSourceProxyTest.getDataSourceProxy(dataSource);
+        TableMetaCache tableMetaCache = 
TableMetaCacheFactory.getTableMetaCache(JdbcConstants.DM);
+
+        Assertions.assertThrows(ShouldNeverHappenException.class, () -> {
+            tableMetaCache.getTableMeta(proxy.getPlainConnection(), "dt1", 
proxy.getResourceId());
+        });
+    }
+
+    @Test
+    public void testGetTableMetaWithCompositeIndex() throws SQLException {
+        Object[][] compositeIndexMetas = new Object[][] {
+            new Object[] {"idx_pk", "id", false, "", 3, 1, "A", 34},
+            new Object[] {"idx_composite", "name1", false, "", 3, 1, "A", 34},
+            new Object[] {"idx_composite", "name2", false, "", 3, 2, "A", 34}
+        };
+
+        MockDriver mockDriver = new MockDriver(columnMetas, 
compositeIndexMetas, pkMetas, tableMetas);
+        DruidDataSource dataSource = new DruidDataSource();
+        dataSource.setUrl("jdbc:mock:dm");
+        dataSource.setDriver(mockDriver);
+
+        DataSourceProxy proxy = 
DataSourceProxyTest.getDataSourceProxy(dataSource);
+        TableMetaCache tableMetaCache = 
TableMetaCacheFactory.getTableMetaCache(JdbcConstants.DM);
+
+        TableMeta tableMeta = 
tableMetaCache.getTableMeta(proxy.getPlainConnection(), "t.dt1", 
proxy.getResourceId());
+
+        Assertions.assertNotNull(tableMeta);
+        Assertions.assertTrue(tableMeta.getAllIndexes().size() >= 1);
+        Assertions.assertEquals(4, tableMeta.getAllColumns().size());
+    }
+
+    @Test
+    public void testGetTableMetaWithPrimaryKeyIndex() throws SQLException {
+        MockDriver mockDriver = new MockDriver(columnMetas, indexMetas, 
pkMetas, tableMetas);
+        DruidDataSource dataSource = new DruidDataSource();
+        dataSource.setUrl("jdbc:mock:dm");
+        dataSource.setDriver(mockDriver);
+
+        DataSourceProxy proxy = 
DataSourceProxyTest.getDataSourceProxy(dataSource);
+        TableMetaCache tableMetaCache = 
TableMetaCacheFactory.getTableMetaCache(JdbcConstants.DM);
+
+        TableMeta tableMeta = 
tableMetaCache.getTableMeta(proxy.getPlainConnection(), "t.dt1", 
proxy.getResourceId());
+
+        Assertions.assertNotNull(tableMeta);
+        IndexMeta pkIndex = tableMeta.getAllIndexes().get("IDX_ID");
+        Assertions.assertNotNull(pkIndex);
+        Assertions.assertEquals(IndexType.PRIMARY, pkIndex.getIndextype());
+    }
+
+    @Test
+    public void testGetTableMetaWithUniqueIndex() throws SQLException {
+        MockDriver mockDriver = new MockDriver(columnMetas, indexMetas, 
pkMetas, tableMetas);
+        DruidDataSource dataSource = new DruidDataSource();
+        dataSource.setUrl("jdbc:mock:dm");
+        dataSource.setDriver(mockDriver);
+
+        DataSourceProxy proxy = 
DataSourceProxyTest.getDataSourceProxy(dataSource);
+        TableMetaCache tableMetaCache = 
TableMetaCacheFactory.getTableMetaCache(JdbcConstants.DM);
+
+        TableMeta tableMeta = 
tableMetaCache.getTableMeta(proxy.getPlainConnection(), "t.dt1", 
proxy.getResourceId());
+
+        Assertions.assertNotNull(tableMeta);
+        IndexMeta uniqueIndex = tableMeta.getAllIndexes().get("IDX_NAME1");
+        Assertions.assertNotNull(uniqueIndex);
+        Assertions.assertEquals(IndexType.UNIQUE, uniqueIndex.getIndextype());
+    }
+
+    @Test
+    public void testGetTableMetaWithNormalIndex() throws SQLException {
+        MockDriver mockDriver = new MockDriver(columnMetas, indexMetas, 
pkMetas, tableMetas);
+        DruidDataSource dataSource = new DruidDataSource();
+        dataSource.setUrl("jdbc:mock:dm");
+        dataSource.setDriver(mockDriver);
+
+        DataSourceProxy proxy = 
DataSourceProxyTest.getDataSourceProxy(dataSource);
+        TableMetaCache tableMetaCache = 
TableMetaCacheFactory.getTableMetaCache(JdbcConstants.DM);
+
+        TableMeta tableMeta = 
tableMetaCache.getTableMeta(proxy.getPlainConnection(), "t.dt1", 
proxy.getResourceId());
+
+        Assertions.assertNotNull(tableMeta);
+        IndexMeta normalIndex = tableMeta.getAllIndexes().get("IDX_NAME2");
+        Assertions.assertNotNull(normalIndex);
+        Assertions.assertEquals(IndexType.NORMAL, normalIndex.getIndextype());
+    }
+
+    @Test
+    public void testGetTableMetaWithNullIndexName() throws SQLException {
+        Object[][] nullIndexMetas = new Object[][] {
+            new Object[] {"idx_id", "id", false, "", 3, 0, "A", 34},
+            new Object[] {null, "name1", false, "", 3, 1, "A", 34}
+        };
+
+        MockDriver mockDriver = new MockDriver(columnMetas, nullIndexMetas, 
pkMetas, tableMetas);
+        DruidDataSource dataSource = new DruidDataSource();
+        dataSource.setUrl("jdbc:mock:dm");
+        dataSource.setDriver(mockDriver);
+
+        DataSourceProxy proxy = 
DataSourceProxyTest.getDataSourceProxy(dataSource);
+        TableMetaCache tableMetaCache = 
TableMetaCacheFactory.getTableMetaCache(JdbcConstants.DM);
+
+        TableMeta tableMeta = 
tableMetaCache.getTableMeta(proxy.getPlainConnection(), "t.dt1", 
proxy.getResourceId());
+
+        Assertions.assertNotNull(tableMeta);
+        Assertions.assertTrue(tableMeta.getAllIndexes().containsKey("IDX_ID"));
+        Assertions.assertFalse(tableMeta.getAllIndexes().containsKey(null));
+    }
 
+    @Test
+    public void testGetTableMetaCaching() throws SQLException {
+        MockDriver mockDriver = new MockDriver(columnMetas, indexMetas, 
pkMetas, tableMetas);
+        DruidDataSource dataSource = new DruidDataSource();
+        dataSource.setUrl("jdbc:mock:dm");
+        dataSource.setDriver(mockDriver);
+
+        DataSourceProxy proxy = 
DataSourceProxyTest.getDataSourceProxy(dataSource);
+        TableMetaCache tableMetaCache = 
TableMetaCacheFactory.getTableMetaCache(JdbcConstants.DM);
+
+        TableMeta tableMeta1 = 
tableMetaCache.getTableMeta(proxy.getPlainConnection(), "t.dt1", 
proxy.getResourceId());
+        TableMeta tableMeta2 = 
tableMetaCache.getTableMeta(proxy.getPlainConnection(), "T.DT1", 
proxy.getResourceId());
+
+        Assertions.assertSame(tableMeta1, tableMeta2, "Cache should return 
same instance");
+    }
+
+    @Test
+    public void testGetTableMetaWithoutSchemaPrefix() throws SQLException {
+        Object[][] singleTableMetas = new Object[][] {new Object[] {"", 
"public", "dt1"}};
+
+        MockDriver mockDriver = new MockDriver(columnMetas, indexMetas, 
pkMetas, singleTableMetas);
+        DruidDataSource dataSource = new DruidDataSource();
+        dataSource.setUrl("jdbc:mock:dm");
+        dataSource.setDriver(mockDriver);
+
+        DataSourceProxy proxy = 
DataSourceProxyTest.getDataSourceProxy(dataSource);
         TableMetaCache tableMetaCache = 
TableMetaCacheFactory.getTableMetaCache(JdbcConstants.DM);
 
         TableMeta tableMeta = 
tableMetaCache.getTableMeta(proxy.getPlainConnection(), "dt1", 
proxy.getResourceId());
 
         Assertions.assertNotNull(tableMeta);
         Assertions.assertEquals("DT1", tableMeta.getTableName());
-        Assertions.assertEquals("dt1", tableMeta.getOriginalTableName());
+    }
+
+    @Test
+    public void testGetTableMetaWithLowerCaseTable() throws SQLException {
+        Object[][] lowerCaseTableMetas = new Object[][] {new Object[] {"", 
"t", "lowertable"}};
+        Object[][] lowerCaseColumnMetas = new Object[][] {
+            new Object[] {
+                "", "", "lowertable", "id", Types.INTEGER, "INTEGER", 64, 0, 
10, 1, "", "", 0, 0, 64, 1, "NO", "YES"
+            }
+        };
+        Object[][] lowerCaseIndexMetas = new Object[][] {new Object[] 
{"idx_id", "id", false, "", 3, 0, "A", 34}};
+        Object[][] lowerCasePKMetas = new Object[][] {new Object[] {"id"}};
+
+        MockDriver mockDriver =
+                new MockDriver(lowerCaseColumnMetas, lowerCaseIndexMetas, 
lowerCasePKMetas, lowerCaseTableMetas);
+        DruidDataSource dataSource = new DruidDataSource();
+        dataSource.setUrl("jdbc:mock:dm");
+        dataSource.setDriver(mockDriver);
+
+        DataSourceProxy proxy = 
DataSourceProxyTest.getDataSourceProxy(dataSource);
+        TableMetaCache tableMetaCache = 
TableMetaCacheFactory.getTableMetaCache(JdbcConstants.DM);
+
+        TableMeta tableMeta =
+                tableMetaCache.getTableMeta(proxy.getPlainConnection(), 
"lowertable", proxy.getResourceId());
+
+        Assertions.assertNotNull(tableMeta);
+    }
+
+    @Test
+    public void testGetTableMetaWithMultiplePrimaryKeys() throws SQLException {
+        Object[][] multiPKMetas = new Object[][] {new Object[] {"id"}, new 
Object[] {"name1"}};
+        Object[][] multiPKIndexMetas = new Object[][] {
+            new Object[] {"idx_composite_pk", "id", false, "", 3, 1, "A", 34},
+            new Object[] {"idx_composite_pk", "name1", false, "", 3, 2, "A", 
34}
+        };
+
+        MockDriver mockDriver = new MockDriver(columnMetas, multiPKIndexMetas, 
multiPKMetas, tableMetas);
+        DruidDataSource dataSource = new DruidDataSource();
+        dataSource.setUrl("jdbc:mock:dm");
+        dataSource.setDriver(mockDriver);
+
+        DataSourceProxy proxy = 
DataSourceProxyTest.getDataSourceProxy(dataSource);
+        TableMetaCache tableMetaCache = 
TableMetaCacheFactory.getTableMetaCache(JdbcConstants.DM);
+
+        TableMeta tableMeta = 
tableMetaCache.getTableMeta(proxy.getPlainConnection(), "t.dt1", 
proxy.getResourceId());
+
+        Assertions.assertNotNull(tableMeta);
+        Assertions.assertTrue(tableMeta.getPrimaryKeyMap().size() >= 1);
+        Assertions.assertTrue(tableMeta.getAllIndexes().size() >= 1);
+    }

Review Comment:
   This test doesn't verify that the index with composite primary keys is 
actually marked as IndexType.PRIMARY. It only checks that at least one primary 
key exists and at least one index exists, but doesn't assert that 
idx_composite_pk has the correct PRIMARY index type. This misses validating the 
core fix for composite primary key handling.
   
   Consider adding an assertion like:
   IndexMeta pkIndex = tableMeta.getAllIndexes().get("idx_composite_pk");
   Assertions.assertEquals(IndexType.PRIMARY, pkIndex.getIndextype());



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to