Distinct support for null (#4559)
* distinct support for null * better testing
This commit is contained in:
committed by
Florent Vilmart
parent
cac14bce09
commit
848a6cf7ae
@@ -589,6 +589,30 @@ describe('Parse.Query Aggregate testing', () => {
|
|||||||
}).catch(done.fail);
|
}).catch(done.fail);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('distinct null field', (done) => {
|
||||||
|
const options = Object.assign({}, masterKeyOptions, {
|
||||||
|
body: { distinct: 'distinctField' }
|
||||||
|
});
|
||||||
|
const user1 = new Parse.User();
|
||||||
|
user1.setUsername('distinct_1');
|
||||||
|
user1.setPassword('password');
|
||||||
|
user1.set('distinctField', 'one');
|
||||||
|
|
||||||
|
const user2 = new Parse.User();
|
||||||
|
user2.setUsername('distinct_2');
|
||||||
|
user2.setPassword('password');
|
||||||
|
user2.set('distinctField', null);
|
||||||
|
user1.signUp().then(() => {
|
||||||
|
return user2.signUp();
|
||||||
|
}).then(() => {
|
||||||
|
return rp.get(Parse.serverURL + '/aggregate/_User', options);
|
||||||
|
}).then((resp) => {
|
||||||
|
expect(resp.results.length).toEqual(1);
|
||||||
|
expect(resp.results).toEqual(['one']);
|
||||||
|
done();
|
||||||
|
}).catch(done.fail);
|
||||||
|
});
|
||||||
|
|
||||||
it('does not return sensitive hidden properties', (done) => {
|
it('does not return sensitive hidden properties', (done) => {
|
||||||
const options = Object.assign({}, masterKeyOptions, {
|
const options = Object.assign({}, masterKeyOptions, {
|
||||||
body: {
|
body: {
|
||||||
|
|||||||
@@ -511,13 +511,16 @@ export class MongoStorageAdapter implements StorageAdapter {
|
|||||||
}
|
}
|
||||||
return this._adaptiveCollection(className)
|
return this._adaptiveCollection(className)
|
||||||
.then(collection => collection.distinct(fieldName, transformWhere(className, query, schema)))
|
.then(collection => collection.distinct(fieldName, transformWhere(className, query, schema)))
|
||||||
.then(objects => objects.map(object => {
|
.then(objects => {
|
||||||
if (isPointerField) {
|
objects = objects.filter((obj) => obj != null);
|
||||||
const field = fieldName.substring(3);
|
return objects.map(object => {
|
||||||
return transformPointerString(schema, field, object);
|
if (isPointerField) {
|
||||||
}
|
const field = fieldName.substring(3);
|
||||||
return mongoObjectToParseObject(className, object, schema);
|
return transformPointerString(schema, field, object);
|
||||||
}));
|
}
|
||||||
|
return mongoObjectToParseObject(className, object, schema);
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
aggregate(className: string, schema: any, pipeline: any, readPreference: ?string) {
|
aggregate(className: string, schema: any, pipeline: any, readPreference: ?string) {
|
||||||
|
|||||||
@@ -1464,7 +1464,8 @@ export class PostgresStorageAdapter implements StorageAdapter {
|
|||||||
debug('distinct', className, query);
|
debug('distinct', className, query);
|
||||||
let field = fieldName;
|
let field = fieldName;
|
||||||
let column = fieldName;
|
let column = fieldName;
|
||||||
if (fieldName.indexOf('.') >= 0) {
|
const isNested = fieldName.indexOf('.') >= 0;
|
||||||
|
if (isNested) {
|
||||||
field = transformDotFieldToComponents(fieldName).join('->');
|
field = transformDotFieldToComponents(fieldName).join('->');
|
||||||
column = fieldName.split('.')[0];
|
column = fieldName.split('.')[0];
|
||||||
}
|
}
|
||||||
@@ -1480,7 +1481,10 @@ export class PostgresStorageAdapter implements StorageAdapter {
|
|||||||
|
|
||||||
const wherePattern = where.pattern.length > 0 ? `WHERE ${where.pattern}` : '';
|
const wherePattern = where.pattern.length > 0 ? `WHERE ${where.pattern}` : '';
|
||||||
const transformer = isArrayField ? 'jsonb_array_elements' : 'ON';
|
const transformer = isArrayField ? 'jsonb_array_elements' : 'ON';
|
||||||
const qs = `SELECT DISTINCT ${transformer}($1:raw) $2:raw FROM $3:name ${wherePattern}`;
|
let qs = `SELECT DISTINCT ${transformer}($1:name) $2:name FROM $3:name ${wherePattern}`;
|
||||||
|
if (isNested) {
|
||||||
|
qs = `SELECT DISTINCT ${transformer}($1:raw) $2:raw FROM $3:name ${wherePattern}`;
|
||||||
|
}
|
||||||
debug(qs, values);
|
debug(qs, values);
|
||||||
return this._client.any(qs, values)
|
return this._client.any(qs, values)
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
@@ -1490,7 +1494,7 @@ export class PostgresStorageAdapter implements StorageAdapter {
|
|||||||
throw error;
|
throw error;
|
||||||
})
|
})
|
||||||
.then((results) => {
|
.then((results) => {
|
||||||
if (fieldName.indexOf('.') === -1) {
|
if (!isNested) {
|
||||||
results = results.filter((object) => object[field] !== null);
|
results = results.filter((object) => object[field] !== null);
|
||||||
return results.map(object => {
|
return results.map(object => {
|
||||||
if (!isPointerField) {
|
if (!isPointerField) {
|
||||||
|
|||||||
Reference in New Issue
Block a user