-
Notifications
You must be signed in to change notification settings - Fork 406
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into support_limit
- Loading branch information
Showing
96 changed files
with
1,394 additions
and
1,101 deletions.
There are no files selected for viewing
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
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
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
83 changes: 83 additions & 0 deletions
83
common/src/main/java/com/tencent/supersonic/common/jsqlparser/CustomExpressionDeParser.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,83 @@ | ||
package com.tencent.supersonic.common.jsqlparser; | ||
|
||
import net.sf.jsqlparser.expression.Expression; | ||
import net.sf.jsqlparser.expression.operators.conditional.AndExpression; | ||
import net.sf.jsqlparser.expression.operators.conditional.OrExpression; | ||
import net.sf.jsqlparser.expression.operators.relational.IsNullExpression; | ||
import net.sf.jsqlparser.schema.Column; | ||
import net.sf.jsqlparser.util.deparser.ExpressionDeParser; | ||
|
||
import java.util.Set; | ||
|
||
public class CustomExpressionDeParser extends ExpressionDeParser { | ||
|
||
private Set<String> removeFieldNames; | ||
private boolean dealNull; | ||
private boolean dealNotNull; | ||
|
||
public CustomExpressionDeParser( | ||
Set<String> removeFieldNames, boolean dealNull, boolean dealNotNull) { | ||
this.removeFieldNames = removeFieldNames; | ||
this.dealNull = dealNull; | ||
this.dealNotNull = dealNotNull; | ||
} | ||
|
||
@Override | ||
public void visit(AndExpression andExpression) { | ||
processBinaryExpression(andExpression, " AND "); | ||
} | ||
|
||
@Override | ||
public void visit(OrExpression orExpression) { | ||
processBinaryExpression(orExpression, " OR "); | ||
} | ||
|
||
@Override | ||
public void visit(IsNullExpression isNullExpression) { | ||
if (shouldSkip(isNullExpression)) { | ||
// Skip this expression | ||
} else { | ||
super.visit(isNullExpression); | ||
} | ||
} | ||
|
||
private void processBinaryExpression(Expression binaryExpression, String operator) { | ||
Expression leftExpression = ((AndExpression) binaryExpression).getLeftExpression(); | ||
Expression rightExpression = ((AndExpression) binaryExpression).getRightExpression(); | ||
|
||
boolean leftIsNull = | ||
leftExpression instanceof IsNullExpression | ||
&& shouldSkip((IsNullExpression) leftExpression); | ||
boolean rightIsNull = | ||
rightExpression instanceof IsNullExpression | ||
&& shouldSkip((IsNullExpression) rightExpression); | ||
|
||
if (leftIsNull && rightIsNull) { | ||
// Skip both expressions | ||
} else if (leftIsNull) { | ||
rightExpression.accept(this); | ||
} else if (rightIsNull) { | ||
leftExpression.accept(this); | ||
} else { | ||
leftExpression.accept(this); | ||
buffer.append(operator); | ||
rightExpression.accept(this); | ||
} | ||
} | ||
|
||
private boolean shouldSkip(IsNullExpression isNullExpression) { | ||
if (isNullExpression.getLeftExpression() instanceof Column) { | ||
Column column = (Column) isNullExpression.getLeftExpression(); | ||
String columnName = column.getColumnName(); | ||
// Add your target column names here | ||
if (removeFieldNames.contains(columnName)) { | ||
if (isNullExpression.isNot() && dealNotNull) { | ||
return true; | ||
} else if (!isNullExpression.isNot() && dealNull) { | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
} |
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
Oops, something went wrong.