-
Notifications
You must be signed in to change notification settings - Fork 515
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fix][headless] Solve the problem of SQL execution error when alias i…
…s Chinese (#2039)
- Loading branch information
1 parent
eef7b3c
commit a8157ee
Showing
4 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
.../java/com/tencent/supersonic/common/jsqlparser/FieldAliasReplaceWithBackticksVisitor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.tencent.supersonic.common.jsqlparser; | ||
|
||
import net.sf.jsqlparser.expression.Alias; | ||
import net.sf.jsqlparser.statement.select.SelectItem; | ||
import net.sf.jsqlparser.statement.select.SelectItemVisitorAdapter; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
public class FieldAliasReplaceWithBackticksVisitor extends SelectItemVisitorAdapter { | ||
|
||
@Override | ||
public void visit(SelectItem selectExpressionItem) { | ||
Alias alias = selectExpressionItem.getAlias(); | ||
if (alias == null) { | ||
return; | ||
} | ||
String aliasName = alias.getName(); | ||
String replaceValue = addBackticks(aliasName); | ||
if (StringUtils.isBlank(replaceValue)) { | ||
return; | ||
} | ||
alias.setName(replaceValue); | ||
} | ||
|
||
private String addBackticks(String aliasName) { | ||
if (StringUtils.isBlank(aliasName)) { | ||
return ""; | ||
} | ||
if (aliasName.startsWith("`") && aliasName.endsWith("`")) { | ||
return ""; | ||
} | ||
return "`" + aliasName + "`"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters