|
12 | 12 | import static org.opensearch.sql.ast.tree.Sort.SortOrder.ASC;
|
13 | 13 | import static org.opensearch.sql.ast.tree.Sort.SortOrder.DESC;
|
14 | 14 |
|
| 15 | +import com.google.common.base.Strings; |
15 | 16 | import com.google.common.collect.ImmutableList;
|
16 | 17 | import com.google.common.collect.Iterables;
|
17 | 18 | import java.util.ArrayList;
|
|
31 | 32 | import org.apache.calcite.rex.RexLiteral;
|
32 | 33 | import org.apache.calcite.rex.RexNode;
|
33 | 34 | import org.apache.calcite.rex.RexWindowBounds;
|
34 |
| -import org.apache.calcite.sql.fun.SqlLibraryOperators; |
35 | 35 | import org.apache.calcite.sql.fun.SqlStdOperatorTable;
|
| 36 | +import org.apache.calcite.sql.type.SqlTypeName; |
36 | 37 | import org.apache.calcite.tools.RelBuilder;
|
37 | 38 | import org.apache.calcite.tools.RelBuilder.AggCall;
|
38 | 39 | import org.apache.calcite.util.Holder;
|
|
78 | 79 | import org.opensearch.sql.calcite.utils.JoinAndLookupUtils;
|
79 | 80 | import org.opensearch.sql.exception.CalciteUnsupportedException;
|
80 | 81 | import org.opensearch.sql.exception.SemanticCheckException;
|
| 82 | +import org.opensearch.sql.expression.function.PPLFuncImpTable; |
81 | 83 | import org.opensearch.sql.utils.ParseUtils;
|
82 | 84 |
|
83 | 85 | public class CalciteRelNodeVisitor extends AbstractNodeVisitor<RelNode, CalcitePlanContext> {
|
@@ -283,21 +285,28 @@ public RelNode visitHead(Head node, CalcitePlanContext context) {
|
283 | 285 | @Override
|
284 | 286 | public RelNode visitParse(Parse node, CalcitePlanContext context) {
|
285 | 287 | visitChildren(node, context);
|
286 |
| - List<String> originalFieldNames = context.relBuilder.peek().getRowType().getFieldNames(); |
287 | 288 | RexNode sourceField = rexVisitor.analyze(node.getSourceField(), context);
|
288 | 289 | ParseMethod parseMethod = node.getParseMethod();
|
289 | 290 | java.util.Map<String, Literal> arguments = node.getArguments();
|
290 |
| - String pattern = (String) node.getPattern().getValue(); |
| 291 | + String patternValue = (String) node.getPattern().getValue(); |
| 292 | + String pattern = |
| 293 | + ParseMethod.PATTERNS.equals(parseMethod) && Strings.isNullOrEmpty(patternValue) |
| 294 | + ? "[a-zA-Z0-9]" |
| 295 | + : patternValue; |
291 | 296 | List<String> groupCandidates =
|
292 | 297 | ParseUtils.getNamedGroupCandidates(parseMethod, pattern, arguments);
|
293 | 298 | List<RexNode> newFields =
|
294 | 299 | groupCandidates.stream()
|
295 | 300 | .map(
|
296 | 301 | group ->
|
297 |
| - context.rexBuilder.makeCall( |
298 |
| - SqlLibraryOperators.REGEXP_EXTRACT, |
| 302 | + PPLFuncImpTable.INSTANCE.resolve( |
| 303 | + context.rexBuilder, |
| 304 | + ParseUtils.BUILTIN_FUNCTION_MAP.get(parseMethod), |
299 | 305 | sourceField,
|
300 |
| - context.rexBuilder.makeLiteral(pattern))) |
| 306 | + context.rexBuilder.makeLiteral( |
| 307 | + pattern, |
| 308 | + context.rexBuilder.getTypeFactory().createSqlType(SqlTypeName.VARCHAR), |
| 309 | + true))) |
301 | 310 | .toList();
|
302 | 311 | projectPlusOverriding(newFields, groupCandidates, context);
|
303 | 312 | return context.relBuilder.peek();
|
|
0 commit comments