You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by pt...@apache.org on 2025/01/22 09:54:02 UTC

(ignite-3) branch main updated: IGNITE-24276 Thin client: return actual table name from TABLE_GET (#5089)

This is an automated email from the ASF dual-hosted git repository.

ptupitsyn pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git


The following commit(s) were added to refs/heads/main by this push:
     new 4634c8a25c IGNITE-24276 Thin client: return actual table name from TABLE_GET (#5089)
4634c8a25c is described below

commit 4634c8a25caf49b32ea951ae5e1157a7e62fd1fc
Author: Pavel Tupitsyn <pt...@apache.org>
AuthorDate: Wed Jan 22 11:53:56 2025 +0200

    IGNITE-24276 Thin client: return actual table name from TABLE_GET (#5089)
    
    Return the original name of the resolved table from the server.
---
 .../requests/table/ClientTableGetRequest.java      | 19 ++++++++++++++++++
 .../ignite/internal/client/table/ClientTables.java |  4 +++-
 .../apache/ignite/client/AbstractClientTest.java   |  2 +-
 .../apache/ignite/client/ClientComputeTest.java    |  2 +-
 .../ignite/client/fakes/FakeIgniteTables.java      | 12 +++++------
 .../cpp/ignite/client/detail/table/tables_impl.cpp |  3 ++-
 .../cpp/tests/client-test/tables_test.cpp          |  6 +++---
 .../dotnet/Apache.Ignite.Tests/FakeServer.cs       |  1 +
 .../Apache.Ignite.Tests/Table/TablesTests.cs       |  9 +++++++++
 .../dotnet/Apache.Ignite/Internal/Table/Tables.cs  | 23 +++++++++++++++-------
 .../app/client/ItThinClientConnectionTest.java     | 17 ++++++++++++++++
 11 files changed, 78 insertions(+), 20 deletions(-)

diff --git a/modules/client-handler/src/main/java/org/apache/ignite/client/handler/requests/table/ClientTableGetRequest.java b/modules/client-handler/src/main/java/org/apache/ignite/client/handler/requests/table/ClientTableGetRequest.java
index f3e8457647..11b05f1300 100644
--- a/modules/client-handler/src/main/java/org/apache/ignite/client/handler/requests/table/ClientTableGetRequest.java
+++ b/modules/client-handler/src/main/java/org/apache/ignite/client/handler/requests/table/ClientTableGetRequest.java
@@ -21,6 +21,7 @@ import java.util.concurrent.CompletableFuture;
 import org.apache.ignite.internal.client.proto.ClientMessagePacker;
 import org.apache.ignite.internal.client.proto.ClientMessageUnpacker;
 import org.apache.ignite.internal.table.TableViewInternal;
+import org.apache.ignite.lang.util.IgniteNameUtils;
 import org.apache.ignite.table.IgniteTables;
 
 /**
@@ -47,7 +48,25 @@ public class ClientTableGetRequest {
                 out.packNil();
             } else {
                 out.packInt(((TableViewInternal) table).tableId());
+                out.packString(quoteTableNameIfNotAllUpper(table.name()));
             }
         });
     }
+
+    private static String quoteTableNameIfNotAllUpper(String name) {
+        // TODO: IGNITE-24029 use QualifiedName.
+        for (int i = 0; i < name.length(); i++) {
+            char ch = name.charAt(i);
+
+            if (Character.isDigit(ch) || ch == '_') {
+                continue;
+            }
+
+            if (!Character.isUpperCase(ch)) {
+                return IgniteNameUtils.quote(name);
+            }
+        }
+
+        return name;
+    }
 }
diff --git a/modules/client/src/main/java/org/apache/ignite/internal/client/table/ClientTables.java b/modules/client/src/main/java/org/apache/ignite/internal/client/table/ClientTables.java
index ba9d44adf7..baf128afbb 100644
--- a/modules/client/src/main/java/org/apache/ignite/internal/client/table/ClientTables.java
+++ b/modules/client/src/main/java/org/apache/ignite/internal/client/table/ClientTables.java
@@ -82,6 +82,8 @@ public class ClientTables implements IgniteTables {
         Objects.requireNonNull(name);
 
         return ch.serviceAsync(ClientOp.TABLE_GET, w -> w.out().packString(name),
-                r -> r.in().tryUnpackNil() ? null : new ClientTable(ch, marshallers, r.in().unpackInt(), name));
+                r -> r.in().tryUnpackNil()
+                        ? null
+                        : new ClientTable(ch, marshallers, r.in().unpackInt(), r.in().unpackString()));
     }
 }
diff --git a/modules/client/src/test/java/org/apache/ignite/client/AbstractClientTest.java b/modules/client/src/test/java/org/apache/ignite/client/AbstractClientTest.java
index 6f382e6b01..30e19cdb2d 100644
--- a/modules/client/src/test/java/org/apache/ignite/client/AbstractClientTest.java
+++ b/modules/client/src/test/java/org/apache/ignite/client/AbstractClientTest.java
@@ -41,7 +41,7 @@ import org.junit.jupiter.api.BeforeEach;
  * Base class for client tests.
  */
 public abstract class AbstractClientTest extends BaseIgniteAbstractTest {
-    protected static final String DEFAULT_TABLE = "default_test_table";
+    protected static final String DEFAULT_TABLE = "DEFAULT_TEST_TABLE";
 
     protected static TestServer testServer;
 
diff --git a/modules/client/src/test/java/org/apache/ignite/client/ClientComputeTest.java b/modules/client/src/test/java/org/apache/ignite/client/ClientComputeTest.java
index 1dc746ea3f..c0908449bf 100644
--- a/modules/client/src/test/java/org/apache/ignite/client/ClientComputeTest.java
+++ b/modules/client/src/test/java/org/apache/ignite/client/ClientComputeTest.java
@@ -207,7 +207,7 @@ public class ClientComputeTest extends BaseIgniteAbstractTest {
     @ParameterizedTest
     @ValueSource(booleans = {true, false})
     void testExecuteColocatedUpdatesTableCacheOnTableDrop(boolean forceLoadAssignment) {
-        String tableName = "drop-me";
+        String tableName = "DROP_ME";
 
         initServers(reqId -> false);
         createTable(tableName);
diff --git a/modules/client/src/test/java/org/apache/ignite/client/fakes/FakeIgniteTables.java b/modules/client/src/test/java/org/apache/ignite/client/fakes/FakeIgniteTables.java
index 94605d8553..514f228490 100644
--- a/modules/client/src/test/java/org/apache/ignite/client/fakes/FakeIgniteTables.java
+++ b/modules/client/src/test/java/org/apache/ignite/client/fakes/FakeIgniteTables.java
@@ -55,17 +55,17 @@ import org.jetbrains.annotations.Nullable;
 public class FakeIgniteTables implements IgniteTablesInternal {
     public static final String TABLE_EXISTS = "Table exists";
 
-    public static final String TABLE_ALL_COLUMNS = "all-columns";
+    public static final String TABLE_ALL_COLUMNS = "ALL_COLUMNS";
 
-    public static final String TABLE_ONE_COLUMN = "one-column";
+    public static final String TABLE_ONE_COLUMN = "ONE_COLUMN";
 
-    public static final String TABLE_WITH_DEFAULT_VALUES = "default-columns";
+    public static final String TABLE_WITH_DEFAULT_VALUES = "DEFAULT_COLUMNS";
 
-    public static final String TABLE_COMPOSITE_KEY = "composite-key";
+    public static final String TABLE_COMPOSITE_KEY = "COMPOSITE_KEY";
 
-    public static final String TABLE_COLOCATION_KEY = "colocation-key";
+    public static final String TABLE_COLOCATION_KEY = "COLOCATION_KEY";
 
-    public static final String BAD_TABLE = "bad-table";
+    public static final String BAD_TABLE = "BAD_TABLE";
 
     public static final String BAD_TABLE_ERR = "Err!";
 
diff --git a/modules/platforms/cpp/ignite/client/detail/table/tables_impl.cpp b/modules/platforms/cpp/ignite/client/detail/table/tables_impl.cpp
index 0eacd8d571..1b0e22c853 100644
--- a/modules/platforms/cpp/ignite/client/detail/table/tables_impl.cpp
+++ b/modules/platforms/cpp/ignite/client/detail/table/tables_impl.cpp
@@ -30,7 +30,8 @@ void tables_impl::get_table_async(std::string_view name, ignite_callback<std::op
             return std::nullopt;
 
         auto id = reader.read_int32();
-        auto table0 = std::make_shared<table_impl>(std::string(name), id, std::move(conn));
+        auto actualName = reader.read_string();
+        auto table0 = std::make_shared<table_impl>(std::move(actualName), id, std::move(conn));
 
         return std::make_optional(table(table0));
     };
diff --git a/modules/platforms/cpp/tests/client-test/tables_test.cpp b/modules/platforms/cpp/tests/client-test/tables_test.cpp
index 73cf73404d..d61c4537a9 100644
--- a/modules/platforms/cpp/tests/client-test/tables_test.cpp
+++ b/modules/platforms/cpp/tests/client-test/tables_test.cpp
@@ -45,7 +45,7 @@ TEST_F(tables_test, tables_get_table) {
 
     auto table = tables.get_table("tbl1");
     ASSERT_TRUE(table.has_value());
-    EXPECT_EQ(table->get_name(), "tbl1");
+    EXPECT_EQ(table->get_name(), "TBL1");
 }
 
 TEST_F(tables_test, tables_get_table_async_promises) {
@@ -70,7 +70,7 @@ TEST_F(tables_test, tables_get_table_async_promises) {
 
     auto table = tablePromise->get_future().get();
     ASSERT_TRUE(table.has_value());
-    EXPECT_EQ(table->get_name(), "tbl1");
+    EXPECT_EQ(table->get_name(), "TBL1");
 }
 
 TEST_F(tables_test, tables_get_table_async_callbacks) {
@@ -113,7 +113,7 @@ TEST_F(tables_test, tables_get_table_async_callbacks) {
                 operation2->set_exception(std::make_exception_ptr(ignite_error("Table should not be null")));
                 return;
             }
-            if (table->get_name() != "tbl1") {
+            if (table->get_name() != "TBL1") {
                 operation2->set_exception(
                     std::make_exception_ptr(ignite_error("Table has unexpected name: " + table->get_name())));
                 return;
diff --git a/modules/platforms/dotnet/Apache.Ignite.Tests/FakeServer.cs b/modules/platforms/dotnet/Apache.Ignite.Tests/FakeServer.cs
index 62c9e9073f..b0d60514c7 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Tests/FakeServer.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Tests/FakeServer.cs
@@ -241,6 +241,7 @@ namespace Apache.Ignite.Tests
                         {
                             using var arrayBufferWriter = new PooledArrayBuffer();
                             arrayBufferWriter.MessageWriter.Write(tableId);
+                            arrayBufferWriter.MessageWriter.Write(tableName);
 
                             Send(handler, requestId, arrayBufferWriter);
 
diff --git a/modules/platforms/dotnet/Apache.Ignite.Tests/Table/TablesTests.cs b/modules/platforms/dotnet/Apache.Ignite.Tests/Table/TablesTests.cs
index fea189312b..49a04ab7ec 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Tests/Table/TablesTests.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Tests/Table/TablesTests.cs
@@ -47,6 +47,15 @@ namespace Apache.Ignite.Tests.Table
             Assert.AreEqual(TableName, table!.Name);
         }
 
+        [Test]
+        public async Task TestGetTableReturnsActualName()
+        {
+            var table = await Client.Tables.GetTableAsync("tBl1");
+
+            Assert.IsNotNull(table);
+            Assert.AreEqual("TBL1", table!.Name);
+        }
+
         [Test]
         public async Task TestGetExistingTableReturnsSameInstanceEveryTime()
         {
diff --git a/modules/platforms/dotnet/Apache.Ignite/Internal/Table/Tables.cs b/modules/platforms/dotnet/Apache.Ignite/Internal/Table/Tables.cs
index e6b8340191..afa729aab7 100644
--- a/modules/platforms/dotnet/Apache.Ignite/Internal/Table/Tables.cs
+++ b/modules/platforms/dotnet/Apache.Ignite/Internal/Table/Tables.cs
@@ -109,13 +109,22 @@ namespace Apache.Ignite.Internal.Table
             return Read(resBuf.GetReader());
 
             // ReSharper disable once LambdaExpressionMustBeStatic (requires .NET 5+)
-            Table? Read(MsgPackReader r) =>
-                r.TryReadNil()
-                    ? null
-                    : _cachedTables.GetOrAdd(
-                        r.ReadInt32(),
-                        (int id, (string Name, Tables Tables) arg) => new Table(arg.Name, id, arg.Tables._socket, arg.Tables._sql),
-                        (name, this));
+            Table? Read(MsgPackReader r)
+            {
+                if (r.TryReadNil())
+                {
+                    return null;
+                }
+
+                var tableId = r.ReadInt32();
+                var actualName = r.ReadString();
+
+                return _cachedTables.GetOrAdd(
+                    tableId,
+                    static (int id, (string ActualName, Tables Tables) arg) =>
+                        new Table(arg.ActualName, id, arg.Tables._socket, arg.Tables._sql),
+                    (actualName, this));
+            }
         }
     }
 }
diff --git a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/client/ItThinClientConnectionTest.java b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/client/ItThinClientConnectionTest.java
index be83feefc3..c943baca22 100644
--- a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/client/ItThinClientConnectionTest.java
+++ b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/client/ItThinClientConnectionTest.java
@@ -125,4 +125,21 @@ public class ItThinClientConnectionTest extends ItAbstractThinClientTest {
         assertEquals("To see the full stack trace set clientConnector.sendServerExceptionStackTraceToClient:true",
                 ex.getCause().getCause().getCause().getCause().getMessage());
     }
+
+    @Test
+    void testServerReturnsActualTableName() {
+        // Quoting is not necessary.
+        Table table = client().tables().table("tbl1");
+        assertEquals("TBL1", table.name());
+
+        // Quoting is necessary.
+        client().sql().execute(null, "CREATE TABLE IF NOT EXISTS \"tbl-2\" (key INTEGER PRIMARY KEY)");
+
+        try {
+            Table table2 = client().tables().table("\"tbl-2\"");
+            assertEquals("\"tbl-2\"", table2.name());
+        } finally {
+            client().sql().execute(null, "DROP TABLE \"tbl-2\"");
+        }
+    }
 }