@mastra/duckdb 1.11.0 → 1.11.1-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4187,10 +4187,10 @@ async function listTraceRows(db, args, reconstructSelect, mapRow, toSpans) {
4187
4187
  if (orderDir !== "ASC" && orderDir !== "DESC") throw new Error(`Invalid sort direction: ${orderBy.direction}`);
4188
4188
  const canOrderInPrefilter = SAFE_PREFILTER_ORDER_FIELDS.has(orderBy.field);
4189
4189
  if (!(Object.keys(postAgg).length > 0 || hasChildError !== void 0 || !canOrderInPrefilter)) {
4190
- const prefilterOrderBy = `ORDER BY timestamp ${orderDir}`;
4190
+ const prefilterOrderBy = `ORDER BY anchorStartedAt ${orderDir}, traceId, spanId`;
4191
4191
  const offset = page * perPage;
4192
4192
  const countSql = `
4193
- SELECT COUNT(*) as total
4193
+ SELECT COUNT(DISTINCT (traceId, spanId)) as total
4194
4194
  FROM span_events AS ${outerAlias}
4195
4195
  ${prefilterWhere}
4196
4196
  `;
@@ -4198,14 +4198,15 @@ async function listTraceRows(db, args, reconstructSelect, mapRow, toSpans) {
4198
4198
  const total = Number(countResult[0]?.total ?? 0);
4199
4199
  const pageSql = `
4200
4200
  WITH page_roots AS (
4201
- SELECT traceId, spanId, timestamp AS anchorStartedAt
4201
+ SELECT traceId, spanId, min(timestamp) AS anchorStartedAt
4202
4202
  FROM span_events AS ${outerAlias}
4203
4203
  ${prefilterWhere}
4204
+ GROUP BY traceId, spanId
4204
4205
  ${prefilterOrderBy}
4205
4206
  LIMIT ? OFFSET ?
4206
4207
  )
4207
4208
  ${reconstructForAnchors(reconstructSelect, "page_roots")}
4208
- ${buildOrderByClause(orderBy)}
4209
+ ${buildOrderByClause(orderBy)}, traceId, spanId
4209
4210
  `;
4210
4211
  const spans = (await db.query(pageSql, [
4211
4212
  ...prefilterParams,
@@ -4318,9 +4319,10 @@ async function listTraces(db, args) {
4318
4319
  };
4319
4320
  const dataSql = `
4320
4321
  WITH candidate_roots AS (
4321
- SELECT traceId, spanId, cursorId
4322
+ SELECT traceId, spanId, max(cursorId) AS cursorId
4322
4323
  FROM span_events AS ${outerAlias}
4323
4324
  ${prefilterWhere}
4325
+ GROUP BY traceId, spanId
4324
4326
  ),
4325
4327
  root_spans AS (
4326
4328
  SELECT reconstructed.*, candidate_roots.cursorId AS anchorCursorId
@@ -4494,9 +4496,10 @@ async function listBranches(db, args) {
4494
4496
  };
4495
4497
  const dataSql = `
4496
4498
  WITH candidate_anchors AS (
4497
- SELECT traceId, spanId, cursorId
4499
+ SELECT traceId, spanId, max(cursorId) AS cursorId
4498
4500
  FROM span_events AS ${outerAlias}
4499
4501
  ${prefilterWhere}
4502
+ GROUP BY traceId, spanId
4500
4503
  ),
4501
4504
  branch_anchors AS (
4502
4505
  SELECT reconstructed.*, candidate_anchors.cursorId AS anchorCursorId
@@ -4547,10 +4550,10 @@ async function listBranches(db, args) {
4547
4550
  const currentDeltaCursor = deltaPollingFeatureEnabled() ? await getBranchDeltaCursor(db, filters) : void 0;
4548
4551
  const canOrderInPrefilter = SAFE_PREFILTER_ORDER_FIELDS.has(orderBy.field);
4549
4552
  if (!(Object.keys(postAgg).length > 0 || !canOrderInPrefilter)) {
4550
- const prefilterOrderBy = `ORDER BY timestamp ${orderDir}`;
4553
+ const prefilterOrderBy = `ORDER BY anchorStartedAt ${orderDir}, traceId, spanId`;
4551
4554
  const offset = page * perPage;
4552
4555
  const countSql = `
4553
- SELECT COUNT(*) as total
4556
+ SELECT COUNT(DISTINCT (traceId, spanId)) as total
4554
4557
  FROM span_events AS ${outerAlias}
4555
4558
  ${prefilterWhere}
4556
4559
  `;
@@ -4568,14 +4571,15 @@ async function listBranches(db, args) {
4568
4571
  };
4569
4572
  const pageSql = `
4570
4573
  WITH page_anchors AS (
4571
- SELECT traceId, spanId, timestamp AS anchorStartedAt
4574
+ SELECT traceId, spanId, min(timestamp) AS anchorStartedAt
4572
4575
  FROM span_events AS ${outerAlias}
4573
4576
  ${prefilterWhere}
4577
+ GROUP BY traceId, spanId
4574
4578
  ${prefilterOrderBy}
4575
4579
  LIMIT ? OFFSET ?
4576
4580
  )
4577
4581
  ${reconstructForAnchors(SPAN_RECONSTRUCT_SELECT, "page_anchors")}
4578
- ${buildOrderByClause(orderBy)}
4582
+ ${buildOrderByClause(orderBy)}, traceId, spanId
4579
4583
  `;
4580
4584
  const spans = (await db.query(pageSql, [
4581
4585
  ...prefilterParams,
@@ -5039,4 +5043,4 @@ var ObservabilityStorageDuckDB = class ObservabilityStorageDuckDB extends Observ
5039
5043
  //#endregion
5040
5044
  export { ObservabilityStorageDuckDB };
5041
5045
 
5042
- //# sourceMappingURL=observability-CDtl20Mc.js.map
5046
+ //# sourceMappingURL=observability-By_TJb9K.js.map