-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[Expressions] Use table column ID instead of name when set #99724
Changes from 4 commits
03563b4
41789fb
628cf8d
5413d7a
468cfcf
d222796
9f4d647
7f1df87
969ffd9
8d04687
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,7 +101,18 @@ export const mapColumn: ExpressionFunctionDefinition< | |
}); | ||
|
||
return Promise.all(rowPromises).then((rows) => { | ||
const existingColumnIndex = columns.findIndex(({ name }) => name === args.name); | ||
const existingColumnIndex = columns.findIndex(({ id, name }) => { | ||
// Columns that have IDs are allowed to have duplicate names, for example esaggs | ||
if (args.id) { | ||
return id === args.id; | ||
} | ||
// If the column has an ID, but there is no ID argument to mapColumn | ||
if (id) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we also check whether There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @flash1293 @poffdeluxe I've just changed the logic here since your last review. I'm now checking |
||
return id === args.name; | ||
} | ||
// Columns without ID use name as the unique key. For example, SQL output does not have IDs | ||
return name === args.name; | ||
}); | ||
const type = rows.length ? getType(rows[0][columnId]) : 'null'; | ||
const newColumn = { | ||
id: columnId, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,10 +130,11 @@ export const math: ExpressionFunctionDefinition< | |
throw errors.emptyExpression(); | ||
} | ||
|
||
// Use unique ID if available, otherwise fall back to names | ||
const mathContext = isDatatable(input) | ||
? pivotObjectArray( | ||
input.rows, | ||
input.columns.map((col) => col.name) | ||
input.columns.map((col) => col.id ?? col.name) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this necessary? If we can be sure there is an id now, we can simply use |
||
) | ||
: { value: input }; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the
args.id
is passed but the column does not haveid
is it ok to returnfalse
?I didn't see any test about this. I assume it's ok, but probably it's better to make it clear somewhere (either with a test or documentation).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dej611 good catch, I thought I had a test for this but I will add one.