|
71 | 71 | import org.opensearch.sql.ast.tree.Relation; |
72 | 72 | import org.opensearch.sql.ast.tree.Rename; |
73 | 73 | import org.opensearch.sql.ast.tree.Reverse; |
| 74 | +import org.opensearch.sql.ast.tree.Rex; |
74 | 75 | import org.opensearch.sql.ast.tree.Sort; |
75 | 76 | import org.opensearch.sql.ast.tree.SubqueryAlias; |
76 | 77 | import org.opensearch.sql.ast.tree.TableFunction; |
@@ -363,6 +364,32 @@ public String visitReverse(Reverse node, String context) { |
363 | 364 | return StringUtils.format("%s | reverse", child); |
364 | 365 | } |
365 | 366 |
|
| 367 | + @Override |
| 368 | + public String visitRex(Rex node, String context) { |
| 369 | + String child = node.getChild().get(0).accept(this, context); |
| 370 | + String field = visitExpression(node.getField()); |
| 371 | + String pattern = "\"" + node.getPattern().toString() + "\""; |
| 372 | + StringBuilder command = new StringBuilder(); |
| 373 | + |
| 374 | + // Build the base command |
| 375 | + if (node.getMode() == Rex.RexMode.SED) { |
| 376 | + command.append(String.format("%s | rex field=%s mode=sed %s", child, field, pattern)); |
| 377 | + } else { |
| 378 | + command.append(String.format("%s | rex field=%s %s", child, field, pattern)); |
| 379 | + } |
| 380 | + |
| 381 | + // Add optional parameters |
| 382 | + if (node.getMaxMatch().isPresent()) { |
| 383 | + command.append(" max_match=").append(node.getMaxMatch().get()); |
| 384 | + } |
| 385 | + |
| 386 | + if (node.getOffsetField().isPresent()) { |
| 387 | + command.append(" offset_field=").append(node.getOffsetField().get()); |
| 388 | + } |
| 389 | + |
| 390 | + return command.toString(); |
| 391 | + } |
| 392 | + |
366 | 393 | @Override |
367 | 394 | public String visitParse(Parse node, String context) { |
368 | 395 | String child = node.getChild().get(0).accept(this, context); |
@@ -678,5 +705,11 @@ public String visitCast(Cast node, String context) { |
678 | 705 | String expr = analyze(node.getExpression(), context); |
679 | 706 | return StringUtils.format("cast(%s as %s)", expr, node.getConvertedType().toString()); |
680 | 707 | } |
| 708 | + |
| 709 | + @Override |
| 710 | + public String visitQualifiedName( |
| 711 | + org.opensearch.sql.ast.expression.QualifiedName node, String context) { |
| 712 | + return String.join(".", node.getParts()); |
| 713 | + } |
681 | 714 | } |
682 | 715 | } |
0 commit comments