Skip to content

Commit

Permalink
fix(pat-5034): use field name in selection set for testing order-by i…
Browse files Browse the repository at this point in the history
…nclusion
  • Loading branch information
Ajith Mascarenhas committed Dec 19, 2023
1 parent 254709e commit 796aeb8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
4 changes: 2 additions & 2 deletions static/nodejs/src/backends/dpm_agent/dpm_agent_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,12 @@ export function makeDpmAgentQuery(query: Table): DpmAgentQuery {
}

// Process any groupings defined in selection or orderBy.
const selectionMap = new Set<FieldExpr>(selection ?? []);
const selectionSet = new Set<string>((selection ?? []).map((x) => x.name));
const expandedSelection = [
...(selection ?? []),
...(orderBy ?? [])
.map((x: Ordering) => x[0])
.filter((x) => !selectionMap.has(x)),
.filter((x) => !selectionSet.has(x.name)),
];
if (
expandedSelection.findIndex(
Expand Down
41 changes: 28 additions & 13 deletions static/nodejs/test/dpm_query_builder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,9 @@ describe('makeDpmAgentQuery', () => {

test('returns expected Query message for a query with selections, filter, aggregations', () => {
const query = table
.select('id', 'name', price.avg().as('avgPrice'))
.select('id', createdOn.day, price.avg().as('avgPrice'))
.filter(name.like('%bah%').and(createdOn.before(new Date('2023-01-01'))))
.orderBy(['avgPrice', 'DESC'], [name, 'ASC'], [createdOn, 'ASC']) // Note that createdOn is not in the selection.
.orderBy(['avgPrice', 'DESC'], [createdOn.day, 'ASC'], [name, 'ASC']) // Note that `name` is not in the selection.
.limit(10);
const dpmQuery = makeDpmAgentQuery(query);
const want: DpmAgentQuery.AsObject = {
Expand All @@ -223,9 +223,14 @@ describe('makeDpmAgentQuery', () => {
},
{
argument: {
field: {
fieldname: 'name',
tablename: '',
derived: {
op: DpmAgentQuery.DerivedExpression.ProjectionOperator.DAY,
argument: {
field: {
fieldname: 'created_on',
tablename: '',
},
},
},
},
alias: '',
Expand Down Expand Up @@ -313,14 +318,19 @@ describe('makeDpmAgentQuery', () => {
},
},
{
field: {
fieldname: 'name',
tablename: '',
derived: {
op: DpmAgentQuery.DerivedExpression.ProjectionOperator.DAY,
argument: {
field: {
fieldname: 'created_on',
tablename: '',
},
},
},
},
{
field: {
fieldname: 'created_on',
fieldname: 'name',
tablename: '',
},
},
Expand All @@ -342,17 +352,22 @@ describe('makeDpmAgentQuery', () => {
},
{
argument: {
field: {
fieldname: 'name',
tablename: '',
derived: {
op: DpmAgentQuery.DerivedExpression.ProjectionOperator.DAY,
argument: {
field: {
fieldname: 'created_on',
tablename: '',
},
},
},
},
direction: DpmAgentQuery.OrderByExpression.Direction.ASC,
},
{
argument: {
field: {
fieldname: 'created_on',
fieldname: 'name',
tablename: '',
},
},
Expand Down

0 comments on commit 796aeb8

Please sign in to comment.