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

feat: convert dataset to table class #1239

Merged
merged 14 commits into from
Feb 2, 2021

Conversation

heshan0131
Copy link
Contributor

  • add valueAccessor to Kepler field, remove tableFieldIdx
  • Move filter dataset in to table class
  • Move field domain calculation into table class

@macrigiuseppe macrigiuseppe changed the title [WIP] convert dataset to table class feat: convert dataset to table class Jan 25, 2021
@igorDykhta igorDykhta self-requested a review January 28, 2021 15:10
import './color-util-test';
import './util-test';
import './export-utils-test';
// import './gpu-filter-utils-test';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

all these tests are disabled?

@macrigiuseppe macrigiuseppe force-pushed the feature/field-value-accessor branch 2 times, most recently from bbfcd58 to 1cc8c16 Compare January 28, 2021 16:43
@@ -503,7 +504,7 @@ export default function MapContainerFactory(MapPopover, MapControl, Editor) {
transformRequest
};

const isEdit = mapControls.mapDraw.active;
const isEdit = !isExport && mapControls.mapDraw.active;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this now has confict with master

Copy link
Collaborator

Choose a reason for hiding this comment

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

Rebased

ibgreen and others added 13 commits January 29, 2021 14:12
Signed-off-by: Shan He <[email protected]>
Signed-off-by: Giuseppe Macri <[email protected]>
Signed-off-by: Giuseppe Macri <[email protected]>
Signed-off-by: Giuseppe Macri <[email protected]>
Signed-off-by: Giuseppe Macri <[email protected]>
Signed-off-by: Giuseppe Macri <[email protected]>
Signed-off-by: Giuseppe Macri <[email protected]>
@ibgreen
Copy link
Collaborator

ibgreen commented Jan 29, 2021

@igorDykhta Sounds like this is coming together, you can probably rebase your work on this now.

Copy link
Collaborator

@igorDykhta igorDykhta left a comment

Choose a reason for hiding this comment

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

Looks good in general.
Not sure about inconsistent fieldIdx in several tests and some comments leftovers.

