Copilot commented on code in PR #13198:
URL: https://github.com/apache/ignite/pull/13198#discussion_r3353762668


##########
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/PublicApiIntegrationTest.java:
##########
@@ -0,0 +1,104 @@
+/*
+ * 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.ignite.internal.processors.query.calcite.integration;
+
+import java.util.List;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.calcite.CalciteQueryEngineConfiguration;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.SqlConfiguration;
+import org.apache.ignite.transactions.Transaction;
+import org.junit.Test;
+
+import static 
org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC;
+import static 
org.apache.ignite.transactions.TransactionIsolation.READ_COMMITTED;
+
+/** Public api integration tests. */
+public class PublicApiIntegrationTest extends AbstractBasicIntegrationTest {
+    /** */
+    @Override protected IgniteConfiguration getConfiguration(String 
igniteInstanceName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
+
+        cfg.setSqlConfiguration(new SqlConfiguration()
+            .setQueryEnginesConfiguration(new 
CalciteQueryEngineConfiguration().setDefault(true)));
+
+        return cfg;
+    }
+
+    /** */
+    @Test
+    public void testSimpleInsert() {
+        IgniteCache<Object, Object> cache = 
client.createCache(DEFAULT_CACHE_NAME);
+
+        runQuery(0, nodeCount() * 10, false, cache);
+
+        cache = cache.withKeepBinary();
+
+        runQuery(nodeCount() * 10, 2 * nodeCount() * 10, false, cache);
+
+        List<List<?>> res = cache.query(new SqlFieldsQuery("SELECT * FROM 
emp")).getAll();
+
+        assertEquals("Unexpected result set size: " + res.size(), 1, 
res.size());
+    }
+
+    /** */
+    @Test
+    public void testTxInsert() {
+        CacheConfiguration<Object, Object> ccfg = new 
CacheConfiguration<>(DEFAULT_CACHE_NAME);
+        ccfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
+
+        IgniteCache<?, ?> cache = client.createCache(ccfg);
+
+        runQuery(0, nodeCount() * 10, true, cache);
+
+        cache = cache.withKeepBinary();
+
+        runQuery(nodeCount() * 10, 2 * nodeCount() * 10, true, cache);
+
+        List<List<?>> res = cache.query(new SqlFieldsQuery("SELECT * FROM 
emp")).getAll();
+
+        assertEquals("Unexpected result set size: " + res.size(), 1, 
res.size());
+    }
+
+    /** */
+    private void runQuery(int begin, int end, boolean transactional, 
IgniteCache<?, ?> cache) {
+        Transaction tx = null;
+
+        cache.query(new SqlFieldsQuery("CREATE TABLE IF NOT EXISTS emp(empid 
INTEGER, deptid INTEGER, name VARCHAR, salary INTEGER, " +
+            "PRIMARY KEY(empid, deptid)) WITH \"AFFINITY_KEY=deptid" + 
(transactional ? ", ATOMICITY=transactional" : "") + "\""));
+
+        if (transactional) {
+            //noinspection resource
+            tx = client.transactions().txStart(PESSIMISTIC, READ_COMMITTED);
+        }
+
+        for (int i = begin; i < end; i++) {
+            cache.query(new SqlFieldsQuery("INSERT INTO emp (empid, deptid, 
name, salary) VALUES (?, ?, ?, ?)").setArgs(
+                i, i % 2, "Employee " + i, i / 10));
+
+            cache.query(new SqlFieldsQuery("UPDATE emp SET name = '' WHERE 
empid = ? AND deptid = ?").setArgs(i, i % 2));
+            cache.query(new SqlFieldsQuery("DELETE FROM emp WHERE empid = 
?").setArgs(i - 1)).getAll();
+        }
+
+        if (transactional)
+            tx.commit();
+    }

Review Comment:
   `runQuery` creates multiple `SqlFieldsQuery` cursors but does not 
close/consume them consistently (CREATE/INSERT/UPDATE are not followed by 
`getAll()` or try-with-resources). This can leak query resources and may keep 
entries in the running-queries registry, making the test flaky (especially 
since `AbstractBasicIntegrationTest.afterTest()` asserts running queries are 
empty). Also, starting a transaction without try-with-resources means it won’t 
be rolled back/closed if an assertion or query fails mid-loop.



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java:
##########
@@ -2695,7 +2695,7 @@ else if (GridDhtCacheEntry.ReaderId.contains(readers, 
nearNode.id())) {
                             null,
                             compRes.get1(),
                             compRes.get2(),
-                            req.keepBinary());
+                            true);

Review Comment:
   Hardcoding `keepBinary` to `true` when adding entry-processor results 
ignores the `keepBinary` flag from the request (`req.keepBinary()`). This can 
change the keepBinary contract for `invoke`/`invokeAll` and makes this code 
inconsistent with the other `addEntryProcessResult` call in the same class 
(which uses `req.keepBinary()`). It’s safer to pass through `req.keepBinary()` 
here as well so binary unwrapping behavior is controlled by the 
caller/operation context.



##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/util/Commons.java:
##########
@@ -569,4 +571,38 @@ public static boolean isBinaryComparable(Object o1, Object 
o2) {
     public static int compareBinary(Object o1, Object o2) {
         return BinaryUtils.binariesFactory.compareForDml(o1, o2);
     }
+
+    /**
+     * Makes current operation context as keepBinary.
+     *
+     * @param cctx Cache context.
+     * @return Old operation context.
+     */
+    public static CacheOperationContext 
setKeepBinaryContext(GridCacheContext<?, ?> cctx) {
+        CacheOperationContext opCtx = cctx.operationContextPerCall();
+
+        // Force keepBinary for operation context to avoid binary 
deserialization inside entry processor
+        CacheOperationContext newOpCtx = null;
+
+        if (opCtx == null)
+            // Mimics behavior of GridCacheAdapter#keepBinary and 
GridCacheProxyImpl#keepBinary
+            newOpCtx = new CacheOperationContext(false, false, true, null, 
false, null, false, null, null);
+        else if (!opCtx.isKeepBinary())
+            newOpCtx = opCtx.keepBinary();
+
+        if (newOpCtx != null)
+            cctx.operationContextPerCall(newOpCtx);
+
+        return opCtx;
+    }

Review Comment:
   `setKeepBinaryContext`/`restoreKeepBinaryContext` are introduced here, but 
they are not referenced anywhere in the calcite module (or elsewhere) in this 
PR. If they are required for Calcite DML (as the PR title suggests), they 
likely need to be applied around DML entry-processor invocations with a 
try/finally restore; otherwise this becomes dead/duplicated utility code that 
can silently diverge from `modules/indexing/.../DmlUtils` over time.



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