alex-plekhanov commented on code in PR #11724:
URL: https://github.com/apache/ignite/pull/11724#discussion_r1883492989


##########
modules/core/src/main/java/org/apache/ignite/internal/jdbc/thin/JdbcThinConnection.java:
##########
@@ -1122,6 +1140,8 @@ JdbcResultWithIo sendRequest(JdbcRequest req, 
JdbcThinStatement stmt, @Nullable
                     if (req instanceof JdbcQueryExecuteRequest)
                         qryReq = (JdbcQueryExecuteRequest)req;
 
+                    req.clientInfo(clientInfo);

Review Comment:
   Why do we send client info with every request, but read it only for 
`JdbcQueryExecuteRequest` and `JdbcBatchExecuteRequest`?



##########
modules/calcite/src/test/java/org/apache/ignite/JdbcSetClientInfoTest.java:
##########
@@ -0,0 +1,292 @@
+/*
+ * 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;

Review Comment:
   org.apache.ignite.internal.processors.query.calcite.jdbc



##########
modules/calcite/src/test/java/org/apache/ignite/JdbcSetClientInfoTest.java:
##########
@@ -0,0 +1,292 @@
+/*
+ * 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;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.List;
+import java.util.Properties;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.cache.query.annotations.QuerySqlFunction;
+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.internal.IgniteEx;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.resources.SessionContextProviderResource;
+import org.apache.ignite.session.SessionContext;
+import org.apache.ignite.session.SessionContextProvider;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.jetbrains.annotations.Nullable;
+import org.junit.Test;
+
+/** */
+public class JdbcSetClientInfoTest extends GridCommonAbstractTest {
+    /** */
+    private static final String SESSION_ID = "sessionId";
+
+    /** */
+    private static final String URL = 
"jdbc:ignite:thin://127.0.0.1?queryEngine=calcite";
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String 
instanceName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(instanceName);
+
+        cfg.setSqlConfiguration(new SqlConfiguration()
+            .setQueryEnginesConfiguration(new 
CalciteQueryEngineConfiguration().setDefault(true)));
+
+        cfg.setCacheConfiguration(new CacheConfiguration<>()
+            .setName(DEFAULT_CACHE_NAME)
+            .setSqlSchema("PUBLIC")
+            .setSqlFunctionClasses(SessionContextFunctions.class));
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        IgniteEx ign = startGrids(3);
+
+        query(ign, "create table PUBLIC.MYTABLE(id int primary key, sessionId 
varchar);");
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() {
+        stopAllGrids();
+    }
+
+    /** */
+    @Test
+    public void testSetClientInfo() throws Exception {
+        try (Connection conn = DriverManager.getConnection(URL)) {
+            checkSessionId(conn, null);
+            checkSessionId(conn, "1234");
+        }
+    }
+
+    /** */
+    @Test
+    public void testResetClientInfo() throws Exception {
+        try (Connection conn = DriverManager.getConnection(URL)) {
+            checkSessionId(conn, "1234");
+            checkSessionId(conn, "4567");
+            checkSessionId(conn, null);
+        }
+    }
+
+    /** */
+    private void checkSessionId(Connection conn, @Nullable String sesId) 
throws Exception {

Review Comment:
   Let's move this method below public methods.



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/jdbc/JdbcRequest.java:
##########
@@ -103,6 +106,9 @@ public class JdbcRequest extends ClientListenerRequestNoId 
implements JdbcRawBin
     /** Request id. */
     private long reqId;
 
+    /** Client info set with {@link JdbcThinConnection#setClientInfo} methods. 
*/
+    private @Nullable Map<String, String> clientInfo;

Review Comment:
   Only required for `JdbcQueryExecuteRequest` and `JdbcBatchExecuteRequest`. 
Let's introduce something like `JdbcClientInfoAwareRequest` class and inherit 
required classes from it.



##########
modules/calcite/src/test/java/org/apache/ignite/JdbcSetClientInfoTest.java:
##########
@@ -0,0 +1,292 @@
+/*
+ * 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;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.List;
+import java.util.Properties;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.cache.query.annotations.QuerySqlFunction;
+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.internal.IgniteEx;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.resources.SessionContextProviderResource;
+import org.apache.ignite.session.SessionContext;
+import org.apache.ignite.session.SessionContextProvider;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.jetbrains.annotations.Nullable;
+import org.junit.Test;
+
+/** */
+public class JdbcSetClientInfoTest extends GridCommonAbstractTest {
+    /** */
+    private static final String SESSION_ID = "sessionId";
+
+    /** */
+    private static final String URL = 
"jdbc:ignite:thin://127.0.0.1?queryEngine=calcite";
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String 
instanceName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(instanceName);
+
+        cfg.setSqlConfiguration(new SqlConfiguration()
+            .setQueryEnginesConfiguration(new 
CalciteQueryEngineConfiguration().setDefault(true)));
+
+        cfg.setCacheConfiguration(new CacheConfiguration<>()
+            .setName(DEFAULT_CACHE_NAME)
+            .setSqlSchema("PUBLIC")
+            .setSqlFunctionClasses(SessionContextFunctions.class));
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        IgniteEx ign = startGrids(3);
+
+        query(ign, "create table PUBLIC.MYTABLE(id int primary key, sessionId 
varchar);");
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() {
+        stopAllGrids();
+    }
+
+    /** */
+    @Test
+    public void testSetClientInfo() throws Exception {
+        try (Connection conn = DriverManager.getConnection(URL)) {
+            checkSessionId(conn, null);
+            checkSessionId(conn, "1234");
+        }
+    }
+
+    /** */
+    @Test
+    public void testResetClientInfo() throws Exception {
+        try (Connection conn = DriverManager.getConnection(URL)) {
+            checkSessionId(conn, "1234");
+            checkSessionId(conn, "4567");
+            checkSessionId(conn, null);
+        }
+    }
+
+    /** */
+    private void checkSessionId(Connection conn, @Nullable String sesId) 
throws Exception {
+        setClientInfo(conn, sesId);
+
+        ResultSet set = jdbcQuery(conn, "select sessionId() as SESSION_ID;");
+
+        set.next();
+
+        String actSesId = set.getString("SESSION_ID");
+
+        assertEquals(sesId, actSesId);
+    }
+
+    /** */
+    @Test
+    public void testWhereClause() throws Exception {
+        for (int i = 0; i < 100; i++) {
+            String sesId = i % 2 == 0 ? "1" : "2";
+
+            query(grid(0), "insert into PUBLIC.MYTABLE(id, sessionId) values 
(?, ?);", i, sesId);
+        }
+
+        try (Connection conn = DriverManager.getConnection(URL)) {
+            for (String sesId: F.asList("1", "2")) {
+

Review Comment:
   Redundant NL



##########
modules/calcite/src/test/java/org/apache/ignite/JdbcSetClientInfoTest.java:
##########
@@ -0,0 +1,292 @@
+/*
+ * 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;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.List;
+import java.util.Properties;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.cache.query.annotations.QuerySqlFunction;
+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.internal.IgniteEx;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.resources.SessionContextProviderResource;
+import org.apache.ignite.session.SessionContext;
+import org.apache.ignite.session.SessionContextProvider;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.jetbrains.annotations.Nullable;
+import org.junit.Test;
+
+/** */
+public class JdbcSetClientInfoTest extends GridCommonAbstractTest {
+    /** */
+    private static final String SESSION_ID = "sessionId";
+
+    /** */
+    private static final String URL = 
"jdbc:ignite:thin://127.0.0.1?queryEngine=calcite";

Review Comment:
   Calcite engine is configured by default, it's not necessary to doublicate it 
in the URL



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/jdbc/JdbcRequestHandler.java:
##########
@@ -1151,7 +1162,7 @@ private void executeBatchedQuery(SqlFieldsQueryEx qry, 
List<Integer> updCntsAcc,
             }
 
             List<FieldsQueryCursor<List<?>>> qryRes = 
connCtx.kernalContext().query().querySqlFields(
-                null, qry, cliCtx, true, true, cancel);
+                null, qry, cliCtx, true, true, GridCacheQueryType.SQL_FIELDS, 
cancel, appAttrs);

Review Comment:
   Consider using of  `cliCtx` to pass `appAttrs` instead of modifying method 
declaration. 



-- 
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: notifications-unsubscr...@ignite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to