Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release-23.1: ui: fix creation index syntax on console #107218

Merged
merged 1 commit into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,20 @@ describe("Create index name", () => {
{
name: "one parameter no space",
query: "CREATE INDEX ON t(i) STORING (k)",
expected: "CREATE INDEX IF NOT EXISTS t_i_rec_idx ON t(i) STORING (k)",
expected:
"CREATE INDEX IF NOT EXISTS t_i_storing_rec_idx ON t(i) STORING (k)",
},
{
name: "two parameters",
query: "CREATE INDEX ON t (i, j) STORING (k)",
expected:
"CREATE INDEX IF NOT EXISTS t_i_j_rec_idx ON t (i, j) STORING (k)",
"CREATE INDEX IF NOT EXISTS t_i_j_storing_rec_idx ON t (i, j) STORING (k)",
},
{
name: "one parameter, one expression",
query: "CREATE INDEX ON t (i, (j + k)) STORING (k)",
expected:
"CREATE INDEX IF NOT EXISTS t_i_expr_rec_idx ON t (i, (j + k)) STORING (k)",
"CREATE INDEX IF NOT EXISTS t_i_expr_storing_rec_idx ON t (i, (j + k)) STORING (k)",
},
{
name: "one parameter, one expression no parenthesis",
Expand All @@ -43,7 +44,7 @@ describe("Create index name", () => {
name: "two expressions",
query: "CREATE INDEX ON t ((i+l), (j + k)) STORING (k)",
expected:
"CREATE INDEX IF NOT EXISTS t_expr_expr1_rec_idx ON t ((i+l), (j + k)) STORING (k)",
"CREATE INDEX IF NOT EXISTS t_expr_expr1_storing_rec_idx ON t ((i+l), (j + k)) STORING (k)",
},
{
name: "one expression, one parameter",
Expand All @@ -54,19 +55,19 @@ describe("Create index name", () => {
name: "two expressions, one parameter",
query: "CREATE INDEX ON t ((i + l), (j + k), a) STORING (k)",
expected:
"CREATE INDEX IF NOT EXISTS t_expr_expr1_a_rec_idx ON t ((i + l), (j + k), a) STORING (k)",
"CREATE INDEX IF NOT EXISTS t_expr_expr1_a_storing_rec_idx ON t ((i + l), (j + k), a) STORING (k)",
},
{
name: "invalid expression, missing )",
query: "CREATE INDEX ON t ((i + l, (j + k), a) STORING (k)",
expected:
"CREATE INDEX IF NOT EXISTS t_expr_expr1_expr2_rec_idx ON t ((i + l, (j + k), a) STORING (k)",
"CREATE INDEX IF NOT EXISTS t_expr_expr1_expr2_storing_rec_idx ON t ((i + l, (j + k), a) STORING (k)",
},
{
name: "invalid expression, extra )",
query: "CREATE INDEX ON t ((i + l)), (j + k), a) STORING (k)",
expected:
"CREATE INDEX IF NOT EXISTS t_expr_rec_idx ON t ((i + l)), (j + k), a) STORING (k)",
"CREATE INDEX IF NOT EXISTS t_expr_storing_rec_idx ON t ((i + l)), (j + k), a) STORING (k)",
},
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,12 @@ export function createIdxName(statement: string): string {
idxName += "_" + value;
}
}

idxName += "_rec_idx";
const suffix =
statement.indexOf("STORING") >= 0 ? "_storing_rec_idx" : "_rec_idx";
// The table name is fully qualified at this point, but we don't need the full name,
// so just use the last value (also an index name can't have ".")
const idxNameArr = idxName.split(".");
idxName = idxNameArr[idxNameArr.length - 1].replace(/\s/g, "_") + suffix;

return statement.replace(
"CREATE INDEX ON ",
Expand Down