From ff6e492946b7df165cc8193da2cec42faac65609 Mon Sep 17 00:00:00 2001 From: liugddx Date: Thu, 15 Feb 2024 12:53:26 +0800 Subject: [PATCH] 1 --- .../apache/doris/qe/SessionVariableField.java | 23 +++++++++++++++++-- .../apache/doris/qe/SessionVariablesTest.java | 12 ++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariableField.java b/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariableField.java index dc88020fbb07dc..55d2d69b4fc930 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariableField.java +++ b/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariableField.java @@ -22,6 +22,7 @@ import java.io.ObjectOutputStream; import java.io.Serializable; import java.lang.reflect.Field; +import java.util.Objects; public class SessionVariableField implements Serializable { private transient Field field; @@ -53,9 +54,9 @@ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundE private Field getField(String fieldName, Class fieldType) throws NoSuchFieldException { try { - return SessionVariableField.class.getDeclaredField(fieldName); + return SessionVariable.class.getDeclaredField(fieldName); } catch (NoSuchFieldException e) { - Class superclass = SessionVariableField.class.getSuperclass(); + Class superclass = SessionVariable.class.getSuperclass(); if (superclass != null) { return getField(fieldName, fieldType); } @@ -63,4 +64,22 @@ private Field getField(String fieldName, Class fieldType) throws NoSuchFieldE } } + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null || getClass() != obj.getClass()) { + return false; + } + SessionVariableField other = (SessionVariableField) obj; + // 忽略 transient 字段的比较 + return Objects.equals(this.getField(), other.getField()); + } + + @Override + public int hashCode() { + return Objects.hashCode(this.getField()); + } + } diff --git a/fe/fe-core/src/test/java/org/apache/doris/qe/SessionVariablesTest.java b/fe/fe-core/src/test/java/org/apache/doris/qe/SessionVariablesTest.java index 273c89d80eedde..bad7842e01e6d6 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/qe/SessionVariablesTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/qe/SessionVariablesTest.java @@ -156,4 +156,16 @@ public void testForwardQueryOptions() { Assertions.assertEquals(123, sessionVariable.getQueryTimeoutS()); Assertions.assertEquals(123, sessionVariable.getInsertTimeoutS()); } + + @Test + public void testCloneSessionVariablesWithSessionOriginValueNotEmpty() throws NoSuchFieldException { + Field txIsolation = SessionVariable.class.getField("txIsolation"); + SessionVariableField txIsolationSessionVariableField = new SessionVariableField(txIsolation); + sessionVariable.addSessionOriginValue(txIsolationSessionVariableField, "test"); + + SessionVariable sessionVariableClone = VariableMgr.cloneSessionVariable(sessionVariable); + + Assertions.assertEquals("test", + sessionVariableClone.getSessionOriginValue().get(txIsolationSessionVariableField)); + } }