-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2709 from bakdata/hotfix/revert-multi-column-dist…
…inct Hotfix/revert multi column distinct
- Loading branch information
Showing
13 changed files
with
243 additions
and
306 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 22 additions & 24 deletions
46
.../com/bakdata/conquery/models/datasets/concepts/select/connector/specific/CountSelect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,54 @@ | ||
package com.bakdata.conquery.models.datasets.concepts.select.connector.specific; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.stream.Stream; | ||
|
||
import javax.validation.constraints.NotNull; | ||
|
||
import com.bakdata.conquery.io.cps.CPSType; | ||
import com.bakdata.conquery.io.jackson.serializer.NsIdRefCollection; | ||
import com.bakdata.conquery.io.jackson.serializer.NsIdRef; | ||
import com.bakdata.conquery.models.datasets.Column; | ||
import com.bakdata.conquery.models.datasets.concepts.select.Select; | ||
import com.bakdata.conquery.models.query.queryplan.aggregators.Aggregator; | ||
import com.bakdata.conquery.models.query.queryplan.aggregators.DistinctValuesWrapperAggregator; | ||
import com.bakdata.conquery.models.query.queryplan.aggregators.specific.CountAggregator; | ||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
import io.dropwizard.validation.ValidationMethod; | ||
import lombok.Data; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
@CPSType(id = "COUNT", base = Select.class) | ||
@NoArgsConstructor | ||
@Data | ||
public class CountSelect extends Select { | ||
|
||
@Getter | ||
@Setter | ||
private boolean distinct = false; | ||
|
||
@NsIdRefCollection | ||
@NotNull | ||
private List<Column> column; | ||
@Getter | ||
@Setter | ||
@NsIdRef | ||
private Column distinctByColumn; | ||
|
||
@Getter | ||
@Setter | ||
@NsIdRef | ||
@NotNull | ||
private Column column; | ||
|
||
@Override | ||
public Aggregator<?> createAggregator() { | ||
if (distinct) { | ||
return new DistinctValuesWrapperAggregator<>(new CountAggregator(), getColumn()); | ||
if (distinct || distinctByColumn != null) { | ||
return new DistinctValuesWrapperAggregator<>(new CountAggregator(getColumn()), getDistinctByColumn() == null ? getColumn() : getDistinctByColumn()); | ||
} | ||
return new CountAggregator(getColumn().get(0)); | ||
return new CountAggregator(getColumn()); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public Column[] getRequiredColumns() { | ||
return getColumn().toArray(Column[]::new); | ||
} | ||
|
||
|
||
@JsonIgnore | ||
@ValidationMethod(message = "Cannot use multiple columns, when distinct is not set.") | ||
public boolean isMultiOnlyWhenDistinct() { | ||
if(!isDistinct()){ | ||
return getColumn().size() == 1; | ||
} | ||
|
||
return true; | ||
return Stream.of(getColumn(), getDistinctByColumn()) | ||
.filter(Objects::nonNull) | ||
.toArray(Column[]::new); | ||
} | ||
} |
Oops, something went wrong.