You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "timoninmaxim (via GitHub)" <gi...@apache.org> on 2024/12/10 15:01:36 UTC
[PR] IGNITE-23722 Map JDBC ClientInfo to ApplicationAttributes [ignite]
timoninmaxim opened a new pull request, #11724:
URL: https://github.com/apache/ignite/pull/11724
Thank you for submitting the pull request to the Apache Ignite.
In order to streamline the review of the contribution
we ask you to ensure the following steps have been taken:
### The Contribution Checklist
- [ ] There is a single JIRA ticket related to the pull request.
- [ ] The web-link to the pull request is attached to the JIRA ticket.
- [ ] The JIRA ticket has the _Patch Available_ state.
- [ ] The pull request body describes changes that have been made.
The description explains _WHAT_ and _WHY_ was made instead of _HOW_.
- [ ] The pull request title is treated as the final commit message.
The following pattern must be used: `IGNITE-XXXX Change summary` where `XXXX` - number of JIRA issue.
- [ ] A reviewer has been mentioned through the JIRA comments
(see [the Maintainers list](https://cwiki.apache.org/confluence/display/IGNITE/How+to+Contribute#HowtoContribute-ReviewProcessandMaintainers))
- [ ] The pull request has been checked by the Teamcity Bot and
the `green visa` attached to the JIRA ticket (see [TC.Bot: Check PR](https://mtcga.gridgain.com/prs.html))
### Notes
- [How to Contribute](https://cwiki.apache.org/confluence/display/IGNITE/How+to+Contribute)
- [Coding abbreviation rules](https://cwiki.apache.org/confluence/display/IGNITE/Abbreviation+Rules)
- [Coding Guidelines](https://cwiki.apache.org/confluence/display/IGNITE/Coding+Guidelines)
- [Apache Ignite Teamcity Bot](https://cwiki.apache.org/confluence/display/IGNITE/Apache+Ignite+Teamcity+Bot)
If you need any help, please email dev@ignite.apache.org or ask anу advice on http://asf.slack.com _#ignite_ channel.
--
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-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-23722 Map JDBC ClientInfo to ApplicationAttributes [ignite]
Posted by "alex-plekhanov (via GitHub)" <gi...@apache.org>.
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-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-23722 Map JDBC ClientInfo to ApplicationAttributes [ignite]
Posted by "timoninmaxim (via GitHub)" <gi...@apache.org>.
timoninmaxim merged PR #11724:
URL: https://github.com/apache/ignite/pull/11724
--
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-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org