|
76 | 76 | import org.opensearch.sql.ast.tree.Relation; |
77 | 77 | import org.opensearch.sql.ast.tree.Rename; |
78 | 78 | import org.opensearch.sql.ast.tree.Reverse; |
| 79 | +import org.opensearch.sql.ast.tree.Rex; |
79 | 80 | import org.opensearch.sql.ast.tree.Sort; |
80 | 81 | import org.opensearch.sql.ast.tree.SpanBin; |
81 | 82 | import org.opensearch.sql.ast.tree.SubqueryAlias; |
@@ -419,6 +420,32 @@ public String visitReverse(Reverse node, String context) { |
419 | 420 | return StringUtils.format("%s | reverse", child); |
420 | 421 | } |
421 | 422 |
|
| 423 | + @Override |
| 424 | + public String visitRex(Rex node, String context) { |
| 425 | + String child = node.getChild().get(0).accept(this, context); |
| 426 | + String field = visitExpression(node.getField()); |
| 427 | + String pattern = "\"" + node.getPattern().toString() + "\""; |
| 428 | + StringBuilder command = new StringBuilder(); |
| 429 | + |
| 430 | + // Build the base command |
| 431 | + if (node.getMode() == Rex.RexMode.SED) { |
| 432 | + command.append(String.format("%s | rex field=%s mode=sed %s", child, field, pattern)); |
| 433 | + } else { |
| 434 | + command.append(String.format("%s | rex field=%s %s", child, field, pattern)); |
| 435 | + } |
| 436 | + |
| 437 | + // Add optional parameters |
| 438 | + if (node.getMaxMatch().isPresent()) { |
| 439 | + command.append(" max_match=").append(node.getMaxMatch().get()); |
| 440 | + } |
| 441 | + |
| 442 | + if (node.getOffsetField().isPresent()) { |
| 443 | + command.append(" offset_field=").append(node.getOffsetField().get()); |
| 444 | + } |
| 445 | + |
| 446 | + return command.toString(); |
| 447 | + } |
| 448 | + |
422 | 449 | @Override |
423 | 450 | public String visitParse(Parse node, String context) { |
424 | 451 | String child = node.getChild().get(0).accept(this, context); |
@@ -734,5 +761,11 @@ public String visitCast(Cast node, String context) { |
734 | 761 | String expr = analyze(node.getExpression(), context); |
735 | 762 | return StringUtils.format("cast(%s as %s)", expr, node.getConvertedType().toString()); |
736 | 763 | } |
| 764 | + |
| 765 | + @Override |
| 766 | + public String visitQualifiedName( |
| 767 | + org.opensearch.sql.ast.expression.QualifiedName node, String context) { |
| 768 | + return String.join(".", node.getParts()); |
| 769 | + } |
737 | 770 | } |
738 | 771 | } |
0 commit comments