IP Library Granted Patent US 8,108,415
Granted Patent B2
US 8,108,415 · App. 12/283,194 · Granted Jan 31, 2012

Query transformation

View Patent ↗
Loading inventors, assignments & file history…
Monitor This Case
Get email alerts when status or documents change.
Order Certified Copies
Most orders are placed with the USPTO same day — all within 24 business hours.
Order via The Patent Place →
Pre-filled with this patent's details
Quick Facts
Patent No.
US 8,108,415
App. No.
12/283,194
Granted
Jan 31, 2012
Kind
B2
Abstract

A mechanism is provided for transforming an original database query into a supported database query that can be fully computed by a target database. The original database query comprising a select list including a plurality of expressions, the plurality of expressions having a control break. The plurality of expressions includes an expression that cannot be directly computed by the target database. The mechanism constructs a derived table from the unsupported database query comprising constructing a new select list of the derived table, traversing the plurality of expressions of the select list of the unsupported database query, and adding a GROUP BY expression to the derived table based on the new select list of the derived table. The mechanism constructs the supported database query using the unsupported database query and the derived table.

Claims (91)

1. A method of transforming an unsupported database query into a supported database query that can be fully computed by a target database, the unsupported database query comprising a select list including a plurality of expressions, the plurality of expressions each having a control break, the plurality of expressions including an expression that cannot be directly computed by the target database, the method comprising:

constructing a derived table from the unsupported database query, wherein constructing the derived table comprises:

constructing a new select list of the derived table;

traversing the plurality of expressions of the select list of the unsupported database query and for each of the expressions:

determining a corresponding expression to add to the new select list, wherein determining the corresponding expression to add to the new select list comprises determining an aggregate of the expression and determining a control break of the aggregate;

adding the corresponding expression to the new select list;

adding the control break of the expression to an ordered list of control breaks, wherein the ordered list is ordered from a shortest control break with a fewest number of columns to a longest control break with a highest number of columns; and

when the control break of the aggregate has fewer columns than the longest control break of the order list of control breaks, and the aggregate of the expression is of the form AGG(C 0 ): replacing the expression AGG(C 0 ) OVER (PARTITION BY C 1 , C 2 , . . . , C k ) with an expression of the form AGG(AGG(C 0 )) OVER(PARTITION C 1 , C 2 , . . . , C k ), where each C is a column, where n is a number of columns in the longest control break, and where k is a number of columns in the other control break; and

adding a GROUP BY expression to the derived table based on the new select list of the derived table;

determining the unsupported database query can be transformed into a supported database query, wherein determining the unsupported database query can be transformed into the supported database query comprises determining all control breaks of the unsupported database query are compatible based on the ordered list; and

constructing the supported database query using the unsupported database query and the derived table.

2. The method as claimed in claim 1 , wherein constructing the supported database query comprises:

adding to a select list of the supported database query, expressions of the select list of the unsupported database query with a standard expression referencing the corresponding expression added to the new select list of the derived table; and

replacing a FROM table of the unsupported database query with a reference to the derived table.

3. The method as claimed in claim 1 , further comprising:

for each expression, determining the control break of the expression is not already in the ordered list prior to adding the control break of the expression to the ordered list.

4. The method as claimed in claim 1 , the method further comprising, when the control break of the aggregate of the expression has no columns, and the aggregate of the expression is of the form AVG(C 0 ):

replacing the expression AVG(C 0 ) OVER ( ) with an expression of the form SUM(SUM(C 0 )) OVER( )/SUM(COUNT(C 0 )) OVER( ), where C 0 is a column.

5. The method as claimed in claim 4 , further comprising, when the control break of the aggregate of the expression has one or more columns found in the longest control break in the ordered list, and the aggregate of the expression is of the form AVG(C0):

replacing the expression AVG(C 0 ) OVER (PARTITION BY C 1 , C 2 , . . . , C n )) with an expression of the form SUM(SUM(C 0 ) OVER (PARTITION BY C 1 , C 2 , . . . , C n )) OVER( )/SUM(COUNT(C 0 ) OVER (PARTITION BY C 1 , C 2 , . . . , C n )) OVER( ), where each C is a column and where n is the number of columns in the longest control break.

6. The method as claimed in claim 1 , the method further comprising, when the control break of the aggregate is the same as the longest control break of the order list of control breaks, and the aggregate of the expression is of the form AGG(C 0 ):

replacing the expression AGG(C 0 ) OVER (PARTITION BY C 1 , C 2 , . . . , C n ) with an expression of the form AGG(C 0 ), where each C is a column and where n is the number of columns in the longest control break.

7. The method as claimed in claim 1 , where aggregates of the form AGG comprise one of MIN, MAX, SUB, COUNT.

8. The method as claimed in claim 1 , wherein determining the unsupported database query can be transformed into a supported database query further comprises:

