Copilot commented on code in PR #11127:
URL: https://github.com/apache/gravitino/pull/11127#discussion_r3257136835


##########
plugins/idp-basic/src/test/java/org/apache/gravitino/idp/storage/mapper/provider/base/TestIdpGroupMetaBaseSQLProvider.java:
##########
@@ -0,0 +1,162 @@
+/*
+ * 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.gravitino.idp.storage.mapper.provider.base;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.gravitino.idp.storage.po.IdpGroupPO;
+import org.apache.ibatis.builder.BuilderException;
+import org.apache.ibatis.mapping.BoundSql;
+import org.apache.ibatis.mapping.SqlSource;
+import org.apache.ibatis.scripting.xmltags.XMLLanguageDriver;
+import org.apache.ibatis.session.Configuration;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class TestIdpGroupMetaBaseSQLProvider {
+
+  protected IdpGroupMetaBaseSQLProvider createProvider() {
+    return new IdpGroupMetaBaseSQLProvider() {
+      @Override
+      protected String currentTimeMillisExpression() {
+        return "CURRENT_TIME_MILLIS()";
+      }
+    };
+  }
+
+  protected String expectedDeleteAtClause() {
+    return "deleted_at = CURRENT_TIME_MILLIS()";
+  }
+
+  protected String expectedDeleteIdpGroupMetasByLegacyTimelineSql() {
+    return "DELETE FROM idp_group_meta WHERE deleted_at > 0 AND deleted_at < 
#{legacyTimeline}"
+        + " LIMIT #{limit}";
+  }
+
+  @Test
+  void testSelectIdpGroup() {
+    String normalizedSql = 
createProvider().selectIdpGroup("group").replaceAll("\\s+", " ").trim();
+
+    Assertions.assertTrue(normalizedSql.contains("SELECT group_id as 
groupId"));
+    Assertions.assertTrue(normalizedSql.contains("FROM idp_group_meta"));
+    Assertions.assertTrue(
+        normalizedSql.contains("WHERE group_name = #{groupName} AND deleted_at 
= 0"));
+  }
+
+  @Test
+  void testSelectIdpGroups() {
+    String script = createProvider().selectIdpGroups(Arrays.asList("dev", 
"ops"));
+    Map<String, Object> params = new HashMap<>();
+    params.put("groupNames", Arrays.asList("dev", "ops"));
+
+    String normalizedSql = renderScript(script, params);
+
+    Assertions.assertTrue(normalizedSql.contains("SELECT group_id as 
groupId"));
+    Assertions.assertTrue(normalizedSql.contains("FROM idp_group_meta"));
+    Assertions.assertTrue(normalizedSql.matches(".*group_name IN \\( \\? , \\? 
\\).*"));
+    Assertions.assertFalse(normalizedSql.matches(".*\\b1\\s*=\\s*0\\b.*"));
+  }
+
+  @Test
+  void testSelectIdpGroupsWithEmptyGroupNames() {
+    String script = createProvider().selectIdpGroups(Collections.emptyList());
+    Map<String, Object> params = new HashMap<>();
+    params.put("groupNames", Collections.emptyList());
+
+    String normalizedSql = renderScript(script, params);
+
+    Assertions.assertFalse(
+        normalizedSql.matches(".*\\bIN\\s*\\(\\s*\\).*"),
+        "Empty groupNames should not generate invalid SQL IN (...) with no 
values");
+    Assertions.assertFalse(normalizedSql.matches(".*\\b1\\s*=\\s*0\\b.*"));
+    Assertions.assertEquals(
+        "SELECT group_id as groupId, group_name as groupName, current_version 
as"
+            + " currentVersion, last_version as lastVersion, deleted_at as 
deletedAt FROM"
+            + " idp_group_meta WHERE deleted_at = 0",
+        normalizedSql);

Review Comment:
   These assertions are overly sensitive to MyBatis-generated 
whitespace/punctuation (e.g., whether placeholders render as `(?,?)` vs `( ? , 
? )`). This makes the tests brittle across MyBatis/H2/PostgreSQL driver 
versions. Prefer asserting on structure (e.g., `contains(\"group_name IN\")` 
and counting `?` placeholders) or using a regex that ignores optional 
whitespace around commas/parentheses.
   



##########
plugins/idp-basic/src/test/java/org/apache/gravitino/idp/storage/mapper/provider/base/TestIdpGroupMetaBaseSQLProvider.java:
##########
@@ -0,0 +1,162 @@
+/*
+ * 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.gravitino.idp.storage.mapper.provider.base;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.gravitino.idp.storage.po.IdpGroupPO;
+import org.apache.ibatis.builder.BuilderException;
+import org.apache.ibatis.mapping.BoundSql;
+import org.apache.ibatis.mapping.SqlSource;
+import org.apache.ibatis.scripting.xmltags.XMLLanguageDriver;
+import org.apache.ibatis.session.Configuration;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class TestIdpGroupMetaBaseSQLProvider {
+
+  protected IdpGroupMetaBaseSQLProvider createProvider() {
+    return new IdpGroupMetaBaseSQLProvider() {
+      @Override
+      protected String currentTimeMillisExpression() {
+        return "CURRENT_TIME_MILLIS()";
+      }
+    };
+  }
+
+  protected String expectedDeleteAtClause() {
+    return "deleted_at = CURRENT_TIME_MILLIS()";
+  }
+
+  protected String expectedDeleteIdpGroupMetasByLegacyTimelineSql() {
+    return "DELETE FROM idp_group_meta WHERE deleted_at > 0 AND deleted_at < 
#{legacyTimeline}"
+        + " LIMIT #{limit}";
+  }
+
+  @Test
+  void testSelectIdpGroup() {
+    String normalizedSql = 
createProvider().selectIdpGroup("group").replaceAll("\\s+", " ").trim();
+
+    Assertions.assertTrue(normalizedSql.contains("SELECT group_id as 
groupId"));
+    Assertions.assertTrue(normalizedSql.contains("FROM idp_group_meta"));
+    Assertions.assertTrue(
+        normalizedSql.contains("WHERE group_name = #{groupName} AND deleted_at 
= 0"));
+  }
+
+  @Test
+  void testSelectIdpGroups() {
+    String script = createProvider().selectIdpGroups(Arrays.asList("dev", 
"ops"));
+    Map<String, Object> params = new HashMap<>();
+    params.put("groupNames", Arrays.asList("dev", "ops"));
+
+    String normalizedSql = renderScript(script, params);
+
+    Assertions.assertTrue(normalizedSql.contains("SELECT group_id as 
groupId"));
+    Assertions.assertTrue(normalizedSql.contains("FROM idp_group_meta"));
+    Assertions.assertTrue(normalizedSql.matches(".*group_name IN \\( \\? , \\? 
\\).*"));

Review Comment:
   These assertions are overly sensitive to MyBatis-generated 
whitespace/punctuation (e.g., whether placeholders render as `(?,?)` vs `( ? , 
? )`). This makes the tests brittle across MyBatis/H2/PostgreSQL driver 
versions. Prefer asserting on structure (e.g., `contains(\"group_name IN\")` 
and counting `?` placeholders) or using a regex that ignores optional 
whitespace around commas/parentheses.



##########
plugins/idp-basic/src/test/java/org/apache/gravitino/idp/storage/mapper/TestIdpBasicMapperPackageProvider.java:
##########
@@ -0,0 +1,52 @@
+/*
+ * 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.gravitino.idp.storage.mapper;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.List;
+import java.util.ServiceLoader;
+import 
org.apache.gravitino.idp.storage.mapper.provider.IdpBasicMapperPackageProvider;
+import 
org.apache.gravitino.storage.relational.mapper.provider.MapperPackageProvider;
+import org.junit.jupiter.api.Test;
+
+public class TestIdpBasicMapperPackageProvider {
+
+  @Test
+  public void testGetMapperClasses() {
+    MapperPackageProvider provider = new IdpBasicMapperPackageProvider();
+
+    assertEquals(
+        List.of(IdpUserMetaMapper.class, IdpGroupMetaMapper.class), 
provider.getMapperClasses());

Review Comment:
   This test hard-codes the order of mapper classes. If `getMapperClasses()` is 
intended to be an unordered set of mappers, this will cause unnecessary 
failures on benign reordering. Consider asserting membership instead (e.g., 
same elements regardless of order) unless order is a required contract.
   



##########
plugins/idp-basic/src/main/java/org/apache/gravitino/idp/storage/mapper/provider/postgresql/IdpGroupMetaPostgreSQLProvider.java:
##########
@@ -0,0 +1,42 @@
+/*
+ * 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.gravitino.idp.storage.mapper.provider.postgresql;
+
+import org.apache.gravitino.idp.storage.mapper.IdpGroupMetaMapper;
+import 
org.apache.gravitino.idp.storage.mapper.provider.base.IdpGroupMetaBaseSQLProvider;
+import org.apache.ibatis.annotations.Param;
+
+public class IdpGroupMetaPostgreSQLProvider extends 
IdpGroupMetaBaseSQLProvider {
+
+  @Override
+  protected String currentTimeMillisExpression() {
+    return "CAST(EXTRACT(EPOCH FROM CURRENT_TIMESTAMP) * 1000 AS BIGINT)";
+  }
+
+  @Override
+  public String deleteIdpGroupMetasByLegacyTimeline(
+      @Param("legacyTimeline") Long legacyTimeline, @Param("limit") int limit) 
{
+    return "DELETE FROM "
+        + IdpGroupMetaMapper.IDP_GROUP_TABLE_NAME
+        + " WHERE group_id IN (SELECT group_id FROM "

Review Comment:
   This PostgreSQL delete can remove rows that do not satisfy the 
legacy-timeline predicate if the table ever contains multiple rows per 
`group_id` (the outer `DELETE` only filters by `group_id`). To keep semantics 
aligned with the base provider (and be robust to duplicates), include 
`deleted_at > 0 AND deleted_at < #{legacyTimeline}` in the outer `DELETE` as 
well (or delete by a unique row identifier / CTE).
   



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