Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement]Add session variable enable_compare_for_null to support compare null … #51201

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

even986025158
Copy link
Contributor

@even986025158 even986025158 commented Sep 20, 2024

…when use =
need use = to compare null = null and want to it return true

Why I'm doing:

Some services migrated from other systems want to use = for null comparison, but do not want to modify the SQL

What I'm doing:

add the session variable enable_compare_for_null to support compare null with =
Fixes #issue

What type of PR is this:

  • BugFix
  • Feature
  • Enhancement
  • Refactor
  • UT
  • Doc
  • Tool

Does this PR entail a change in behavior?

  • Yes, this PR will result in a change in behavior.
  • No, this PR will not result in a change in behavior.

If yes, please specify the type of change:

  • Interface/UI changes: syntax, type conversion, expression evaluation, display information
  • Parameter changes: default values, similar parameters but with different default values
  • Policy changes: use new policy to replace old one, functionality automatically enabled
  • Feature removed
  • Miscellaneous: upgrade & downgrade compatibility, etc.

Checklist:

  • I have added test cases for my bug fix or my new feature
  • This pr needs user documentation (for new or modified features or behaviors)
  • I have added documentation for my new feature or new function
  • This is a backport pr

Bugfix cherry-pick branch check:

  • I have checked the version labels which the pr will be auto-backported to the target branch
    • 3.3
    • 3.2
    • 3.1
    • 3.0
    • 2.5

public void setEnableCompareForNull(boolean enableCompareForNull) {
this.enableCompareForNull = enableCompareForNull;
}

public long getSqlMode() {
return sqlMode;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The most risky bug in this code is:
Serialization inconsistency due to missing enableCompareForNull field.

You can modify the code like this:

    @@ -173,6 +173,7 @@ public class SessionVariable implements Serializable, Writable, Cloneable {
     public static final String QUERY_CACHE_TYPE = "query_cache_type";
     public static final String INTERACTIVE_TIMEOUT = "interactive_timeout";
     public static final String WAIT_TIMEOUT = "wait_timeout";
+    public static final String ENABLE_COMPARE_FOR_NULL = "enable_compare_for_null";
 
     public static final String CATALOG = "catalog";
     public static final String NET_WRITE_TIMEOUT = "net_write_timeout";
@@ -1005,6 +1006,9 @@ public static MaterializedViewRewriteMode parse(String str) {
     @VariableMgr.VarAttr(name = WAIT_TIMEOUT)
     private int waitTimeout = 28800;
 
+    @VariableMgr.VarAttr(name = ENABLE_COMPARE_FOR_NULL)
+    private boolean enableCompareForNull = false;
+
     // The number of seconds to wait for a block to be written to a connection before aborting the write
     @VariableMgr.VarAttr(name = NET_WRITE_TIMEOUT)
     private int netWriteTimeout = 60;
@@ -2610,6 +2614,14 @@ public int getWaitTimeoutS() {
         return waitTimeout;
     }
 
+    public boolean isEnableCompareForNull() {
+        return enableCompareForNull;
+    }
+
+    public void setEnableCompareForNull(boolean enableCompareForNull) {
+        this.enableCompareForNull = enableCompareForNull;
+    }
+
     public long getSqlMode() {
         return sqlMode;
     }

+    /**
+     * Ensure that enableCompareForNull is serialized correctly.
+     */
+    private void writeObject(ObjectOutputStream out) throws IOException {
+        out.defaultWriteObject();
+        out.writeBoolean(enableCompareForNull);
+    }
+
+    /**
+     * Ensure that enableCompareForNull is deserialized correctly.
+     */
+    private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
+        in.defaultReadObject();
+        enableCompareForNull = in.readBoolean();
+    }

Copy link

sonarcloud bot commented Sep 20, 2024

@even986025158 even986025158 changed the title Add session variable enable_compare_for_null to support compare null … [Enhancement]Add session variable enable_compare_for_null to support compare null … Sep 20, 2024
Copy link

[Java-Extensions Incremental Coverage Report]

pass : 0 / 0 (0%)

Copy link

[FE Incremental Coverage Report]

fail : 2 / 4 (50.00%)

file detail

path covered_line new_line coverage not_covered_line_detail
🔵 com/starrocks/qe/SessionVariable.java 2 4 50.00% [2622, 2623]

Copy link

[BE Incremental Coverage Report]

pass : 0 / 0 (0%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant