Skip to content

Commit 2aa1768

Browse files
committed
Update doc
Signed-off-by: Kai Huang <[email protected]>
1 parent 92e4109 commit 2aa1768

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

core/src/main/java/org/opensearch/sql/calcite/utils/binning/handlers/CountBinHandler.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@ public RexNode createExpression(
2828
CountBin countBin = (CountBin) node;
2929

3030
// Create validated binnable field (validates that field is numeric or time-based)
31-
// Note: bins parameter on time-based fields requires pushdown to be enabled
31+
// Note: bins parameter works with both numeric and time-based fields
32+
// Note: bins parameter on time-based fields requires:
33+
// 1. Pushdown to be enabled (controlled by plugins.calcite.pushdown.enabled, enabled by
34+
// default)
35+
// 2. The time-based field to be used as an aggregation bucket
36+
// (e.g., stats count() by @timestamp)
3237
String fieldName = BinFieldValidator.extractFieldName(node);
3338
BinnableField field = new BinnableField(fieldExpr, fieldExpr.getType(), fieldName);
3439

docs/user/ppl/cmd/bin.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,10 @@ Automatically calculates the span using a mathematical O(1) algorithm to create
182182

183183
**Validation**: The bins parameter must be between 2 and 50000 (inclusive). Values outside this range will result in an error.
184184

185-
**Limitation**: The bins parameter on timestamp fields requires pushdown to be enabled. When pushdown is disabled, use the ``span`` parameter instead (e.g., ``bin @timestamp span=5m``).
185+
**Limitation**: The bins parameter on timestamp fields has the following requirements:
186+
187+
1. **Pushdown must be enabled**: Controlled by ``plugins.calcite.pushdown.enabled`` (enabled by default). When pushdown is disabled, use the ``span`` parameter instead (e.g., ``bin @timestamp span=5m``).
188+
2. **Timestamp field must be used as an aggregation bucket**: The binned timestamp field must be used in a ``stats`` aggregation (e.g., ``source=events | bin @timestamp bins=3 | stats count() by @timestamp``). Using bins on timestamp fields outside of aggregation buckets is not supported.
186189

187190
The algorithm uses **mathematical optimization** instead of iteration for O(1) performance:
188191

integ-test/src/test/java/org/opensearch/sql/calcite/remote/CalciteBinCommandIT.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,6 +1140,10 @@ public void testBinsOnTimeFieldWithPushdownDisabled_ShouldFail() throws IOExcept
11401140
"source=events_null | bin @timestamp bins=3 | stats count() by @timestamp"));
11411141

11421142
// Verify the error message clearly explains the limitation and suggests solutions
1143+
// Note: bins parameter on timestamp fields requires BOTH:
1144+
// 1. Pushdown to be enabled (plugins.calcite.pushdown.enabled=true, enabled by default)
1145+
// 2. The timestamp field to be used as an aggregation bucket (e.g., stats count() by
1146+
// @timestamp)
11431147
String errorMessage = exception.getMessage();
11441148
assertTrue(
11451149
"Expected clear error message about bins parameter not supported on timestamp fields when "

0 commit comments

Comments
 (0)