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

未关闭
#549 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 3 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
45/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
活跃
技术栈
sql, typescript

调研方向

首先跟踪 useAnalyticsQuery 入口点和 analytics 插件配置,然后检查基于文件的查询如何在 JSON 和 Arrow 执行路径中进行缓存。定义每个查询的禁用策略或 TTL 策略如何保留现有默认值和执行隔离,并验证已禁用的查询会在没有 nonce 参数的情况下重新执行。

由索引模型根据 Issue 内容生成。

描述

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.
主要语言
TypeScript
星标
119
派生
36
平均合并
4 天 16 小时
30 天内合并 PR
37

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

databricks/appkit 的其他 Issue

查看 databricks/appkit 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。