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
Add Fold Transform #3813
Add Fold Transform #3813
Conversation
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.
Great job. After addressing these some minor comments, we should be good to go.
src/compile/data/fold.ts
Outdated
|
||
public assemble(): VgFoldTransform { | ||
const fields: string[] = []; | ||
for (const field of this.transform.fold) { |
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.
Why do you have to convert undefined to null? Can't you just do fields: this.transform.fold
?
src/compile/data/fold.ts
Outdated
} | ||
} | ||
|
||
private getDefaultName(): [string, string] | undefined { |
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.
This method do more than returning default names. (It returns non-default specified value too, so the method name is a bit misleading.)
const fold = head = new FoldTransformNode(head, t); | ||
|
||
for (const field of keys(fold.producedFields())) { | ||
ancestorParse.set(field, 'derived', false); |
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.
Don't forget to refactor these once we merge all of fold and flatten PR.
@@ -1,4 +1,5 @@ | |||
import {AggregateOp} from 'vega'; | |||
import {FoldTransform as VgFoldTransform} from 'vega-typings'; |
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.
Great! This is exactly what we need.
@domoritz I wonder if we should import and reexport from this file so the rest of the codebase do not have to do as
and thus will have consistent name?
src/compile/data/fold.ts
Outdated
|
||
private getDefaultName(): [string, string] | undefined { | ||
const as = this.transform.as; | ||
if (as && isString(as[0]) && isString(as[1])) { |
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.
-
I don't think you need to check if each item is a string as that's already enforced by the schema. Just need to check if they exist.
-
if as[0] is specified, but as[1] isn't. Shouldn't we use
[as[0], 'value']
?
test/compile/data/fold.test.ts
Outdated
as: undefined | ||
}); | ||
}); | ||
it ('should return proper produced fields for no "as"', () => { |
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.
Please add line breaks between tests.
test/compile/data/fold.test.ts
Outdated
import {Transform} from '../../../src/transform'; | ||
|
||
describe('compile/data/fold', () => { | ||
describe('Testing FoldTransformNode', () => { |
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.
'Testing FoldTransformNode' => 'FoldTransformNode'
Everything under test is a test. :)
src/transform.ts
Outdated
|
||
/** | ||
* The output field names for the key and value properties produced by the fold transform. | ||
* The default is ["key", "value"]. |
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.
Always use __Default value:__
and wrap the default value in back ticks
__Default value:__ `["key", "value"]`
behavior for single element 'as' array, rename getDefaultNames => getNames.
src/compile/data/fold.ts
Outdated
} | ||
|
||
public producedFields() { | ||
const names = this.getNames(); |
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.
It's weird that you're calling getNames()
again in producedFields().
The whole point of setting as in constructor is that you can just simply uses as
to determine producedFields.
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.
Let me fix it :)
test/compile/data/fold.test.ts
Outdated
assert.deepEqual(fold.producedFields(), {'key': true, 'value': true}); | ||
}); | ||
|
||
it ('should return proper produced fields for no "as"', () => { |
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.
Forgot to change this. Should be complete
instead of no
.
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.
Can you fix it and make test pass
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.
Yup.
src/compile/data/fold.ts
Outdated
@@ -25,17 +25,6 @@ export class FoldTransformNode extends DataFlowNode { | |||
}, {}); | |||
} | |||
|
|||
private getNames(): [string, string] | undefined { |
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.
ah sorry forgot to remove this.
TODO: