(
paths: unknown[],
aggregate:
| "COUNT"
| "SUM"
| "AVG"
| "MIN"
| "MAX"
| "COLLECT"
| "STDEV"
| "STDEVP"
| "PERCENTILEDISC"
| "PERCENTILECONT",
variable: string,
property?: string,
context?: QueryContext,
distinct?: boolean,
percentile?: number,
)
| 3161 | } |
| 3162 | |
| 3163 | #computeAggregate( |
| 3164 | paths: unknown[], |
| 3165 | aggregate: |
| 3166 | | "COUNT" |
| 3167 | | "SUM" |
| 3168 | | "AVG" |
| 3169 | | "MIN" |
| 3170 | | "MAX" |
| 3171 | | "COLLECT" |
| 3172 | | "STDEV" |
| 3173 | | "STDEVP" |
| 3174 | | "PERCENTILEDISC" |
| 3175 | | "PERCENTILECONT", |
| 3176 | variable: string, |
| 3177 | property?: string, |
| 3178 | context?: QueryContext, |
| 3179 | distinct?: boolean, |
| 3180 | percentile?: number, |
| 3181 | ): unknown { |
| 3182 | // Helper to create a string key for deduplication |
| 3183 | const valueKey = (value: unknown): string => { |
| 3184 | if (value === null || value === undefined) return "null"; |
| 3185 | if (value instanceof Vertex) return `v:${value.id}`; |
| 3186 | if (value instanceof Edge) return `e:${value.id}`; |
| 3187 | if (typeof value === "object") { |
| 3188 | try { |
| 3189 | return JSON.stringify(value); |
| 3190 | } catch { |
| 3191 | return String(value); |
| 3192 | } |
| 3193 | } |
| 3194 | return String(value); |
| 3195 | }; |
| 3196 | |
| 3197 | switch (aggregate) { |
| 3198 | case "COUNT": { |
| 3199 | if (distinct) { |
| 3200 | const seen = new Set<string>(); |
| 3201 | for (const path of paths) { |
| 3202 | const value = property |
| 3203 | ? this.#extractProperty(path, variable, property) |
| 3204 | : this.#extractValue(path, variable); |
| 3205 | // null values are not counted in count(DISTINCT x) |
| 3206 | if (value !== null && value !== undefined) { |
| 3207 | seen.add(valueKey(value)); |
| 3208 | } |
| 3209 | } |
| 3210 | return seen.size; |
| 3211 | } |
| 3212 | return paths.length; |
| 3213 | } |
| 3214 | |
| 3215 | case "SUM": { |
| 3216 | let sum = 0; |
| 3217 | const seen = distinct ? new Set<string>() : null; |
| 3218 | for (const path of paths) { |
| 3219 | const value = property |
| 3220 | ? this.#extractProperty(path, variable, property) |
no test coverage detected