mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-12 04:27:39 +00:00
[improvement](chat) adapt checkstyle. (#410)
This commit is contained in:
@@ -27,8 +27,6 @@ import net.sf.jsqlparser.statement.select.SelectBody;
|
|||||||
import net.sf.jsqlparser.statement.select.SelectExpressionItem;
|
import net.sf.jsqlparser.statement.select.SelectExpressionItem;
|
||||||
import net.sf.jsqlparser.statement.select.SelectItem;
|
import net.sf.jsqlparser.statement.select.SelectItem;
|
||||||
import net.sf.jsqlparser.statement.select.SelectVisitorAdapter;
|
import net.sf.jsqlparser.statement.select.SelectVisitorAdapter;
|
||||||
import net.sf.jsqlparser.statement.select.SelectItem;
|
|
||||||
import net.sf.jsqlparser.statement.select.SelectExpressionItem;
|
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -64,6 +62,27 @@ public class SqlParserRemoveHelper {
|
|||||||
return selectStatement.toString();
|
return selectStatement.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String removeSelect(String sql, Set<String> fields) {
|
||||||
|
Select selectStatement = SqlParserSelectHelper.getSelect(sql);
|
||||||
|
if (selectStatement == null) {
|
||||||
|
return sql;
|
||||||
|
}
|
||||||
|
SelectBody selectBody = selectStatement.getSelectBody();
|
||||||
|
if (!(selectBody instanceof PlainSelect)) {
|
||||||
|
return sql;
|
||||||
|
}
|
||||||
|
List<SelectItem> selectItems = ((PlainSelect) selectBody).getSelectItems();
|
||||||
|
selectItems.removeIf(selectItem -> {
|
||||||
|
if (selectItem instanceof SelectExpressionItem) {
|
||||||
|
SelectExpressionItem selectExpressionItem = (SelectExpressionItem) selectItem;
|
||||||
|
String columnName = SqlParserSelectHelper.getColumnName(selectExpressionItem.getExpression());
|
||||||
|
return fields.contains(columnName);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
return selectStatement.toString();
|
||||||
|
}
|
||||||
|
|
||||||
public static String removeWhereCondition(String sql, Set<String> removeFieldNames) {
|
public static String removeWhereCondition(String sql, Set<String> removeFieldNames) {
|
||||||
Select selectStatement = SqlParserSelectHelper.getSelect(sql);
|
Select selectStatement = SqlParserSelectHelper.getSelect(sql);
|
||||||
SelectBody selectBody = selectStatement.getSelectBody();
|
SelectBody selectBody = selectStatement.getSelectBody();
|
||||||
@@ -226,28 +245,6 @@ public class SqlParserRemoveHelper {
|
|||||||
return selectStatement.toString();
|
return selectStatement.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static String removeSelect(String sql, Set<String> fields) {
|
|
||||||
Select selectStatement = SqlParserSelectHelper.getSelect(sql);
|
|
||||||
if (selectStatement == null) {
|
|
||||||
return sql;
|
|
||||||
}
|
|
||||||
SelectBody selectBody = selectStatement.getSelectBody();
|
|
||||||
if (!(selectBody instanceof PlainSelect)) {
|
|
||||||
return sql;
|
|
||||||
}
|
|
||||||
List<SelectItem> selectItems = ((PlainSelect) selectBody).getSelectItems();
|
|
||||||
selectItems.removeIf(selectItem -> {
|
|
||||||
if (selectItem instanceof SelectExpressionItem) {
|
|
||||||
SelectExpressionItem selectExpressionItem = (SelectExpressionItem) selectItem;
|
|
||||||
String columnName = SqlParserSelectHelper.getColumnName(selectExpressionItem.getExpression());
|
|
||||||
return fields.contains(columnName);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
return selectStatement.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String removeGroupBy(String sql, Set<String> fields) {
|
public static String removeGroupBy(String sql, Set<String> fields) {
|
||||||
Select selectStatement = SqlParserSelectHelper.getSelect(sql);
|
Select selectStatement = SqlParserSelectHelper.getSelect(sql);
|
||||||
if (selectStatement == null) {
|
if (selectStatement == null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user