@@ -900,8 +895,8 @@ export default class Layer {
* @returns {object} layer
*/
updateLayerDomain(datasets, newFilter) {
const dataset = this.getDataset(datasets);
if (!dataset) {
const table = this.getDataset(datasets);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Interchangeable table/dataset variables are quite confusing. Do we plan to unify this in the future?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yea i agree, let's just keep calling it dataset in kepler.gl, because it is used everywhere

@@ -140,6 +140,7 @@ export function processCsvData(rawData, header) {
// here we get a list of none null values to run analyze on
const sample = getSampleForTypeAnalyze({fields: headerRow, allData: rows});
const fields = getFieldsFromData(sample, headerRow);
// console.log(JSON.stringify(fields, null, 2));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Comment left after testing.

analyzerType: 'INT'
fieldIdx: 9,
analyzerType: 'INT',
valueAccessor: values => values[0]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not exactly sure about underlying test logic, but should it be values[9]?

Copy link
Collaborator

Choose a reason for hiding this comment

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

the test logic only validates the presence of the valueAccessor. it's part of test field. It's really difficult to compare functions and that's why we only validate the presence and the validity of the field, e.g not null.
I can definitely update to valueAccessor: values => values[9] but it will not make a difference.

analyzerType: 'FLOAT'
fieldIdx: 5,
analyzerType: 'FLOAT',
valueAccessor: values => values[4]
Copy link
Collaborator

Choose a reason for hiding this comment

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

values[5] ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

same as above

// mergedEpochFilter
// ];
//
// cmpFilters(t, expectedFilters, mergedState.filters);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need this commented out check?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yea, we should test these merged filters

analyzerType: 'FLOAT',
format: ''
format: '',
valueAccessor: values => values[1]
Copy link
Collaborator

Choose a reason for hiding this comment

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

values[0]?

Copy link
Collaborator

Choose a reason for hiding this comment

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

same as the above

@@ -79,17 +74,16 @@ export class Layer {
_oldDataUpdateTriggers: any;
hasAllColumns(): boolean;
updateLayerConfig(p: Partial<LayerConfig>): Layer;
updateLayerDomain(datasets: Datasets, filter?: Filter): Layer;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

why is this type def deleted? base-layer still has updateLayerDomain method

Copy link
Collaborator

@macrigiuseppe macrigiuseppe Feb 2, 2021

Choose a reason for hiding this comment

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

not sure why this was deleted but i will revert it back

Copy link
Contributor Author

Choose a reason for hiding this comment

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

probably some rebase conflicts
same for

isLayerHovered(objectInfo: any): boolean;
  hasHoveredObject(objectInfo: any): any | null;
  getHoverData(object: any, allData?: Dataset['allData'], fields?: Dataset['fields']): any;

@@ -481,12 +482,12 @@ export function layerVisualChannelChangeUpdater(state, action) {
if (!oldLayer.config.dataId) {
return state;
}
const dataset = state.datasets[oldLayer.config.dataId];
const table = state.datasets[oldLayer.config.dataId];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

change this back to dataset?


const idx = state.layers.findIndex(l => l.id === oldLayer.id);
const newLayer = oldLayer.updateLayerConfig(newConfig);

newLayer.updateLayerVisualChannel(dataset, channel);
newLayer.updateLayerVisualChannel(table, channel);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

same her

@@ -962,45 +909,42 @@ export function applyFiltersToDatasets(datasetIds, datasets, filters, layers) {
export function applyFilterFieldName(filter, dataset, fieldName, filterDatasetIndex = 0, option) {
// using filterDatasetIndex we can filter only the specified dataset
const mergeDomain = option && option.hasOwnProperty('mergeDomain') ? option.mergeDomain : false;
const {fields, allData} = dataset;
// const {fields, allData} = dataset;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

delete comment

field.hasOwnProperty('filterProps') && field.filterProps
? field.filterProps
: getFilterProps(allData, field);
// const field = fields[fieldIndex];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

delete comment

};

const newFields = Object.assign([...fields], {[fieldIndex]: fieldWithFilterProps});
// const fieldWithFilterProps = {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

delete comment

tableFieldIndex: 10,
analyzerType: 'DATETIME'
analyzerType: 'DATETIME',
valueAccessor: values => values[9]
Copy link
Contributor Author

@heshan0131 heshan0131 Feb 2, 2021

Choose a reason for hiding this comment

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

this doesn't seem to be right, ts valueAccessor should return epoch milisecond, are these really tested?

tableFieldIndex: 9,
analyzerType: 'DATETIME'
analyzerType: 'DATETIME',
valueAccessor: values => values[8]
Copy link
Contributor Author

@heshan0131 heshan0131 Feb 2, 2021

Choose a reason for hiding this comment

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

Same as above

});
}
} else if (k === 'valueAccessor') {
t.ok(typeof actual[k] === 'function', `${name}.valueAccessor should be a function`);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we should actually test valueAccessor not that it's just a function

Copy link
Collaborator

@macrigiuseppe macrigiuseppe Feb 2, 2021

Choose a reason for hiding this comment

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

got it. it's not easy to test equality (not memory address but value) among functions, how should we test it?
I was thinking about the following options:

  • calling the function with some data and check that both function return the same value? this may have other implications, e.g. sometimes we only compare layers and we don't have the actual data.
  • use toString on both functions and compare the output?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok i guess it's fine. the result of valueAccessor is indirectly tested in format layer data and filter.

Copy link
Collaborator

Choose a reason for hiding this comment

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

cool

// mergedEpochFilter
// ];
//
// cmpFilters(t, expectedFilters, mergedState.filters);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

yea, we should test these merged filters

@@ -400,39 +400,6 @@ test('VisStateMerger.v1 -> mergeLayers -> toEmptyState', t => {
t.end();
});

test('VisStateMerger.v1 -> mergeLayers -> toEmptyState', t => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this test deleted?

Copy link
Collaborator

Choose a reason for hiding this comment

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

oh yeah, this test was a duplicate of the one at line 370

const isTime = field.type === ALL_FIELD_TYPES.timestamp;
const valueAccessor = maybeToDate.bind(null, isTime, fieldIdx, field.format);
let domain;
// export function getFieldDomain(allData, field) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

remove comment

@macrigiuseppe macrigiuseppe merged commit 9476c29 into master Feb 2, 2021
@delete-merged-branch delete-merged-branch bot deleted the feature/field-value-accessor branch February 2, 2021 19:03
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.

4 participants