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

huajianlan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 6099f0c5ed6 [chore](test) add ut for sql cache (#49389)
6099f0c5ed6 is described below

commit 6099f0c5ed61efc84ccdc2c90372ba93225b62e9
Author: 924060929 <lanhuaj...@selectdb.com>
AuthorDate: Wed Mar 26 21:22:03 2025 +0800

    [chore](test) add ut for sql cache (#49389)
    
    add test for #46099
---
 .../java/org/apache/doris/qe/SqlCacheTest.java     | 60 ++++++++++++++++++++++
 1 file changed, 60 insertions(+)

diff --git a/fe/fe-core/src/test/java/org/apache/doris/qe/SqlCacheTest.java 
b/fe/fe-core/src/test/java/org/apache/doris/qe/SqlCacheTest.java
new file mode 100644
index 00000000000..afe95a49bde
--- /dev/null
+++ b/fe/fe-core/src/test/java/org/apache/doris/qe/SqlCacheTest.java
@@ -0,0 +1,60 @@
+// 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.doris.qe;
+
+import org.apache.doris.analysis.UserIdentity;
+import org.apache.doris.nereids.SqlCacheContext;
+import org.apache.doris.proto.Types.PUniqueId;
+import org.apache.doris.thrift.TUniqueId;
+
+import com.google.common.collect.ImmutableSet;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.util.UUID;
+
+public class SqlCacheTest {
+    @Test
+    public void testCacheKey() {
+        TUniqueId queryId = new TUniqueId();
+        UUID uuid = UUID.randomUUID();
+        queryId.setHi(uuid.getMostSignificantBits());
+        queryId.setLo(uuid.getLeastSignificantBits());
+        UserIdentity admin = new UserIdentity("admin", "127.0.0.1");
+
+        SqlCacheContext cacheContext = new SqlCacheContext(admin, queryId);
+        cacheContext.setOriginSql("SELECT * FROM tbl");
+        PUniqueId key1 = cacheContext.doComputeCacheKeyMd5(ImmutableSet.of());
+
+        SqlCacheContext cacheContext2 = new SqlCacheContext(admin, queryId);
+        cacheContext2.setOriginSql(
+                "-- Same query with comments and extra spaces\n"
+                    + "/* Comment */  SELECT   *   FROM   tbl  "
+        );
+        PUniqueId key2 = cacheContext2.doComputeCacheKeyMd5(ImmutableSet.of());
+        Assertions.assertEquals(key1, key2);
+
+        SqlCacheContext cacheContext3 = new SqlCacheContext(admin, queryId);
+        cacheContext3.setOriginSql(
+                "-- Same query with comments and extra spaces\n"
+                        + "/* Comment */  SELeCT   *   FROM   tbl  "
+        );
+        PUniqueId key3 = cacheContext3.doComputeCacheKeyMd5(ImmutableSet.of());
+        Assertions.assertNotEquals(key1, key3);
+    }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to