@mastra/clickhouse 1.19.1-alpha.0 → 1.20.0-alpha.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/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +117 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +117 -0
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/observability/v-next/index.d.ts +4 -2
- package/dist/storage/domains/observability/v-next/index.d.ts.map +1 -1
- package/dist/storage/domains/observability/v-next/trace-query.d.ts +5 -1
- package/dist/storage/domains/observability/v-next/trace-query.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/docs/SKILL.md
CHANGED
|
@@ -3,7 +3,7 @@ name: mastra-clickhouse
|
|
|
3
3
|
description: Documentation for @mastra/clickhouse. Use when working with @mastra/clickhouse APIs, configuration, or implementation.
|
|
4
4
|
metadata:
|
|
5
5
|
package: "@mastra/clickhouse"
|
|
6
|
-
version: "1.
|
|
6
|
+
version: "1.20.0-alpha.1"
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
## When to use
|
package/dist/index.cjs
CHANGED
|
@@ -6797,6 +6797,76 @@ LIMIT ${limit}`,
|
|
|
6797
6797
|
query_params: parameters.params
|
|
6798
6798
|
};
|
|
6799
6799
|
}
|
|
6800
|
+
function discoveryRegistry(scope) {
|
|
6801
|
+
if (scope === "trace") return TRACE_FIELDS;
|
|
6802
|
+
if (scope === "spans") return SPAN_FIELDS;
|
|
6803
|
+
if (scope === "scores") return SCORE_FIELDS;
|
|
6804
|
+
return FEEDBACK_FIELDS;
|
|
6805
|
+
}
|
|
6806
|
+
function discoverySource(scope) {
|
|
6807
|
+
if (scope === "trace") return "root_scope r";
|
|
6808
|
+
if (scope === "spans") return "current_spans s";
|
|
6809
|
+
if (scope === "scores") return "current_scores s";
|
|
6810
|
+
return "current_feedback s";
|
|
6811
|
+
}
|
|
6812
|
+
function discoveryCollections(scope) {
|
|
6813
|
+
return scope === "trace" ? /* @__PURE__ */ new Set() : /* @__PURE__ */ new Set([scope]);
|
|
6814
|
+
}
|
|
6815
|
+
function compileClickHouseTraceQueryObservedFields(plan) {
|
|
6816
|
+
const parameters = new ParameterBuilder();
|
|
6817
|
+
const ctes = compileClickHouseTraceScope(plan, /* @__PURE__ */ new Set(), parameters);
|
|
6818
|
+
const search = plan.search ? `AND positionCaseInsensitiveUTF8(concat('metadata.', key), ${parameters.add(plan.search, "String")}) > 0` : "";
|
|
6819
|
+
const limit = parameters.add(plan.limit + 1, "UInt64");
|
|
6820
|
+
ctes.push(`metadata_entries AS (
|
|
6821
|
+
SELECT
|
|
6822
|
+
entry.1 AS key,
|
|
6823
|
+
entry.2 AS rawValue,
|
|
6824
|
+
JSONExtractString(entry.2) AS value
|
|
6825
|
+
FROM root_scope r
|
|
6826
|
+
ARRAY JOIN JSONExtractKeysAndValuesRaw(ifNull(r.metadataRaw, '{}')) AS entry
|
|
6827
|
+
)`);
|
|
6828
|
+
return {
|
|
6829
|
+
query: `WITH ${ctes.join(",\n")}
|
|
6830
|
+
SELECT concat('metadata.', key) AS path, count() AS occurrences
|
|
6831
|
+
FROM metadata_entries
|
|
6832
|
+
WHERE JSONType(rawValue) = 'String'
|
|
6833
|
+
AND trim(value) != ''
|
|
6834
|
+
AND key != ''
|
|
6835
|
+
AND position(key, '.') = 0
|
|
6836
|
+
AND length(concat('metadata.', key)) <= ${_mastra_core_storage.TRACE_QUERY_MAX_PATH_BYTES}
|
|
6837
|
+
AND length(value) <= ${_mastra_core_storage.TRACE_QUERY_MAX_STRING_BYTES}
|
|
6838
|
+
${search}
|
|
6839
|
+
GROUP BY key
|
|
6840
|
+
ORDER BY occurrences DESC, path ASC
|
|
6841
|
+
LIMIT ${limit}`,
|
|
6842
|
+
query_params: parameters.params
|
|
6843
|
+
};
|
|
6844
|
+
}
|
|
6845
|
+
function compileClickHouseTraceQueryValues(plan) {
|
|
6846
|
+
const parameters = new ParameterBuilder();
|
|
6847
|
+
const ctes = compileClickHouseTraceScope(plan, discoveryCollections(plan.predicateScope), parameters);
|
|
6848
|
+
let field;
|
|
6849
|
+
if (plan.predicateScope === "trace" && plan.path.startsWith("metadata.")) {
|
|
6850
|
+
const key = parameters.add(plan.path.slice(9), "String");
|
|
6851
|
+
field = `coalesce(if(mapContains(r.metadataSearch, ${key}), r.metadataSearch[${key}], NULL), nullIf(trim(JSONExtractString(r.metadataRaw, ${key})), ''))`;
|
|
6852
|
+
} else field = fieldDefinition(discoveryRegistry(plan.predicateScope), plan.path).sql;
|
|
6853
|
+
const search = plan.search ? `AND positionCaseInsensitiveUTF8(value, ${parameters.add(plan.search, "String")}) > 0` : "";
|
|
6854
|
+
const limit = parameters.add(plan.limit + 1, "UInt64");
|
|
6855
|
+
return {
|
|
6856
|
+
query: `WITH ${ctes.join(",\n")}, extracted AS (
|
|
6857
|
+
SELECT toString(${field}) AS value FROM ${discoverySource(plan.predicateScope)}
|
|
6858
|
+
)
|
|
6859
|
+
SELECT value, count() AS count
|
|
6860
|
+
FROM extracted
|
|
6861
|
+
WHERE value IS NOT NULL
|
|
6862
|
+
AND length(value) <= ${_mastra_core_storage.TRACE_QUERY_MAX_STRING_BYTES}
|
|
6863
|
+
${search}
|
|
6864
|
+
GROUP BY value
|
|
6865
|
+
ORDER BY count DESC, value ASC
|
|
6866
|
+
LIMIT ${limit}`,
|
|
6867
|
+
query_params: parameters.params
|
|
6868
|
+
};
|
|
6869
|
+
}
|
|
6800
6870
|
function asIsoTimestamp(value) {
|
|
6801
6871
|
return new Date(value).toISOString();
|
|
6802
6872
|
}
|
|
@@ -6823,6 +6893,27 @@ async function runWithClickHouseTraceQueryTimeout(client, timeoutMs, compiled, q
|
|
|
6823
6893
|
throw error;
|
|
6824
6894
|
}
|
|
6825
6895
|
}
|
|
6896
|
+
async function getTraceQueryObservedFields(client, plan, timeoutMs) {
|
|
6897
|
+
if (plan.predicateScope !== "trace") return {
|
|
6898
|
+
observedFields: [],
|
|
6899
|
+
observedFieldsTruncated: false
|
|
6900
|
+
};
|
|
6901
|
+
const rows = await runWithClickHouseTraceQueryTimeout(client, timeoutMs, compileClickHouseTraceQueryObservedFields(plan));
|
|
6902
|
+
return {
|
|
6903
|
+
observedFields: rows.slice(0, plan.limit).map((row) => _mastra_core_storage.createTraceQueryObservedFieldDescriptor(String(row.path), Number(row.occurrences))),
|
|
6904
|
+
observedFieldsTruncated: rows.length > plan.limit
|
|
6905
|
+
};
|
|
6906
|
+
}
|
|
6907
|
+
async function getTraceQueryValues(client, plan, timeoutMs) {
|
|
6908
|
+
const rows = await runWithClickHouseTraceQueryTimeout(client, timeoutMs, compileClickHouseTraceQueryValues(plan));
|
|
6909
|
+
return _mastra_core_storage.getTraceQueryValuesResponseSchema.parse({
|
|
6910
|
+
values: rows.slice(0, plan.limit).map((row) => ({
|
|
6911
|
+
value: String(row.value),
|
|
6912
|
+
count: Number(row.count)
|
|
6913
|
+
})),
|
|
6914
|
+
valuesTruncated: rows.length > plan.limit
|
|
6915
|
+
});
|
|
6916
|
+
}
|
|
6826
6917
|
async function queryTraces(client, plan, timeoutMs) {
|
|
6827
6918
|
const rows = await runWithClickHouseTraceQueryTimeout(client, timeoutMs, compileClickHouseTraceQuery(plan));
|
|
6828
6919
|
const visibleRows = rows.slice(0, plan.limit);
|
|
@@ -7988,6 +8079,7 @@ var ObservabilityStorageClickhouseVNext = class extends _mastra_core_storage.Obs
|
|
|
7988
8079
|
"metrics",
|
|
7989
8080
|
"logs",
|
|
7990
8081
|
"trace-query",
|
|
8082
|
+
"trace-query-discovery",
|
|
7991
8083
|
"thread-query"
|
|
7992
8084
|
];
|
|
7993
8085
|
return [
|
|
@@ -7995,6 +8087,7 @@ var ObservabilityStorageClickhouseVNext = class extends _mastra_core_storage.Obs
|
|
|
7995
8087
|
"logs",
|
|
7996
8088
|
"delta-polling",
|
|
7997
8089
|
"trace-query",
|
|
8090
|
+
"trace-query-discovery",
|
|
7998
8091
|
"thread-query"
|
|
7999
8092
|
];
|
|
8000
8093
|
}
|
|
@@ -8122,6 +8215,30 @@ var ObservabilityStorageClickhouseVNext = class extends _mastra_core_storage.Obs
|
|
|
8122
8215
|
}, error);
|
|
8123
8216
|
}
|
|
8124
8217
|
}
|
|
8218
|
+
async getTraceQueryObservedFields(plan) {
|
|
8219
|
+
try {
|
|
8220
|
+
return await getTraceQueryObservedFields(this.#client, plan, this.#traceQueryTimeoutMs);
|
|
8221
|
+
} catch (error) {
|
|
8222
|
+
if (error instanceof _mastra_core_error.MastraError || error instanceof _mastra_core_storage.TraceQueryExecutionError) throw error;
|
|
8223
|
+
throw new _mastra_core_error.MastraError({
|
|
8224
|
+
id: (0, _mastra_core_storage.createStorageErrorId)("CLICKHOUSE", "GET_TRACE_QUERY_OBSERVED_FIELDS", "FAILED"),
|
|
8225
|
+
domain: _mastra_core_error.ErrorDomain.STORAGE,
|
|
8226
|
+
category: _mastra_core_error.ErrorCategory.THIRD_PARTY
|
|
8227
|
+
}, error);
|
|
8228
|
+
}
|
|
8229
|
+
}
|
|
8230
|
+
async getTraceQueryValues(plan) {
|
|
8231
|
+
try {
|
|
8232
|
+
return await getTraceQueryValues(this.#client, plan, this.#traceQueryTimeoutMs);
|
|
8233
|
+
} catch (error) {
|
|
8234
|
+
if (error instanceof _mastra_core_error.MastraError || error instanceof _mastra_core_storage.TraceQueryExecutionError) throw error;
|
|
8235
|
+
throw new _mastra_core_error.MastraError({
|
|
8236
|
+
id: (0, _mastra_core_storage.createStorageErrorId)("CLICKHOUSE", "GET_TRACE_QUERY_VALUES", "FAILED"),
|
|
8237
|
+
domain: _mastra_core_error.ErrorDomain.STORAGE,
|
|
8238
|
+
category: _mastra_core_error.ErrorCategory.THIRD_PARTY
|
|
8239
|
+
}, error);
|
|
8240
|
+
}
|
|
8241
|
+
}
|
|
8125
8242
|
async queryThreads(plan) {
|
|
8126
8243
|
try {
|
|
8127
8244
|
return await queryThreads(this.#client, plan, this.#traceQueryTimeoutMs);
|