Skip to content

Commit

Permalink
[#801] Fix wrong calculation of view index in subselect correlator le…
Browse files Browse the repository at this point in the history
…ads to empty correlations
  • Loading branch information
beikov committed May 29, 2019
1 parent 87e3d5d commit ff0acc2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ private String applyAndGetCorrelationRoot(BatchCorrelationMode batchCorrelationM
this.criteriaBuilder.registerMacro("view_root", viewRootJpqlMacro);
this.criteriaBuilder.registerMacro("embedding_view", embeddingViewJpqlMacro);

SubqueryCorrelationBuilder correlationBuilder = new SubqueryCorrelationBuilder(criteriaBuilder, correlationAlias, correlationResult, correlationBasisType, correlationBasisEntityType, CORRELATION_KEY_ALIAS, batchSize, false, attributePath);
String joinBase = CORRELATION_KEY_ALIAS;
SubqueryCorrelationBuilder correlationBuilder = new SubqueryCorrelationBuilder(criteriaBuilder, correlationAlias, correlationResult, correlationBasisType, correlationBasisEntityType, CORRELATION_KEY_ALIAS, joinBase, batchSize, false, attributePath);
CorrelationProvider provider = correlationProviderFactory.create(entityViewConfiguration.getCriteriaBuilder(), entityViewConfiguration.getOptionalParameters());

String correlationKeyExpression;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public abstract class AbstractCorrelatedSubselectTupleListTransformer extends Ab
protected final String correlationBasisExpression;
protected final String correlationKeyExpression;
protected final int valueIndex;
protected final int viewIndex;

protected int viewIndex;
protected int keyIndex;
protected FullQueryBuilder<?, ?> criteriaBuilder;
protected CorrelatedSubqueryViewRootJpqlMacro viewRootJpqlMacro;
Expand All @@ -85,7 +85,6 @@ public AbstractCorrelatedSubselectTupleListTransformer(ExpressionFactory ef, Cor
this.correlationBasisExpression = correlationBasisExpression;
this.correlationKeyExpression = correlationKeyExpression;
this.valueIndex = correlator.getElementOffset();
this.viewIndex = valueIndex + 1;
}

private static int viewIdMapperCount(ManagedViewType<?> viewRootType) {
Expand Down Expand Up @@ -146,7 +145,8 @@ public List<Object[]> transform(List<Object[]> tuples) {
String oldEmbeddingViewPath = embeddingViewJpqlMacro.getEmbeddingViewPath();
embeddingViewJpqlMacro.setEmbeddingViewPath(embeddingViewPath);

SubqueryCorrelationBuilder correlationBuilder = new SubqueryCorrelationBuilder(criteriaBuilder, correlationAlias, correlationResult, correlationBasisType, correlationBasisEntityType, null, 1, true, attributePath);
String joinBase = embeddingViewPath;
SubqueryCorrelationBuilder correlationBuilder = new SubqueryCorrelationBuilder(criteriaBuilder, correlationAlias, correlationResult, correlationBasisType, correlationBasisEntityType, null, joinBase, 1, true, attributePath);
CorrelationProvider provider = correlationProviderFactory.create(entityViewConfiguration.getCriteriaBuilder(), entityViewConfiguration.getOptionalParameters());

provider.applyCorrelation(correlationBuilder, correlationBasisExpression);
Expand All @@ -170,12 +170,15 @@ public List<Object[]> transform(List<Object[]> tuples) {
if (usesEmbeddingView) {
maximumSlotsFilled = embeddingViewIdMapperCount == 0 ? 1 : embeddingViewIdMapperCount;
this.keyIndex = (maximumViewMapperCount - maximumSlotsFilled) + 2 + valueIndex;
this.viewIndex = (maximumViewMapperCount - maximumSlotsFilled) + 1 + valueIndex;
} else if (usesViewRoot) {
maximumSlotsFilled = viewRootIdMapperCount == 0 ? 1 : viewRootIdMapperCount;
this.keyIndex = (maximumViewMapperCount - maximumSlotsFilled) + 2 + valueIndex;
this.viewIndex = (maximumViewMapperCount - maximumSlotsFilled) + 1 + valueIndex;
} else {
maximumSlotsFilled = 0;
this.keyIndex = maximumViewMapperCount + 1 + valueIndex;
this.viewIndex = 1 + valueIndex;
}

for (int i = maximumSlotsFilled; i < maximumViewMapperCount; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,19 @@ public class SubqueryCorrelationBuilder implements CorrelationBuilder {
private final Class<?> correlationBasisType;
private final Class<?> correlationBasisEntity;
private final String correlationKeyAlias;
private final String correlationJoinBase;
private final int batchSize;
private final boolean innerJoin;
private String correlationRoot;

public SubqueryCorrelationBuilder(FullQueryBuilder<?, ?> criteriaBuilder, String correlationAlias, String correlationResult, Class<?> correlationBasisType, Class<?> correlationBasisEntity, String correlationKeyAlias, int batchSize, boolean innerJoin, String attributePath) {
public SubqueryCorrelationBuilder(FullQueryBuilder<?, ?> criteriaBuilder, String correlationAlias, String correlationResult, Class<?> correlationBasisType, Class<?> correlationBasisEntity, String correlationKeyAlias, String correlationJoinBase, int batchSize, boolean innerJoin, String attributePath) {
this.criteriaBuilder = criteriaBuilder;
this.correlationAlias = correlationAlias;
this.correlationResult = correlationResult;
this.correlationBasisType = correlationBasisType;
this.correlationBasisEntity = correlationBasisEntity;
this.correlationKeyAlias = correlationKeyAlias;
this.correlationJoinBase = correlationJoinBase;
this.batchSize = batchSize;
this.innerJoin = innerJoin;
}
Expand Down Expand Up @@ -85,10 +87,10 @@ public JoinOnBuilder<CorrelationQueryBuilder> correlate(Class<?> entityClass) {
criteriaBuilder.fromValues(correlationBasisType, correlationKeyAlias, batchSize);
}

correlationBuilder = (JoinOnBuilder<CorrelationQueryBuilder>) (JoinOnBuilder<?>) criteriaBuilder.innerJoinOn(entityClass, correlationAlias);
correlationBuilder = (JoinOnBuilder<CorrelationQueryBuilder>) (JoinOnBuilder<?>) criteriaBuilder.innerJoinOn(correlationJoinBase, entityClass, correlationAlias);
} else {
if (innerJoin) {
correlationBuilder = (JoinOnBuilder<CorrelationQueryBuilder>) (JoinOnBuilder<?>) criteriaBuilder.innerJoinOn(entityClass, correlationAlias);
correlationBuilder = (JoinOnBuilder<CorrelationQueryBuilder>) (JoinOnBuilder<?>) criteriaBuilder.innerJoinOn(correlationJoinBase, entityClass, correlationAlias);
} else {
criteriaBuilder.from(entityClass, correlationAlias);
correlationBuilder = criteriaBuilder.getService(JoinOnBuilder.class);
Expand Down

0 comments on commit ff0acc2

Please sign in to comment.