Skip to content

Commit 899ae7b

Browse files
committed
deal where is not null
1 parent dbfe5ee commit 899ae7b

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

core/src/main/java/com/dtstack/flink/sql/side/SidePredicatesParser.java

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -120,22 +120,35 @@ private void extractPredicateInfo(SqlNode whereNode, List<PredicateInfo> predica
120120
SqlOperator operator = ((SqlBasicCall) whereNode).getOperator();
121121
String operatorName = operator.getName();
122122
SqlKind operatorKind = operator.getKind();
123-
// 跳过函数
124-
if ((((SqlBasicCall) whereNode).getOperands()[0] instanceof SqlIdentifier)) {
125-
SqlIdentifier fieldFullPath = (SqlIdentifier) ((SqlBasicCall) whereNode).getOperands()[0];
126-
if (fieldFullPath.names.size() == 2) {
127-
String ownerTable = fieldFullPath.names.get(0);
128-
String fieldName = fieldFullPath.names.get(1);
129-
String content = (operatorKind == SqlKind.BETWEEN) ? ((SqlBasicCall) whereNode).getOperands()[1].toString() + " AND " +
130-
((SqlBasicCall) whereNode).getOperands()[2].toString() : ((SqlBasicCall) whereNode).getOperands()[1].toString();
131123

132-
PredicateInfo predicateInfo = PredicateInfo.builder().setOperatorName(operatorName).setOperatorKind(operatorKind.toString())
133-
.setOwnerTable(ownerTable).setFieldName(fieldName).setCondition(content).build();
124+
if (operatorKind == SqlKind.IS_NOT_NULL || operatorKind == SqlKind.IS_NULL) {
125+
fillPredicateInfoToList((SqlBasicCall) whereNode, predicatesInfoList, operatorName, operatorKind, 0, 0);
126+
return;
127+
}
134128

135-
predicatesInfoList.add(predicateInfo);
136-
}
129+
// 跳过函数
130+
if ((((SqlBasicCall) whereNode).getOperands()[0] instanceof SqlIdentifier)
131+
&& (((SqlBasicCall) whereNode).getOperands()[1].getKind() != SqlKind.OTHER_FUNCTION)) {
132+
fillPredicateInfoToList((SqlBasicCall) whereNode, predicatesInfoList, operatorName, operatorKind, 0, 1);
133+
} else if ((((SqlBasicCall) whereNode).getOperands()[1] instanceof SqlIdentifier)
134+
&& (((SqlBasicCall) whereNode).getOperands()[0].getKind() != SqlKind.OTHER_FUNCTION)) {
135+
fillPredicateInfoToList((SqlBasicCall) whereNode, predicatesInfoList, operatorName, operatorKind, 1, 0);
137136
}
137+
}
138+
}
139+
140+
private void fillPredicateInfoToList(SqlBasicCall whereNode, List<PredicateInfo> predicatesInfoList, String operatorName, SqlKind operatorKind,
141+
int fieldIndex, int conditionIndex) {
142+
SqlIdentifier fieldFullPath = (SqlIdentifier) whereNode.getOperands()[fieldIndex];
143+
if (fieldFullPath.names.size() == 2) {
144+
String ownerTable = fieldFullPath.names.get(0);
145+
String fieldName = fieldFullPath.names.get(1);
146+
String content = (operatorKind == SqlKind.BETWEEN) ? whereNode.getOperands()[conditionIndex].toString() + " AND " +
147+
whereNode.getOperands()[2].toString() : whereNode.getOperands()[conditionIndex].toString();
138148

149+
PredicateInfo predicateInfo = PredicateInfo.builder().setOperatorName(operatorName).setOperatorKind(operatorKind.toString())
150+
.setOwnerTable(ownerTable).setFieldName(fieldName).setCondition(content).build();
151+
predicatesInfoList.add(predicateInfo);
139152
}
140153
}
141154

rdb/rdb-side/src/main/java/com/dtstack/flink/sql/side/rdb/async/RdbAsyncSideInfo.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ public String buildFilterCondition(PredicateInfo info) {
150150
return quoteIdentifier(info.getFieldName()) + " != " + info.getCondition();
151151
case "BETWEEN":
152152
return quoteIdentifier(info.getFieldName()) + " BETWEEN " + info.getCondition();
153+
case "IS_NOT_NULL":
154+
case "IS_NULL":
155+
return quoteIdentifier(info.getFieldName()) + " " + info.getOperatorName();
153156
default:
154157
return quoteIdentifier(info.getFieldName()) + " " + info.getOperatorName() + " " + info.getCondition();
155158
}

0 commit comments

Comments
 (0)