@@ -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
0 commit comments