mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 05:01:07 +00:00
CE-1460 Construct a new, clean QueryJoin object for the second Aggregate call (as JoinsContext changes the one it takes in during the first call, leading to different join conditions being in place, causing second query to potentially fail)
This commit is contained in:
@ -136,29 +136,11 @@ public class ColumnStatsStep implements BackendStep
|
|||||||
filter = new QQueryFilter();
|
filter = new QQueryFilter();
|
||||||
}
|
}
|
||||||
|
|
||||||
QueryJoin queryJoin = null;
|
QTableMetaData table = QContext.getQInstance().getTable(tableName);
|
||||||
QTableMetaData table = QContext.getQInstance().getTable(tableName);
|
|
||||||
QFieldMetaData field = null;
|
FieldAndQueryJoin fieldAndQueryJoin = getFieldAndQueryJoin(table, fieldName);
|
||||||
if(fieldName.contains("."))
|
QFieldMetaData field = fieldAndQueryJoin.field();
|
||||||
{
|
QueryJoin queryJoin = fieldAndQueryJoin.queryJoin();
|
||||||
String[] parts = fieldName.split("\\.", 2);
|
|
||||||
for(ExposedJoin exposedJoin : CollectionUtils.nonNullList(table.getExposedJoins()))
|
|
||||||
{
|
|
||||||
if(exposedJoin.getJoinTable().equals(parts[0]))
|
|
||||||
{
|
|
||||||
field = QContext.getQInstance().getTable(exposedJoin.getJoinTable()).getField(parts[1]);
|
|
||||||
queryJoin = new QueryJoin()
|
|
||||||
.withJoinTable(exposedJoin.getJoinTable())
|
|
||||||
.withSelect(true)
|
|
||||||
.withType(QueryJoin.Type.INNER);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
field = table.getField(fieldName);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(field == null)
|
if(field == null)
|
||||||
{
|
{
|
||||||
@ -213,7 +195,7 @@ public class ColumnStatsStep implements BackendStep
|
|||||||
filter.withOrderBy(new QFilterOrderByAggregate(aggregate, false));
|
filter.withOrderBy(new QFilterOrderByAggregate(aggregate, false));
|
||||||
filter.withOrderBy(new QFilterOrderByGroupBy(groupBy));
|
filter.withOrderBy(new QFilterOrderByGroupBy(groupBy));
|
||||||
|
|
||||||
Integer limit = 1000; // too big?
|
Integer limit = 1000;
|
||||||
AggregateInput aggregateInput = new AggregateInput();
|
AggregateInput aggregateInput = new AggregateInput();
|
||||||
aggregateInput.withAggregate(aggregate);
|
aggregateInput.withAggregate(aggregate);
|
||||||
aggregateInput.withGroupBy(groupBy);
|
aggregateInput.withGroupBy(groupBy);
|
||||||
@ -223,7 +205,11 @@ public class ColumnStatsStep implements BackendStep
|
|||||||
|
|
||||||
if(queryJoin != null)
|
if(queryJoin != null)
|
||||||
{
|
{
|
||||||
aggregateInput.withQueryJoin(queryJoin);
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// re-construct this queryJoin object - just because, the JoinsContext edits the previous one, so we can make some failing-joins otherwise... //
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
fieldAndQueryJoin = getFieldAndQueryJoin(table, fieldName);
|
||||||
|
aggregateInput.withQueryJoin(fieldAndQueryJoin.queryJoin());
|
||||||
}
|
}
|
||||||
|
|
||||||
AggregateOutput aggregateOutput = new AggregateAction().execute(aggregateInput);
|
AggregateOutput aggregateOutput = new AggregateAction().execute(aggregateInput);
|
||||||
@ -238,7 +224,7 @@ public class ColumnStatsStep implements BackendStep
|
|||||||
value = Instant.parse(value + ":00:00Z");
|
value = Instant.parse(value + ":00:00Z");
|
||||||
}
|
}
|
||||||
|
|
||||||
Integer count = ValueUtils.getValueAsInteger(result.getAggregateValue(aggregate));
|
Integer count = ValueUtils.getValueAsInteger(result.getAggregateValue(aggregate));
|
||||||
valueCounts.add(new QRecord().withValue(fieldName, value).withValue("count", count));
|
valueCounts.add(new QRecord().withValue(fieldName, value).withValue("count", count));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -526,4 +512,43 @@ public class ColumnStatsStep implements BackendStep
|
|||||||
return (null);
|
return (null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
private FieldAndQueryJoin getFieldAndQueryJoin(QTableMetaData table, String fieldName)
|
||||||
|
{
|
||||||
|
QFieldMetaData field = null;
|
||||||
|
QueryJoin queryJoin = null;
|
||||||
|
if(fieldName.contains("."))
|
||||||
|
{
|
||||||
|
String[] parts = fieldName.split("\\.", 2);
|
||||||
|
for(ExposedJoin exposedJoin : CollectionUtils.nonNullList(table.getExposedJoins()))
|
||||||
|
{
|
||||||
|
if(exposedJoin.getJoinTable().equals(parts[0]))
|
||||||
|
{
|
||||||
|
field = QContext.getQInstance().getTable(exposedJoin.getJoinTable()).getField(parts[1]);
|
||||||
|
queryJoin = new QueryJoin()
|
||||||
|
.withJoinTable(exposedJoin.getJoinTable())
|
||||||
|
.withSelect(true)
|
||||||
|
.withType(QueryJoin.Type.INNER);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
field = table.getField(fieldName);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (new FieldAndQueryJoin(field, queryJoin));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
private record FieldAndQueryJoin(QFieldMetaData field, QueryJoin queryJoin) {}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user