@mastra/clickhouse 1.22.1-alpha.0 → 1.22.1

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.
package/dist/index.js CHANGED
@@ -4703,6 +4703,7 @@ function getAggregationSql$2(aggregation, measure = "valueNumber") {
4703
4703
  case "max": return `max(${measure})`;
4704
4704
  case "count": return `toFloat64(count(${measure}))`;
4705
4705
  case "last": return `argMax(${measure}, timestamp)`;
4706
+ case "count_distinct": return `toFloat64(uniq(${measure}))`;
4706
4707
  default: return `sum(${measure})`;
4707
4708
  }
4708
4709
  }
@@ -6156,6 +6157,7 @@ function getAggregationSql(aggregation, measure = "score") {
6156
6157
  case "max": return `max(${measure})`;
6157
6158
  case "count": return `toFloat64(count(${measure}))`;
6158
6159
  case "last": return `argMax(${measure}, timestamp)`;
6160
+ case "count_distinct": return `toFloat64(uniq(${measure}))`;
6159
6161
  default: return `sum(${measure})`;
6160
6162
  }
6161
6163
  }
@@ -6413,7 +6415,7 @@ async function getScoreById(client, scoreId) {
6413
6415
  return rows[0] ? rowToScoreRecord(rows[0]) : null;
6414
6416
  }
6415
6417
  async function getScoreAggregate(client, args) {
6416
- const aggSql = getAggregationSql(args.aggregation);
6418
+ const aggSql = `if(count() = 0, NULL, ${getAggregationSql(args.aggregation)})`;
6417
6419
  const identity = buildScoreIdentityFilter(args);
6418
6420
  const combined = mergeFilters(identity, buildScoresFilterConditions(args.filters));
6419
6421
  const whereClause = toWhereClause(combined);
@@ -8466,11 +8468,11 @@ async function detectDeltaCursorStrategy(client, override, existingStrategy) {
8466
8468
  if (override) return override;
8467
8469
  if (existingStrategy && existingStrategy !== "mixed") return existingStrategy;
8468
8470
  try {
8469
- await client.query({
8471
+ await (await client.query({
8470
8472
  query: `SELECT generateSerialID({counterName:String}) AS cursorId`,
8471
8473
  query_params: { counterName: "mastra_observability_delta_cursor_probe" },
8472
8474
  format: "JSONEachRow"
8473
- });
8475
+ })).json();
8474
8476
  return "serial";
8475
8477
  } catch {
8476
8478
  return "fallback";
@@ -8574,11 +8576,11 @@ var ObservabilityStorageClickhouseVNext = class extends ObservabilityStorage {
8574
8576
  if (this.#deltaCursorStrategy !== null) await reconcileScoreDeltaMv(this.#client, this.#replication, this.#deltaCursorStrategy, this.logger);
8575
8577
  await backfillCurrentScores(this.#client);
8576
8578
  if (this.#retention) await this.applyRetention();
8577
- if (this.#deltaCursorStrategy === "serial") for (const counterName of DELTA_CURSOR_COUNTER_NAMES) await this.#client.query({
8579
+ if (this.#deltaCursorStrategy === "serial") for (const counterName of DELTA_CURSOR_COUNTER_NAMES) await (await this.#client.query({
8578
8580
  query: `SELECT generateSerialID({counterName:String}) AS cursorId`,
8579
8581
  query_params: { counterName },
8580
8582
  format: "JSONEachRow"
8581
- });
8583
+ })).json();
8582
8584
  } catch (error) {
8583
8585
  if (error instanceof MastraError) throw error;
8584
8586
  const causeMessage = error instanceof Error ? error.message : String(error);