Adding in char sequence.
This commit is contained in:
parent
967f737158
commit
c11527d539
|
@ -8,33 +8,51 @@ import {
|
||||||
import { getDatasourceAndQuery } from "../../../sdk/app/rows/utils"
|
import { getDatasourceAndQuery } from "../../../sdk/app/rows/utils"
|
||||||
import { cloneDeep } from "lodash"
|
import { cloneDeep } from "lodash"
|
||||||
|
|
||||||
|
class CharSequence {
|
||||||
|
static alphabet = "abcdefghijklmnopqrstuvwxyz"
|
||||||
|
counters: number[]
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.counters = [0]
|
||||||
|
}
|
||||||
|
|
||||||
|
get character() {
|
||||||
|
return this.counters.map(i => CharSequence.alphabet[i]).join("")
|
||||||
|
}
|
||||||
|
|
||||||
|
next() {
|
||||||
|
for (let i = this.counters.length - 1; i >= 0; i--) {
|
||||||
|
if (this.counters[i] < CharSequence.alphabet.length - 1) {
|
||||||
|
this.counters[i]++
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.counters[i] = 0
|
||||||
|
}
|
||||||
|
this.counters.unshift(0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default class AliasTables {
|
export default class AliasTables {
|
||||||
character: string
|
|
||||||
aliases: Record<string, string>
|
aliases: Record<string, string>
|
||||||
tableAliases: Record<string, string>
|
tableAliases: Record<string, string>
|
||||||
tableNames: string[]
|
tableNames: string[]
|
||||||
|
charSeq: CharSequence
|
||||||
|
|
||||||
constructor(tableNames: string[]) {
|
constructor(tableNames: string[]) {
|
||||||
this.tableNames = tableNames
|
this.tableNames = tableNames
|
||||||
this.character = "a"
|
|
||||||
this.aliases = {}
|
this.aliases = {}
|
||||||
this.tableAliases = {}
|
this.tableAliases = {}
|
||||||
|
this.charSeq = new CharSequence()
|
||||||
}
|
}
|
||||||
|
|
||||||
getAlias(tableName: string) {
|
getAlias(tableName: string) {
|
||||||
if (this.aliases[tableName]) {
|
if (this.aliases[tableName]) {
|
||||||
return this.aliases[tableName]
|
return this.aliases[tableName]
|
||||||
}
|
}
|
||||||
const char = this.character
|
const char = this.charSeq.character
|
||||||
|
this.charSeq.next()
|
||||||
this.aliases[tableName] = char
|
this.aliases[tableName] = char
|
||||||
this.tableAliases[char] = tableName
|
this.tableAliases[char] = tableName
|
||||||
this.character =
|
|
||||||
char.substring(0, char.length - 1) +
|
|
||||||
String.fromCharCode(char.charCodeAt(char.length - 1) + 1)
|
|
||||||
// reached end of characters, extend number of characters used
|
|
||||||
if (this.character.charAt(this.character.length - 1) === "z") {
|
|
||||||
this.character = new Array(this.character.length + 1).fill("a").join("")
|
|
||||||
}
|
|
||||||
return char
|
return char
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -171,7 +171,7 @@ describe("Captures of real examples", () => {
|
||||||
for (let table of tableNames) {
|
for (let table of tableNames) {
|
||||||
alias = aliasing.getAlias(table)
|
alias = aliasing.getAlias(table)
|
||||||
}
|
}
|
||||||
expect(alias).toEqual("aaay")
|
expect(alias).toEqual("cu")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue