Ordering of filters in DataObjectQuery

When building a data object query, you can add Filters to it and then pass it into a DOS load. However, recently we were wondering if the ordering of the filters matter. What if we had a list of filters constructed like this:

DataObjectQuery queryExample = dataObjectQuery(types(ExampleMetadataConstants.TYPE),
				stringEquals(ExampleMetadataConstants.ID_A.toString(), testA),
				stringEquals(ExampleMetadataConstants.ID_B.toString(), testB), 
				dateCompare(ExampleMetadataConstants.DATE.toString(), Operator.LESS_THAN_OR_EQUAL_TO, LocalDate.now()),
				orderBy(ExampleMetadataConstants.DATE, true));

vs…

DataObjectQuery queryExample = dataObjectQuery(types(ExampleMetadataConstants.TYPE),
				orderBy(ExampleMetadataConstants.DATE, true),
				stringEquals(ExampleMetadataConstants.ID_A.toString(), testA),
				stringEquals(ExampleMetadataConstants.ID_B.toString(), testB), 
				dateCompare(ExampleMetadataConstants.DATE.toString(), Operator.LESS_THAN_OR_EQUAL_TO, LocalDate.now()));

Again this is just something we were wondering about since in SQL the orderBy predicate usually acts last (and so has to put last) - i.e., select A from B order by C

No, the order does not matter. LEAF will identify the SortingDirective returned by orderBy and apply it correctly when generating the query for the underlying database implementation. Technically the order in which filters (not sorting directives) are added to a DataObjectQuery may affect the order in which they are evaluated during the execution of the query, but it should not affect the results of the query.

Kerwin,

Good to know that.

Thanks