-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Ignore empty text node when parsing XML nodes #3349
Conversation
@harawata Any concerns here? Its using trim so it handles all whitespace type which would probably be more appropriate title here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @nieqiurong ,
This seems like a good optimization without affecting the final SQL.
Nice work!
thanks |
I think I missed compatibility considerations. If the label does not wrap, the statements will be connected together. <!--parse: and id is not null and name is not null-->
<where>
<if test="1==1">
and id is not null
</if>
<if test="1==1">
and name is not null
</if>
</where>
<!-- parse: and id is not nulland name is not null-->
<where>
<if test="1==1">and id is not null</if>
<if test="1==1">and name is not null</if>
</where> It may be better to change it to the following, so that there is no need to cooperate with Configuration#isShrinkWhitespacesInSql to remove line breaks String data = child.getStringBody("").trim();
if (data.isEmpty()) {
continue;
}
data += " "; |
@nieqiurong The suggestion you posted would introduce extra spaces where it would not have normally been before this PR. In this case I think it is better to revert this. wdyt @harawata? |
I agree with your suggestion, but can we add a configuration to decide whether to enable this operation, or provide an interface to support processing? |
Yeah, adding extra space does not look great. It's interesting that it only happens when where 1=1
<if test="1==1">and id is not null</if>
<if test="1==1">and name is not null</if> We might be able to workaround this in a different place. In any case, if this PR changes the final SQL, it would be better to revert it and release 3.5.19. |
I agree, but can you consider removing \n? For example, some parser frameworks will have problems with continuous line breaks. |
Can't you use Find out why it only happens when |
Thank you, I will look into it. You can roll back the code first to ensure compatibility. |
Regression when where node is used without new lines
When parsing XML, since nested nodes have line breaks by default, these nodes should not be parsed as text nodes and added, which will cause unnecessary heap space to be occupied.
The test project reduces the creation of this node, and the space occupied by this node is reduced from 1625KB to 748KB