-
Notifications
You must be signed in to change notification settings - Fork 7
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
Used st_collect
only when it's needed
#178
Open
dgaubert
wants to merge
3
commits into
master
Choose a base branch
from
127-use-collect-when-needed
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,217 @@ | ||
'use strict'; | ||
|
||
var assert = require('assert'); | ||
|
||
var Analysis = require('../../lib/analysis'); | ||
|
||
var testConfig = require('../test-config'); | ||
var QueryRunner = require('../../lib/postgresql/query-runner'); | ||
|
||
describe('centroid analysis', function() { | ||
|
||
var queryRunner; | ||
|
||
before(function() { | ||
queryRunner = new QueryRunner(testConfig.db); | ||
}); | ||
|
||
var QUERY = 'select * from atm_machines'; | ||
var CATEGORY_COLUMN = 'kind'; | ||
var AGGREGATION = 'avg'; | ||
var AGGREGATION_COLUMN = 'cartodb_id'; | ||
|
||
var sourceAtmMachines = { | ||
type: 'source', | ||
params: { | ||
query: QUERY | ||
} | ||
}; | ||
|
||
var config = testConfig.create({ | ||
batch: { | ||
inlineExecution: true | ||
} | ||
}); | ||
|
||
function performAnalysis(definition, callback) { | ||
Analysis.create(config, definition, function (err, analysis) { | ||
if (err) { | ||
return callback(err); | ||
} | ||
|
||
queryRunner.run(analysis.getQuery(), function(err, result) { | ||
if (err) { | ||
return callback(err); | ||
} | ||
|
||
assert.ok(Array.isArray(result.rows)); | ||
var values = result.rows.map(function (value) { | ||
return value; | ||
}); | ||
|
||
callback(null, values); | ||
}); | ||
}); | ||
} | ||
|
||
describe('non optional params', function () { | ||
var centroidDefinition = { | ||
type: 'centroid', | ||
params: { | ||
source: sourceAtmMachines, | ||
} | ||
}; | ||
|
||
it('should create an analysis', function (done) { | ||
performAnalysis(centroidDefinition, function (err, values) { | ||
if(err) { | ||
return done(err); | ||
} | ||
assert.ok(values); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('with category column', function () { | ||
var centroidDefinition = { | ||
type: 'centroid', | ||
params: { | ||
source: sourceAtmMachines, | ||
category_column: CATEGORY_COLUMN | ||
} | ||
}; | ||
|
||
it('should create an analysis', function (done) { | ||
performAnalysis(centroidDefinition, function (err, values) { | ||
if(err) { | ||
return done(err); | ||
} | ||
assert.ok(values); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('with category column and aggregation (miss aggregation_column)', function () { | ||
var centroidDefinition = { | ||
type: 'centroid', | ||
params: { | ||
source: sourceAtmMachines, | ||
category_column: CATEGORY_COLUMN, | ||
aggregation: AGGREGATION | ||
} | ||
}; | ||
|
||
it('should return error', function (done) { | ||
performAnalysis(centroidDefinition, function (err, values) { | ||
assert.ok(err); | ||
assert.ok(!values); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('with category column, aggregation and aggregation column', function () { | ||
var centroidDefinition = { | ||
type: 'centroid', | ||
params: { | ||
source: sourceAtmMachines, | ||
category_column: CATEGORY_COLUMN, | ||
aggregation: AGGREGATION, | ||
aggregation_column: AGGREGATION_COLUMN | ||
} | ||
}; | ||
|
||
it('should create an analysis', function (done) { | ||
performAnalysis(centroidDefinition, function (err, values) { | ||
if(err) { | ||
return done(err); | ||
} | ||
assert.ok(values); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
|
||
describe('with aggregation (miss aggregation_colum for avg method)', function () { | ||
var centroidDefinition = { | ||
type: 'centroid', | ||
params: { | ||
source: sourceAtmMachines, | ||
aggregation: AGGREGATION | ||
} | ||
}; | ||
|
||
it('should return error', function (done) { | ||
performAnalysis(centroidDefinition, function (err, values) { | ||
assert.ok(err); | ||
assert.ok(!values); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
|
||
describe('with aggregation (miss aggregation_colum for avg method)', function () { | ||
var centroidDefinition = { | ||
type: 'centroid', | ||
params: { | ||
source: sourceAtmMachines, | ||
aggregation: 'count' | ||
} | ||
}; | ||
|
||
it('should create an analysis', function (done) { | ||
performAnalysis(centroidDefinition, function (err, values) { | ||
if(err) { | ||
return done(err); | ||
} | ||
assert.ok(values); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('with aggregation and aggregation column', function () { | ||
var centroidDefinition = { | ||
type: 'centroid', | ||
params: { | ||
source: sourceAtmMachines, | ||
aggregation: AGGREGATION, | ||
aggregation_column: AGGREGATION_COLUMN | ||
} | ||
}; | ||
|
||
it('should create an analysis', function (done) { | ||
performAnalysis(centroidDefinition, function (err, values) { | ||
if(err) { | ||
return done(err); | ||
} | ||
assert.ok(values); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
|
||
describe('with category_column and aggregation column', function () { | ||
var centroidDefinition = { | ||
type: 'centroid', | ||
params: { | ||
source: sourceAtmMachines, | ||
category_column: CATEGORY_COLUMN, | ||
aggregation_column: AGGREGATION_COLUMN | ||
} | ||
}; | ||
|
||
it('should return error', function (done) { | ||
performAnalysis(centroidDefinition, function (err, values) { | ||
assert.ok(err); | ||
assert.ok(!values); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 we change the default
count
?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.
To make it a real
nullable
; ifaggregation
comes with null then theENUM
replaces it withcount
and never isnull
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.
But that's the purpose of having a default value, isn't it?
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.
here we need a nullable enum, if
aggregation
comes withnull
value, we shouldn't setcount
as default, should we?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 not? I mean, it's nice to have the count by default, isn't it?
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.
😕 Well I'm not sure, when I used the Builder I have to check the checkbox to select aggregation function:
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.
That doesn't mean the node/analysis has to follow those defaults.
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.
But if
category_column
isnull
andst_collect
is not used, we are forcing to have acount column
filled entirely with1
. right?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 there is no category column the aggregation doesn't matter so you just don't do it. It will happen the same if there is no category column and the user provides an aggregation operation and an aggregation column, right?
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.
Yes, It will.
That's why we need to have the aggregation default to
null
to avoid to do aggregations if category column is not present.I think, I don't get your point. 😢