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

Add Fold Transform #3813

Merged
merged 14 commits into from May 26, 2018
Merged

Add Fold Transform #3813

merged 14 commits into from May 26, 2018

Conversation

invokesus
Copy link
Member

@invokesus invokesus commented May 25, 2018

TODO:

  • Docs
  • Example

Copy link
Member

@kanitw kanitw left a 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.


public assemble(): VgFoldTransform {
const fields: string[] = [];
for (const field of this.transform.fold) {
Copy link
Member

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?

}
}

private getDefaultName(): [string, string] | undefined {
Copy link
Member

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);
Copy link
Member

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';
Copy link
Member

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?


private getDefaultName(): [string, string] | undefined {
const as = this.transform.as;
if (as && isString(as[0]) && isString(as[1])) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 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.

  2. if as[0] is specified, but as[1] isn't. Shouldn't we use [as[0], 'value'] ?

as: undefined
});
});
it ('should return proper produced fields for no "as"', () => {
Copy link
Member

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.

import {Transform} from '../../../src/transform';

describe('compile/data/fold', () => {
describe('Testing FoldTransformNode', () => {
Copy link
Member

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"].
Copy link
Member

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"]`

}

public producedFields() {
const names = this.getNames();
Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me fix it :)

@kanitw kanitw changed the base branch from master to feature/transform May 26, 2018 16:02
@kanitw kanitw changed the base branch from feature/transform to master May 26, 2018 16:04
@kanitw kanitw changed the base branch from master to feature/transform May 26, 2018 16:04
assert.deepEqual(fold.producedFields(), {'key': true, 'value': true});
});

it ('should return proper produced fields for no "as"', () => {
Copy link
Member Author

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.

Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup.

@@ -25,17 +25,6 @@ export class FoldTransformNode extends DataFlowNode {
}, {});
}

private getNames(): [string, string] | undefined {
Copy link
Member

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.

@kanitw kanitw merged commit ed3d381 into feature/transform May 26, 2018
@kanitw kanitw deleted the inv/fold branch May 26, 2018 17:13
invokesus added a commit that referenced this pull request May 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants