Support per-query cache policies for file-based analytics queries

Offen
#549 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 3 Tagen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Anfängerfreundlichkeit
45/100
Issue-Typ
Feature
Klarheit
Größtenteils klar
Aktivitätsstatus
Aktiv
Tech-Stack
sql, typescript

Rechercherichtung

Beginne damit, den useAnalyticsQuery-Einstiegspunkt und die Konfiguration des Analytics-Plugins nachzuverfolgen, und untersuche anschließend, wie dateibasierte Abfragen über die JSON- und Arrow-Ausführungspfade hinweg zwischengespeichert werden. Lege fest, wie pro Abfrage deaktivierte oder TTL-Richtlinien bestehende Standardeinstellungen und die Ausführungsisolierung bewahren, und überprüfe, dass deaktivierte Abfragen ohne Nonce-Parameter erneut ausgeführt werden.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Problem

AppKit's analytics plugin caches identical file-based SQL queries for one hour by default. Some queries are intentionally non-deterministic or calculate against current data and must execute every time the user submits them.

In AppKit 0.65.0, useAnalyticsQuery supports:

  • format
  • maxParametersSize
  • autoStart

There is no per-query cache option. Caching can be disabled globally with:

createApp({
  cache: {
    enabled: false,
  },
});

However, this disables caching for every AppKit plugin and analytics query in the application.

Example

-- config/queries/fresh_value.sql
SELECT current_timestamp() AS calculated_at
const { data } = useAnalyticsQuery('fresh_value');

After unmounting and remounting the component, the same cached timestamp is returned for up to an hour instead of executing the SQL again.

A more significant use case is a parameterized, non-deterministic table-valued function:

SELECT result_json
FROM IDENTIFIER(:functionName)(
  :input,
  :assumption
)

Submitting the same parameters again should deliberately recalculate against current source data.

Current workaround

We add a unique nonce to every submission:

-- @param queryNonce STRING
SELECT ...
WHERE length(:queryNonce) > 0
const [queryNonce] = useState(() => crypto.randomUUID());

const parameters = useMemo(
  () => ({
    input: sql.string(input),
    queryNonce: sql.string(queryNonce),
  }),
  [input, queryNonce]
);

This works because parameters are part of the cache key, but it pollutes the SQL contract and creates cache entries that can never be reused.

Requested capability

Please support a server-controlled cache policy for individual file-based queries.

For example, a query directive:

-- @cache disabled
SELECT ...

Or configurable TTL:

-- @cache ttl=60
SELECT ...

Alternatively, plugin configuration could define the policy:

analytics({
  queries: {
    fresh_value: {
      cache: false,
    },
    summary: {
      cache: { ttl: 60 },
    },
  },
});

A client-side option such as the following would also be useful, although a server-owned policy would prevent clients from bypassing caching for arbitrary expensive queries:

useAnalyticsQuery('fresh_value', parameters, {
  cache: 'no-store',
});

Expected behavior

  • Existing queries remain cached by default.
  • An individual query can disable caching or select a custom TTL.
  • The policy applies consistently to JSON and Arrow execution paths.
  • Service-principal and on-behalf-of-user execution retain their existing cache isolation.
  • Disabled queries execute against the warehouse on every request without requiring dummy parameters.
Vorherrschende Sprache
TypeScript
Sterne
119
Forks
36
Ø Merge
4 T. 16 Std.
Gemergte PRs (30 T.)
37

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus databricks/appkit

Alle Issues in databricks/appkit

Ähnliche Issues

Weitere Issues zu TypeScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.