Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LDEV-5031 #2403

Merged
merged 2 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 65 additions & 65 deletions core/src/main/java/lucee/runtime/db/QoQ.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public QueryImpl execute(PageContext pc, SQL sql, Selects selects, int maxrows)
/**
* Order the rows in a query
*
* @param target Query to order
* @param target Query to order
* @param columns Column expressions to order on
* @param isUnion Is this a union
* @param sql
Expand All @@ -188,16 +188,16 @@ private static void order(PageContext pc, QueryImpl target, Expression[] columns
* Process a single select statement. If this is a union, append it to the incoming "previous" Query
* and return the new, combined query with all rows
*
* @param pc PageContext
* @param select Select instance
* @param source Source query to pull data from
* @param previous Previous query in case of union. May be empty if this is the first select in the
* union
* @param maxrows max rows from cfquery tag. Not necessarily the same as TOP
* @param sql SQL object
* @param pc PageContext
* @param select Select instance
* @param source Source query to pull data from
* @param previous Previous query in case of union. May be empty if this is the first select in the
* union
* @param maxrows max rows from cfquery tag. Not necessarily the same as TOP
* @param sql SQL object
* @param hasOrders Is this overall Selects instance ordered? This affects whether we can optimize
* maxrows or not
* @param isUnion Is this select part of a union of several selects
* maxrows or not
* @param isUnion Is this select part of a union of several selects
* @return
* @throws PageException
*/
Expand Down Expand Up @@ -273,7 +273,7 @@ else if (isUnion && select.isUnionDistinct()) {
* Combine two queries while retaining all rows.
*
* @param previous Query from previous select to union
* @param target New query to add into the previous
* @param target New query to add into the previous
* @return Combined Query with potential duplicate rows
* @throws PageException
*/
Expand Down Expand Up @@ -306,10 +306,10 @@ private QueryImpl doUnionAll(QueryImpl previous, QueryImpl target, SQL sql) thro
/**
* Combine two queries while removing duplicate rows
*
* @param pc PageContext
* @param pc PageContext
* @param previous Query from previous select to union
* @param target New query to add into the previous
* @param sql SQL instance
* @param target New query to add into the previous
* @param sql SQL instance
* @return Combined Query with no duplicate rows
* @throws PageException
*/
Expand All @@ -332,7 +332,7 @@ private QueryImpl doUnionDistinct(PageContext pc, QueryImpl previous, QueryImpl
}

// Initialize our object to track the partitions
QueryPartitions queryPartitions = new QueryPartitions(sql, selectExpressions, new Expression[0], newTarget, new HashSet<Key>(), this);
QueryPartitions queryPartitions = new QueryPartitions(sql, selectExpressions, new Expression[0], newTarget, new HashSet<Key>(), this, false);

// Add in all the rows from our previous work
getStream(previous).forEach(throwingIntConsumer(row -> {
Expand Down Expand Up @@ -360,17 +360,17 @@ private QueryImpl doUnionDistinct(PageContext pc, QueryImpl previous, QueryImpl
/**
* Process a single select that is not partitioned (grouped or distinct)
*
* @param pc PageContext
* @param select Select instance
* @param source Query we're select from
* @param target Query object we're adding rows into. (passed back by reference)
* @param maxrows Max rows from cfquery.
* @param pc PageContext
* @param select Select instance
* @param source Query we're select from
* @param target Query object we're adding rows into. (passed back by reference)
* @param maxrows Max rows from cfquery.
* @param sql
* @param hasOrders Is this overall query ordered?
* @param isUnion Is this part of a union?
* @param hasOrders Is this overall query ordered?
* @param isUnion Is this part of a union?
* @param trgColumns Lookup array of column
* @param trgValues Lookup array of expressions
* @param headers Select lists
* @param trgValues Lookup array of expressions
* @param headers Select lists
* @throws PageException
*/
private void executeSingleNonPartitioned(PageContext pc, Select select, QueryImpl source, QueryImpl target, int maxrows, SQL sql, boolean hasOrders, boolean isUnion,
Expand Down Expand Up @@ -450,17 +450,17 @@ public static Stream<Map.Entry<String, QueryImpl>> getStream(QueryPartitions que
/**
* Process a single select that is partitioned (grouped)
*
* @param pc PageContext
* @param select Select instance
* @param source Query we're selecting from
* @param target Query object we're adding rows into. (passed back by reference)
* @param pc PageContext
* @param select Select instance
* @param source Query we're selecting from
* @param target Query object we're adding rows into. (passed back by reference)
* @param maxrows
* @param sql
* @param hasOrders Is this overall query ordered?
* @param isUnion Is this part of a union?
* @param hasOrders Is this overall query ordered?
* @param isUnion Is this part of a union?
* @param trgColumns Lookup array of column
* @param trgValues Lookup array of expressions
* @param headers select columns
* @param trgValues Lookup array of expressions
* @param headers select columns
* @throws PageException
*/
private void executeSinglePartitioned(PageContext pc, Select select, QueryImpl source, QueryImpl target, int maxrows, SQL sql, boolean hasOrders, boolean isUnion,
Expand All @@ -482,7 +482,7 @@ private void executeSinglePartitioned(PageContext pc, Select select, QueryImpl s

Operation where = select.getWhere();
// Initialize object to track our partitioned data
QueryPartitions queryPartitions = new QueryPartitions(sql, select.getSelects(), select.getGroupbys(), target, select.getAdditionalColumns(), this);
QueryPartitions queryPartitions = new QueryPartitions(sql, select.getSelects(), select.getGroupbys(), target, select.getAdditionalColumns(), this, hasAggregateSelect);

IntStream stream = getStream(source);
if (where != null) {
Expand Down Expand Up @@ -600,7 +600,7 @@ public Object getValue(PageContext pc, SQL sql, QueryImpl querySource, int row,
}

/**
* @param pc Page Context of the Request
* @param pc Page Context of the Request
* @param table ZQLQuery
* @return Query
* @throws PageException
Expand All @@ -614,8 +614,8 @@ private QueryImpl getSingleTable(PageContext pc, Column table) throws PageExcept
*
* @param sql
* @param source Query Result
* @param exp expression to execute
* @param row current row of resultset
* @param exp expression to execute
* @param row current row of resultset
* @return result
* @throws PageException
*/
Expand Down Expand Up @@ -1091,9 +1091,9 @@ private Object executeBracked(PageContext pc, SQL sql, QueryImpl source, Bracket
* execute an and operation
*
* @param sql
* @param source QueryResult to execute on it
* @param source QueryResult to execute on it
* @param expression
* @param row row of resultset to execute
* @param row row of resultset to execute
* @return result
* @throws PageException
*/
Expand Down Expand Up @@ -1121,9 +1121,9 @@ private Object executeXor(PageContext pc, SQL sql, QueryImpl source, Operation2
* execute an equal operation
*
* @param sql
* @param source QueryResult to execute on it
* @param source QueryResult to execute on it
* @param expression
* @param row row of resultset to execute
* @param row row of resultset to execute
* @return result
* @throws PageException
*/
Expand All @@ -1136,9 +1136,9 @@ private Object executeEQ(PageContext pc, SQL sql, QueryImpl source, Operation2 e
* execute a not equal operation
*
* @param sql
* @param source QueryResult to execute on it
* @param source QueryResult to execute on it
* @param expression
* @param row row of resultset to execute
* @param row row of resultset to execute
* @return result
* @throws PageException
*/
Expand All @@ -1151,9 +1151,9 @@ private Object executeNEQ(PageContext pc, SQL sql, QueryImpl source, Operation2
* execute a less than operation
*
* @param sql
* @param source QueryResult to execute on it
* @param source QueryResult to execute on it
* @param expression
* @param row row of resultset to execute
* @param row row of resultset to execute
* @return result
* @throws PageException
*/
Expand All @@ -1166,9 +1166,9 @@ private Object executeLT(PageContext pc, SQL sql, QueryImpl source, Operation2 e
* execute a less than or equal operation
*
* @param sql
* @param source QueryResult to execute on it
* @param source QueryResult to execute on it
* @param expression
* @param row row of resultset to execute
* @param row row of resultset to execute
* @return result
* @throws PageException
*/
Expand All @@ -1181,9 +1181,9 @@ private Object executeLTE(PageContext pc, SQL sql, QueryImpl source, Operation2
* execute a greater than operation
*
* @param sql
* @param source QueryResult to execute on it
* @param source QueryResult to execute on it
* @param expression
* @param row row of resultset to execute
* @param row row of resultset to execute
* @return result
* @throws PageException
*/
Expand All @@ -1196,9 +1196,9 @@ private Object executeGT(PageContext pc, SQL sql, QueryImpl source, Operation2 e
* execute a greater than or equal operation
*
* @param sql
* @param source QueryResult to execute on it
* @param source QueryResult to execute on it
* @param expression
* @param row row of resultset to execute
* @param row row of resultset to execute
* @return result
* @throws PageException
*/
Expand All @@ -1213,7 +1213,7 @@ private Object executeGTE(PageContext pc, SQL sql, QueryImpl source, Operation2
* @param sql
* @param source QueryResult to execute on it
* @param op
* @param row row of resultset to execute
* @param row row of resultset to execute
* @return result
* @throws PageException
*/
Expand Down Expand Up @@ -1244,9 +1244,9 @@ private Object executeMod(PageContext pc, SQL sql, QueryImpl source, Operation2
* execute a greater than or equal operation
*
* @param sql
* @param source QueryResult to execute on it
* @param source QueryResult to execute on it
* @param expression
* @param row row of resultset to execute
* @param row row of resultset to execute
* @return result
* @throws PageException
*/
Expand Down Expand Up @@ -1291,9 +1291,9 @@ private Integer castForMathInt(Object value) throws PageException {
* execute a minus operation
*
* @param sql
* @param source QueryResult to execute on it
* @param source QueryResult to execute on it
* @param expression
* @param row row of resultset to execute
* @param row row of resultset to execute
* @return result
* @throws PageException
*/
Expand All @@ -1314,9 +1314,9 @@ private Object executeMinus(PageContext pc, SQL sql, QueryImpl source, Operation
* execute a divide operation
*
* @param sql
* @param source QueryResult to execute on it
* @param source QueryResult to execute on it
* @param expression
* @param row row of resultset to execute
* @param row row of resultset to execute
* @return result
* @throws PageException
*/
Expand All @@ -1342,9 +1342,9 @@ private Object executeDivide(PageContext pc, SQL sql, QueryImpl source, Operatio
* execute a multiply operation
*
* @param sql
* @param source QueryResult to execute on it
* @param source QueryResult to execute on it
* @param expression
* @param row row of resultset to execute
* @param row row of resultset to execute
* @return result
* @throws PageException
*/
Expand All @@ -1365,9 +1365,9 @@ private Object executeMultiply(PageContext pc, SQL sql, QueryImpl source, Operat
* execute a bitwise operation
*
* @param sql
* @param source QueryResult to execute on it
* @param source QueryResult to execute on it
* @param expression
* @param row row of resultset to execute
* @param row row of resultset to execute
* @return result
* @throws PageException
*/
Expand All @@ -1388,9 +1388,9 @@ private Object executeBitwise(PageContext pc, SQL sql, QueryImpl source, Operati
* execute a plus operation
*
* @param sql
* @param source QueryResult to execute on it
* @param source QueryResult to execute on it
* @param expression
* @param row row of resultset to execute
* @param row row of resultset to execute
* @return result
* @throws PageException
*/
Expand Down Expand Up @@ -1430,9 +1430,9 @@ private Object executePlus(PageContext pc, SQL sql, QueryImpl source, Operation2
* execute a between operation
*
* @param sql
* @param source QueryResult to execute on it
* @param source QueryResult to execute on it
* @param expression
* @param row row of resultset to execute
* @param row row of resultset to execute
* @return result
* @throws PageException
*/
Expand Down
31 changes: 18 additions & 13 deletions core/src/main/java/lucee/runtime/sql/QueryPartitions.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,15 @@ public class QueryPartitions {
* @param qoQ
* @throws PageException
*/
public QueryPartitions(SQL sql, Expression[] columns, Expression[] groupbys, QueryImpl target, Set<Key> additionalColumns, QoQ qoQ) throws PageException {
public QueryPartitions(SQL sql, Expression[] columns, Expression[] groupbys, QueryImpl target, Set<Key> additionalColumns, QoQ qoQ, boolean hasAggregateSelect)
throws PageException {
this.sql = sql;
this.qoQ = qoQ;
this.columns = columns;
this.groupbys = groupbys;
// This happens when using distinct with no group by
// Just assume we're grouping on the entire select list
if (this.groupbys.length == 0) {
if (this.groupbys.length == 0 && !hasAggregateSelect) {
ArrayList<Expression> temp = new ArrayList<Expression>();
for (Expression col: columns) {
if (!(col instanceof OperationAggregate)) {
Expand Down Expand Up @@ -118,11 +119,12 @@ public void addEmptyPartition(QueryImpl source, QueryImpl target) throws PageExc
* Call this to add a single row to the proper partition finaizedColumnVals is true when all data in
* the source Query is fully realized and there are no expressions left to evaluate
*
* @param pc PageContext
* @param source Source query to get data from
* @param row Row to get data from
* @param pc PageContext
* @param source Source query to get data from
* @param row Row to get data from
* @param finalizedColumnVals If we're adding finalized data, just copy it across. Easy. This
* applies when distincting a result set after it's already been processed
* applies when distincting a result set after it's already been
* processed
* @throws PageException
*/
public void addRow(PageContext pc, QueryImpl source, int row, boolean finalizedColumnVals) throws PageException {
Expand Down Expand Up @@ -181,11 +183,13 @@ else if (columns[cell] instanceof ColumnExpression) {
/**
* Generate a unique string that represents the column data being grouped on
*
* @param pc PageContext
* @param source QueryImpl to get data from. Note, operations have not yet been processed
* @param row Row to get data from
* @param pc PageContext
* @param source QueryImpl to get data from. Note, operations have not yet been
* processed
* @param row Row to get data from
* @param finalizedColumnVals If we're adding finalized data, just copy it across. Easy. This
* applies when distincting a result set after it's already been processed
* applies when distincting a result set after it's already been
* processed
* @return unique string
* @throws PageException
*/
Expand Down Expand Up @@ -267,10 +271,11 @@ public Query[] getPartitionArray() {
* Create new Query for a partition. Needs to have all ColumnExpressions in the final select as well
* as any additional columns required for operation expressions
*
* @param target Query for target data (for column refernces)
* @param source source query we're getting data from
* @param target Query for target data (for column refernces)
* @param source source query we're getting data from
* @param finalizedColumnVals If we're adding finalized data, just copy it across. Easy. This
* applies when distincting a result set after it's already been processed
* applies when distincting a result set after it's already been
* processed
* @return Empty Query with all the needed columns
* @throws PageException
*/
Expand Down
Loading
Loading