@querypanel/node-sdk 1.3.7 → 1.3.8

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.d.cts CHANGED
@@ -867,6 +867,12 @@ interface AskOptions {
867
867
  previousSql?: string;
868
868
  /** Maximum number of retry attempts on execution failure. */
869
869
  maxRetry?: number;
870
+ /**
871
+ * Also retry (within `maxRetry`) when the query returns no rows, or one row of only zeros/NULLs
872
+ * (what `COUNT(*) ... WHERE status = 'approved'` returns when the data stores 'APPROVE').
873
+ * Only that fact is sent to QueryPanel, never rows or values. Default false.
874
+ */
875
+ retryOnEmptyResult?: boolean;
870
876
  /** Maximum number of retries for chart generation. */
871
877
  chartMaxRetries?: number;
872
878
  /** Choose chart generation method. */
package/dist/index.d.ts CHANGED
@@ -867,6 +867,12 @@ interface AskOptions {
867
867
  previousSql?: string;
868
868
  /** Maximum number of retry attempts on execution failure. */
869
869
  maxRetry?: number;
870
+ /**
871
+ * Also retry (within `maxRetry`) when the query returns no rows, or one row of only zeros/NULLs
872
+ * (what `COUNT(*) ... WHERE status = 'approved'` returns when the data stores 'APPROVE').
873
+ * Only that fact is sent to QueryPanel, never rows or values. Default false.
874
+ */
875
+ retryOnEmptyResult?: boolean;
870
876
  /** Maximum number of retries for chart generation. */
871
877
  chartMaxRetries?: number;
872
878
  /** Choose chart generation method. */
package/dist/index.js CHANGED
@@ -2444,6 +2444,15 @@ function resolveQueryPipeline(pipeline) {
2444
2444
  }
2445
2445
  return "v2";
2446
2446
  }
2447
+ var EMPTY_RESULT_ERROR = "The query ran but returned no rows (or only zero/NULL values). A filter value probably does not match how the data stores it (case, spelling, codes such as 'APPROVE' vs 'approved'), or a filter is narrower than the question. Check each filter value against the column's documented values and fix it; keep every filter the question asks for.";
2448
+ function isEmptyLikeResult(rows) {
2449
+ if (rows.length === 0) return true;
2450
+ if (rows.length > 1) return false;
2451
+ const row = rows[0];
2452
+ if (!row || typeof row !== "object") return false;
2453
+ const values = Object.values(row);
2454
+ return values.length > 0 && values.every((v) => v === null || v === 0 || v === "0" || v === 0n);
2455
+ }
2447
2456
  async function ask(client, queryEngine, question, options, signal) {
2448
2457
  const tenantId = resolveTenantId5(client, options.tenantId);
2449
2458
  const sessionId = crypto3.randomUUID();
@@ -2526,6 +2535,17 @@ async function ask(client, queryEngine, question, options, signal) {
2526
2535
  tenantId
2527
2536
  );
2528
2537
  const rows = execution.rows ?? [];
2538
+ if (options.retryOnEmptyResult && attempt < maxRetry && isEmptyLikeResult(rows)) {
2539
+ attempt++;
2540
+ lastError = EMPTY_RESULT_ERROR;
2541
+ previousSql = sql;
2542
+ console.warn("Query returned no data, retrying query generation", {
2543
+ attempt,
2544
+ maxAttempts: maxRetry + 1,
2545
+ sql
2546
+ });
2547
+ continue;
2548
+ }
2529
2549
  const chartType = options.chartType ?? "vega-lite";
2530
2550
  let chart = {
2531
2551
  specType: chartType,