|
118 | 118 | import org.opensearch.sql.common.utils.StringUtils; |
119 | 119 | import org.opensearch.sql.exception.CalciteUnsupportedException; |
120 | 120 | import org.opensearch.sql.exception.SemanticCheckException; |
121 | | -import org.opensearch.sql.expression.parse.RegexExpression; |
122 | 121 | import org.opensearch.sql.expression.function.BuiltinFunctionName; |
123 | 122 | import org.opensearch.sql.expression.function.PPLFuncImpTable; |
| 123 | +import org.opensearch.sql.expression.parse.RegexExpression; |
124 | 124 | import org.opensearch.sql.utils.ParseUtils; |
125 | 125 |
|
126 | 126 | public class CalciteRelNodeVisitor extends AbstractNodeVisitor<RelNode, CalcitePlanContext> { |
@@ -180,34 +180,37 @@ public RelNode visitRex(Rex node, CalcitePlanContext context) { |
180 | 180 | RexNode fieldRex = rexVisitor.analyze(node.getField(), context); |
181 | 181 | String patternStr = (String) node.getPattern().getValue(); |
182 | 182 | List<String> namedGroups = RegexExpression.getNamedGroupCandidates(patternStr); |
183 | | - |
| 183 | + |
184 | 184 | if (namedGroups.isEmpty()) { |
185 | | - throw new IllegalArgumentException("Rex pattern must contain at least one named capture group"); |
| 185 | + throw new IllegalArgumentException( |
| 186 | + "Rex pattern must contain at least one named capture group"); |
186 | 187 | } |
187 | 188 |
|
188 | 189 | // Filter matching rows on data nodes using script pushdown |
189 | | - RexNode regexMatchCondition = context.rexBuilder.makeCall( |
190 | | - org.apache.calcite.sql.fun.SqlLibraryOperators.REGEXP_CONTAINS, |
191 | | - fieldRex, |
192 | | - context.rexBuilder.makeLiteral(patternStr) |
193 | | - ); |
| 190 | + RexNode regexMatchCondition = |
| 191 | + context.rexBuilder.makeCall( |
| 192 | + org.apache.calcite.sql.fun.SqlLibraryOperators.REGEXP_CONTAINS, |
| 193 | + fieldRex, |
| 194 | + context.rexBuilder.makeLiteral(patternStr)); |
194 | 195 | context.relBuilder.filter(regexMatchCondition); |
195 | 196 |
|
196 | 197 | // Extract fields from filtered data |
197 | 198 | List<RexNode> newFields = new ArrayList<>(); |
198 | 199 | for (int i = 0; i < namedGroups.size(); i++) { |
199 | | - RexNode extractCall = PPLFuncImpTable.INSTANCE.resolve( |
200 | | - context.rexBuilder, |
201 | | - BuiltinFunctionName.REX_EXTRACT, |
202 | | - fieldRex, |
203 | | - context.rexBuilder.makeLiteral(patternStr), |
204 | | - context.relBuilder.literal(i + 1)); |
| 200 | + RexNode extractCall = |
| 201 | + PPLFuncImpTable.INSTANCE.resolve( |
| 202 | + context.rexBuilder, |
| 203 | + BuiltinFunctionName.REX_EXTRACT, |
| 204 | + fieldRex, |
| 205 | + context.rexBuilder.makeLiteral(patternStr), |
| 206 | + context.relBuilder.literal(i + 1)); |
205 | 207 | newFields.add(extractCall); |
206 | 208 | } |
207 | 209 |
|
208 | 210 | projectPlusOverriding(newFields, namedGroups, context); |
209 | 211 | return context.relBuilder.peek(); |
210 | 212 | } |
| 213 | + |
211 | 214 | private boolean containsSubqueryExpression(Node expr) { |
212 | 215 | if (expr == null) { |
213 | 216 | return false; |
|
0 commit comments