determining a DISTINCT keyword is present in the select list of the unsupported database query;

determining all aggregates of the expressions are eligible for transformation; and

determining simple column references in the select list of the unsupported database query are found in the longest control break of the unsupported database query, when the simple column references are not part of a speciation of one of the aggregates of the unsupported database query.

9. The method as claimed in claim 8 , wherein determining an aggregate is eligible comprises:

determining the aggregate is a report aggregate that has a standard aggregate counterpart.

10. The method as claimed in claim 8 , wherein determining all control breaks are compatible comprises:

determining the longest control break is of the form (C 1 , C 2 , . . . , C n ) and all other control breaks are of the form ( ) or of the form (C 1 , C 2 , . . . , C k ) where 0<=k<=n, where:

each C is a column;

n is the number of columns in the longest control break; and

k is the number of columns in the other control break.

11. A computer program product comprising a computer readable memory having computer readable code embodied therein for use in the execution in a computer of a method of transforming an unsupported database query into a supported database query that can be fully computed by a target database, the unsupported database query comprising a select list including a plurality of expressions, the plurality of expressions each having a control break, the plurality of expressions including an expression that cannot be directly computed by the target database, the computer comprising a processor coupled to the computer storage medium for executing the computer readable code, the method comprising:

constructing a derived table from the unsupported database query, wherein constructing a derived table from the unsupported database query comprises:

constructing a new select list of the derived table;

traversing the plurality of expressions of the select list of the unsupported database query and for each of the expressions:

determining a corresponding expression to add to the new select list, wherein determining the corresponding expression to add to the new select list comprises determining an aggregate of the expression and determining the control break of the aggregate;

adding the corresponding expression to the new select list;

adding the control break of the expression to an ordered list of control breaks, wherein the ordered list is ordered from a shortest control break with a fewest number of columns to a longest control break with a highest number of columns; and

when the control break of the aggregate has fewer columns than the longest control break of the order list of control breaks, and the aggregate of the expression is of the form AGG(C 0 ): replacing the expression AGG(C 0 ) OVER (PARTITION BY C 1 , C 2 , . . . , C k ) with an expression of the form AGG(AGG(C 0 )) OVER (PARTITION C 1 , C 2 , . . . , C k ), where each C is a column, where n is a number of columns in the longest control break, and where k is a number of columns in the other control break; and

adding a GROUP BY expression to the derived table based on the new select list of the derived table;

determining the unsupported database query can be transformed into a supported database query, wherein determining the unsupported database query can be transformed into a supported database query comprises determining all control breaks of the unsupported database query are compatible based on the ordered list; and

constructing the supported database query using the unsupported database query and the derived table.

12. The computer program product as claimed in claim 11 , wherein constructing the supported database query comprises:

adding to a select list of the supported database query, expressions of the select list of the unsupported database query with a standard expression referencing the corresponding expression added to the new select list of the derived table; and

replacing a FROM table of the unsupported database query with a reference to the derived table.

13. The computer program product as claimed in claim 11 , the method further comprising:

when the control break of the aggregate of the expression has no columns, and the aggregate of the expression is of the form AVG(C 0 ), replacing the expression AVG(C 0 ) OVER ( ) with an expression of the form SUM(SUM(C 0 )) OVER( )/SUM(COUNT(C 0 )) OVER( ) where C 0 is a column; and

when the control break of the aggregate of the expression has one or more columns found in the longest control break in the ordered list, and the aggregate of the expression is of the form AVG(C0), replacing the expression AVG(C 0 ) OVER (PARTITION BY C 1 , C 2 , . . . , C n )) with an expression of the form SUM(SUM(C 0 ) OVER (PARTITION BY C 1 , C 2 , . . . , C n )) OVER( )SUM(COUNT(C 0 ) OVER (PARTITION BY C 1 , C 2 , . . . , C n ))OVER( ), where each C is a column and where n is the number of columns in the longest control break.

14. The computer program product as claimed in claim 11 , the method further comprising:

when the control break of the aggregate is the same as a longest control break of the order list of control breaks, and the aggregate of the expression is of the form AGG(C 0 ), replacing the expression AGG(C 0 ) OVER (PARTITION BY C 1 , C 2 , . . . , C n ) with an expression of the form AGG(C 0 ), where each C is a column and where n is the number of columns in the longest control break.

15. The computer program product as claimed in claim 11 , wherein determining the unsupported database query can be transformed into a supported database query further comprises:

determining a DISTINCT keyword is present in the select list of the unsupported database query;

determining all aggregates of the expressions are eligible for transformation; and

determining simple column references in the select list of the unsupported database query are found in the longest control break of the unsupported database query, when the simple column references are not part of a speciation of one of the aggregates of the unsupported database query,

