|
80 | 80 | import org.opensearch.sql.ast.tree.Trendline; |
81 | 81 | import org.opensearch.sql.ast.tree.UnresolvedPlan; |
82 | 82 | import org.opensearch.sql.ast.tree.Values; |
| 83 | +import org.opensearch.sql.calcite.plan.OpenSearchConstants; |
83 | 84 |
|
84 | 85 | /** Class of static methods to create specific node instances. */ |
85 | 86 | @UtilityClass |
@@ -491,15 +492,19 @@ public static Span spanFromSpanLengthLiteral( |
491 | 492 | UnresolvedExpression field, Literal spanLengthLiteral) { |
492 | 493 | if (spanLengthLiteral.getType() == DataType.STRING) { |
493 | 494 | String spanText = spanLengthLiteral.getValue().toString(); |
494 | | - String valueStr = spanText.replaceAll("[^0-9]", ""); |
495 | | - String unitStr = spanText.replaceAll("[0-9]", ""); |
| 495 | + String valueStr = spanText.replaceAll("[^0-9-]", ""); |
| 496 | + String unitStr = spanText.replaceAll("[0-9-]", ""); |
496 | 497 |
|
497 | 498 | if (valueStr.isEmpty()) { |
498 | 499 | // No numeric value found, use the literal as-is |
499 | 500 | return new Span(field, spanLengthLiteral, SpanUnit.NONE); |
500 | 501 | } else { |
501 | 502 | // Parse numeric value and unit |
502 | 503 | Integer value = Integer.parseInt(valueStr); |
| 504 | + if (value <= 0) { |
| 505 | + throw new IllegalArgumentException( |
| 506 | + String.format("Zero or negative time interval not supported: %s", spanText)); |
| 507 | + } |
503 | 508 | SpanUnit unit = unitStr.isEmpty() ? SpanUnit.NONE : SpanUnit.of(unitStr); |
504 | 509 | return span(field, intLiteral(value), unit); |
505 | 510 | } |
@@ -713,4 +718,9 @@ public static Bin bin(UnresolvedExpression field, Argument... arguments) { |
713 | 718 | return DefaultBin.builder().field(field).alias(alias).build(); |
714 | 719 | } |
715 | 720 | } |
| 721 | + |
| 722 | + /** Get a reference to the implicit timestamp field {@code @timestamp} */ |
| 723 | + public static Field referImplicitTimestampField() { |
| 724 | + return AstDSL.field(OpenSearchConstants.IMPLICIT_FIELD_TIMESTAMP); |
| 725 | + } |
716 | 726 | } |
0 commit comments