Patent ID: 8166020

Claim:
A query generator for generating a query that returns a result set comprising data retrieved from a database and data returned by an analytic function that operates on at least a portion of the retrieved data, the result set being arranged as a table having a plurality of rows, wherein the query generator comprises a processor to execute computer program instructions, a memory to store computer program instructions executable by the processor and data for processing by the processor, and computer program instructions stored in the memory and executable to configure the query generator to: a) receive, at the query generator, an input query indicating the data for retrieval from the database, which of these indicated data are for operation on by the analytic function, and the identity of the analytic function; b) analyze, at the query generator, the input query to ascertain whether erroneous results would be produced by the analytic function based on a join configuration and corresponding join metadata of the query because the input query retrieves a data item that will be repeated across one or more rows of the result set and that is operated on by the analytic function, or because the input query calculates an aggregation result from a plurality of data items, the aggregation result that will be repeated across one or more rows of the result set and that is operated on by the analytic function; and c) modify, at the query generator, the input query by inserting a partition clause into the input query to form a modified query that includes at least one more partition clause than the input query, to cause the database to split the retrieved data into a number of partitions such that the data item or aggregation result is present only once in each partition, before operating on the retrieved data with the analytic function, when erroneous results would be produced by the analytic function because the input query retrieves a data item that will be repeated across one or more rows of the result set and that is operated on by the analytic function, or because the input query calculates an aggregation result from a plurality of data items, the aggregation result that will be repeated across one or more rows of the result set and that is operated on by the analytic function.