wherein determining an aggregate is eligible comprises determining the aggregate is a report aggregate that has a standard aggregate counterpart; and

wherein determining all control breaks are compatible comprises:

determining the longest control break is of the form (C 1 , C 2 , . . . , C n ) and all other control breaks are of the form ( ) or of the form (C 1 , C 2 , . . . , C k ) where 0<=k<=n, where:

each C is a column;

n is the number of columns in the longest control break; and

k is the number of columns in the other control break.

16. A computer comprising:

a processor; and

a computer readable memory having computer readable code embodied therein for use in the execution by the processor of a method of transforming an unsupported database query into a supported database query that can be fully computed by a target database, the unsupported database query comprising a select list including a plurality of expressions, the plurality of expressions each having a control break, the plurality of expressions including an expression that cannot be directly computed by the target database, the method comprising:

constructing a derived table from the unsupported database query, wherein constructing a derived table from the unsupported database query comprises:

constructing a new select list of the derived table;

traversing the plurality of expressions of the select list of the unsupported database query and for each of the expressions:

determining a corresponding expression to add to the new select list, wherein determining the corresponding expression to add to the new select list comprises determining an aggregate of the expression and determining the control break of the aggregate;

adding the corresponding expression to the new select list;

adding the control break of the expression to an ordered list of control breaks, wherein the ordered list is ordered from a shortest control break with a fewest number of columns to a longest control break with a highest number of columns;

when the control break of the aggregate has fewer columns than the longest control break of the order list of control breaks, and the aggregate of the expression is of the form AGG(C 0 ): replacing the expression AGG(C 0 ) OVER (PARTITION BY C 1 , C 2 , . . . , C k ) with an expression of the form AGG(AGG(C 0 )) OVER (PARTITION C 1 , C 2 , . . . , C k ), where each C is a column, where n is a number of columns in the longest control break, and where k is a number of columns in the other control break; and

adding a GROUP BY expression to the derived table based on the new select list of the derived table;

determining the unsupported database query can be transformed into a supported database query, wherein determining the unsupported database query can be transformed into a supported database query comprises determining all control breaks of the unsupported database query are compatible based on the ordered list; and

constructing the supported database query using the unsupported database query and the derived table.

17. The computer as claimed in claim 16 , the method further comprising:

when the control break of the aggregate of the expression has no columns, and the aggregate of the expression is of the form AVG(C 0 ), replacing the expression AVG(C 0 ) OVER ( ) with an expression of the form SUM(SUM(C 0 )) OVER( )/SUM(COUNT(C 0 )) OVER( ) where C 0 is a column; and

when the control break of the aggregate of the expression has one or more columns found in the longest control break in the ordered list, and the aggregate of the expression is of the form AVG(C0), replacing the expression AVG(C 0 ) OVER (PARTITION BY C 1 , C 2 , . . . , C n )) with an expression of the form SUM(SUM(C 0 ) OVER (PARTITION BY C 1 , C 2 , . . . , C n )) OVER( )SUM(COUNT(C 0 ) OVER (PARTITION BY C 1 , C 2 , . . . , C n ))OVER( ) where each C is a column and where n is the number of columns in the longest control break.

18. The computer as claimed in claim 16 , the method further comprising:

when the control break of the aggregate is the same as the longest control break of the order list of control breaks, and the aggregate of the expression is of the form AGG(C 0 ), replacing the expression AGG(C 0 ) OVER (PARTITION BY C 1 , C 2 , . . . , C n ) with an expression of the form AGG(C 0 ), where each C is a column and where n is the number of columns in the longest control break.

19. The computer as claimed in claim 16 , wherein determining that the unsupported database query can be transformed into a supported database query further comprises:

determining a DISTINCT keyword is present in the select list of the unsupported database query;

determining all aggregates of the expressions are eligible for transformation; and

determining simple column references in the select list of the unsupported database query are found in the longest control break of the unsupported database query, when the simple column references are not part of a speciation of one of the aggregates of the unsupported database query,

wherein determining an aggregate is eligible comprises determining that the aggregate is a report aggregate that has a standard aggregate counterpart; and

wherein determining all control breaks are compatible comprises:

determining the longest control break is of the form (C 1 , C 2 , . . . , C n ) and all other control breaks are of the form ( ) or of the form (C 1 , C 2 , . . . , C k ) where 0<=k<=n, where:

each C is a column;

n is the number of columns in the longest control break; and

k is the number of columns in the other control break.

Assignments (2)
CHANGE OF NAME Recorded Aug 26, 2014
From: SAP AG
To: SAP SE
Reel/Frame 033625/0334 →
ASSIGNMENT OF ASSIGNOR'S INTEREST Recorded Jul 12, 2012
From: INTERNATIONAL BUSINESS MACHINES CORPORATION
To: SAP AG
Reel/Frame 028540/0522 →