Skip to content

Commit ed625a1

Browse files
committed
Remove histograms from projects
1 parent 7a6e365 commit ed625a1

File tree

4 files changed

+72
-2
lines changed

4 files changed

+72
-2
lines changed

frontend/src/Models/Project/ColumnDbStats.elm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ encode value =
3434
, ( "bytesAvg", value.bytesAvg |> Encode.maybe Encode.float )
3535
, ( "cardinality", value.cardinality |> Encode.maybe Encode.float )
3636
, ( "commonValues", value.commonValues |> Encode.maybe (Encode.list encodeValue) )
37-
, ( "histogram", value.histogram |> Encode.maybe (Encode.list Encode.string) )
37+
, ( "histogram", Encode.null ) -- don't store histogram, bad chars can break Azimutt :/, old: value.histogram |> Encode.maybe (Encode.list Encode.string) )
3838
]
3939

4040

libs/utils/src/array.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
collectOne,
55
diffBy,
66
distinct,
7+
duplicates,
78
findLastIndex,
89
groupBy,
910
indexBy,
@@ -26,6 +27,9 @@ describe('array', () => {
2627
test('distinct', () => {
2728
expect(distinct([1, 1, 2, 3, 5, 3])).toEqual([1, 2, 3, 5])
2829
})
30+
test('duplicates', () => {
31+
expect(duplicates([1, 1, 2, 3, 5, 3, 1])).toEqual([1, 3])
32+
})
2933
test('diffBy', () => {
3034
expect(diffBy(
3135
[{id: 1, name: 'a'}, {id: 2, name: 'b'}],

libs/utils/src/array.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,34 @@ export const distinctBy = <T>(arr: T[], by: (t: T) => string | number): T[] => {
3333
})
3434
}
3535

36+
export const duplicates = <T>(arr: T[]): T[] => {
37+
const seen = new Set<T>()
38+
const dups = new Set<T>()
39+
return arr.filter(t => {
40+
if (seen.has(t)) {
41+
if (dups.has(t)) return false
42+
dups.add(t)
43+
return true
44+
}
45+
seen.add(t)
46+
return false
47+
})
48+
}
49+
export const duplicatesBy = <T>(arr: T[], by: (t: T) => string | number): T[] => {
50+
const seen = new Set<string | number>()
51+
const dups = new Set<string | number>()
52+
return arr.filter(t => {
53+
const key = by(t)
54+
if (seen.has(key)) {
55+
if (dups.has(key)) return false
56+
dups.add(key)
57+
return true
58+
}
59+
seen.add(key)
60+
return false
61+
})
62+
}
63+
3664
export type Diff<T> = {left: T[], right: T[], both: {left: T, right: T}[]}
3765
export const diffBy = <T>(arr1: T[], arr2: T[], f: (t: T, i: number) => string): Diff<T> => {
3866
const left: T[] = []

libs/utils/src/object.ts

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,26 @@
1-
import {isEmpty} from "./validation";
21
import {anySame} from "./any";
2+
import {Diff} from "./array";
3+
import {isEmpty} from "./validation";
34

45
// functions sorted alphabetically
56

7+
export const objDiff = <T>(obj1: Record<string, T>, obj2: Record<string, T>): Diff<T> => {
8+
const left: T[] = []
9+
const both: {left: T, right: T}[] = []
10+
const other = {...obj2}
11+
Object.entries(obj1).forEach(([k, v1]) => {
12+
const v2 = other[k]
13+
if (v2 === undefined) {
14+
left.push(v1)
15+
} else {
16+
both.push({left: v1, right: v2})
17+
}
18+
delete other[k]
19+
})
20+
const right: T[] = Object.values(other)
21+
return {left, right, both}
22+
}
23+
624
export function equalDeep<T>(a: T, b: T): boolean {
725
if (typeof a === 'string' || typeof a === 'number' || typeof a === 'boolean' || typeof a === 'symbol' || a === null || a === undefined) {
826
return a === b
@@ -106,6 +124,26 @@ export function removeFieldsDeep(obj: any, keysToRemove: string[]): any {
106124
return obj
107125
}
108126

127+
export function collectFieldsDeep(obj: any, keysToCollect: string[]): any[] {
128+
if (Array.isArray(obj)) {
129+
return obj.map(item => collectFieldsDeep(item, keysToCollect)).flat()
130+
}
131+
132+
if (typeof obj === 'object' && obj !== null) {
133+
const res: any[] = []
134+
Object.keys(obj).forEach(key => {
135+
if (keysToCollect.indexOf(key) >= 0) {
136+
res.push(obj[key])
137+
} else {
138+
res.push(...collectFieldsDeep(obj[key], keysToCollect))
139+
}
140+
})
141+
return res
142+
}
143+
144+
return []
145+
}
146+
109147
export function removeUndefined<K extends keyof any, V, T extends Record<K, V>>(obj: T): T {
110148
return filterValues(obj, v => v !== undefined)
111149
}

0 commit comments

Comments
 (0)