From 84ecd011fe5f9510783d9d1c6c9afe9cbb75ab5e Mon Sep 17 00:00:00 2001 From: 924060929 Date: Mon, 24 Mar 2025 13:35:31 +0800 Subject: [PATCH 1/2] add ut --- .../org/apache/doris/qe/SqlCacheTest.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 fe/fe-core/src/test/java/org/apache/doris/qe/SqlCacheTest.java 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 00000000000000..6e7c248b6317d6 --- /dev/null +++ b/fe/fe-core/src/test/java/org/apache/doris/qe/SqlCacheTest.java @@ -0,0 +1,43 @@ +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); + } +} From 1ecf9f040c0423b402e3a6abf17a974015158492 Mon Sep 17 00:00:00 2001 From: 924060929 Date: Tue, 25 Mar 2025 11:12:29 +0800 Subject: [PATCH 2/2] add ut --- .../java/org/apache/doris/qe/SqlCacheTest.java | 17 +++++++++++++++++ 1 file changed, 17 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 index 6e7c248b6317d6..afe95a49bde6c2 100644 --- 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 @@ -1,3 +1,20 @@ +// 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;