PG: Support for multiple projection in aggregate (#4469)

This commit is contained in:
Diamond Lewis
2017-12-29 11:39:16 -06:00
committed by Vitaly Tomilov
parent 6ba939994d
commit 04f8673edd
2 changed files with 38 additions and 19 deletions

View File

@@ -254,7 +254,8 @@ describe('Parse.Query Aggregate testing', () => {
rp.get(Parse.serverURL + '/aggregate/TestObject', options) rp.get(Parse.serverURL + '/aggregate/TestObject', options)
.then((resp) => { .then((resp) => {
resp.results.forEach((result) => { resp.results.forEach((result) => {
expect(result.name !== undefined).toBe(true); expect(result.objectId).not.toBe(undefined);
expect(result.name).not.toBe(undefined);
expect(result.sender).toBe(undefined); expect(result.sender).toBe(undefined);
expect(result.size).toBe(undefined); expect(result.size).toBe(undefined);
expect(result.score).toBe(undefined); expect(result.score).toBe(undefined);
@@ -263,6 +264,25 @@ describe('Parse.Query Aggregate testing', () => {
}).catch(done.fail); }).catch(done.fail);
}); });
it('multiple project query', (done) => {
const options = Object.assign({}, masterKeyOptions, {
body: {
project: { name: 1, score: 1, sender: 1 },
}
});
rp.get(Parse.serverURL + '/aggregate/TestObject', options)
.then((resp) => {
resp.results.forEach((result) => {
expect(result.objectId).not.toBe(undefined);
expect(result.name).not.toBe(undefined);
expect(result.score).not.toBe(undefined);
expect(result.sender).not.toBe(undefined);
expect(result.size).toBe(undefined);
});
done();
}).catch(done.fail);
});
it('project with group query', (done) => { it('project with group query', (done) => {
const options = Object.assign({}, masterKeyOptions, { const options = Object.assign({}, masterKeyOptions, {
body: { body: {

View File

@@ -729,9 +729,9 @@ export class PostgresStorageAdapter {
yield self._ensureSchemaCollectionExists(t); yield self._ensureSchemaCollectionExists(t);
yield t.none(qs, values); yield t.none(qs, values);
} catch(error) { } catch(error) {
if (error.code !== PostgresDuplicateRelationError) { if (error.code !== PostgresDuplicateRelationError) {
throw error; throw error;
} }
// ELSE: Table already exists, must have been created by a different request. Ignore the error. // ELSE: Table already exists, must have been created by a different request. Ignore the error.
} }
yield t.tx('create-table-tx', tx => { yield t.tx('create-table-tx', tx => {
@@ -755,14 +755,14 @@ export class PostgresStorageAdapter {
postgresType: parseTypeToPostgresType(type) postgresType: parseTypeToPostgresType(type)
}); });
} catch(error) { } catch(error) {
if (error.code === PostgresRelationDoesNotExistError) { if (error.code === PostgresRelationDoesNotExistError) {
return yield self.createClass(className, {fields: {[fieldName]: type}}, t); return yield self.createClass(className, {fields: {[fieldName]: type}}, t);
} }
if (error.code !== PostgresDuplicateColumnError) { if (error.code !== PostgresDuplicateColumnError) {
throw error; throw error;
} }
// Column already exists, created by other request. Carry on to see if it's the right type. // Column already exists, created by other request. Carry on to see if it's the right type.
}; }
} else { } else {
yield t.none('CREATE TABLE IF NOT EXISTS $<joinTable:name> ("relatedId" varChar(120), "owningId" varChar(120), PRIMARY KEY("relatedId", "owningId") )', {joinTable: `_Join:${fieldName}:${className}`}); yield t.none('CREATE TABLE IF NOT EXISTS $<joinTable:name> ("relatedId" varChar(120), "owningId" varChar(120), PRIMARY KEY("relatedId", "owningId") )', {joinTable: `_Join:${fieldName}:${className}`});
} }
@@ -811,8 +811,8 @@ export class PostgresStorageAdapter {
// No _SCHEMA collection. Don't delete anything. // No _SCHEMA collection. Don't delete anything.
} }
}).then(() => { }).then(() => {
debug(`deleteAllClasses done in ${new Date().getTime() - now}`); debug(`deleteAllClasses done in ${new Date().getTime() - now}`);
}); });
} }
// Remove the column and all the data. For Relations, the _Join collection is handled // Remove the column and all the data. For Relations, the _Join collection is handled
@@ -1500,7 +1500,6 @@ export class PostgresStorageAdapter {
columns.push(`AVG(${transformAggregateField(value.$avg)}) AS "${field}"`); columns.push(`AVG(${transformAggregateField(value.$avg)}) AS "${field}"`);
} }
} }
columns.join();
} else { } else {
columns.push('*'); columns.push('*');
} }
@@ -1546,7 +1545,7 @@ export class PostgresStorageAdapter {
} }
} }
const qs = `SELECT ${columns} FROM $1:name ${wherePattern} ${sortPattern} ${limitPattern} ${skipPattern} ${groupPattern}`; const qs = `SELECT ${columns.join()} FROM $1:name ${wherePattern} ${sortPattern} ${limitPattern} ${skipPattern} ${groupPattern}`;
debug(qs, values); debug(qs, values);
return this._client.map(qs, values, a => this.postgresObjectToParseObject(className, a, schema)) return this._client.map(qs, values, a => this.postgresObjectToParseObject(className, a, schema))
.then(results => { .then(results => {