Skip to content

Commit

Permalink
Merge pull request #3324 from ingef/release
Browse files Browse the repository at this point in the history
Merge Release
  • Loading branch information
thoniTUB authored Mar 5, 2024
2 parents 70dc817 + 0d071ce commit a1dea24
Show file tree
Hide file tree
Showing 284 changed files with 5,174 additions and 5,875 deletions.
5 changes: 5 additions & 0 deletions backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,11 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.password4j</groupId>
<artifactId>password4j</artifactId>
<version>1.7.3</version>
</dependency>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-views-freemarker</artifactId>
Expand Down
108 changes: 15 additions & 93 deletions backend/src/main/java/com/bakdata/conquery/apiv1/QueryProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,22 @@

import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.text.NumberFormat;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Random;
import java.util.OptionalLong;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.BooleanSupplier;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.random.RandomGenerator;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
Expand Down Expand Up @@ -57,9 +55,7 @@
import com.bakdata.conquery.models.auth.entities.User;
import com.bakdata.conquery.models.auth.permissions.Ability;
import com.bakdata.conquery.models.auth.permissions.ConqueryPermission;
import com.bakdata.conquery.models.common.CDateSet;
import com.bakdata.conquery.models.common.Range;
import com.bakdata.conquery.models.common.daterange.CDateRange;
import com.bakdata.conquery.models.config.ColumnConfig;
import com.bakdata.conquery.models.config.ConqueryConfig;
import com.bakdata.conquery.models.datasets.Dataset;
Expand All @@ -83,11 +79,8 @@
import com.bakdata.conquery.models.query.queryplan.DateAggregationAction;
import com.bakdata.conquery.models.query.resultinfo.ResultInfo;
import com.bakdata.conquery.models.query.resultinfo.UniqueNamer;
import com.bakdata.conquery.models.query.results.EntityResult;
import com.bakdata.conquery.models.query.statistics.ColumnStatsCollector;
import com.bakdata.conquery.models.query.statistics.ResultStatistics;
import com.bakdata.conquery.models.query.visitor.QueryVisitor;
import com.bakdata.conquery.models.types.ResultType;
import com.bakdata.conquery.models.types.SemanticType;
import com.bakdata.conquery.models.worker.DatasetRegistry;
import com.bakdata.conquery.models.worker.Namespace;
Expand All @@ -96,8 +89,6 @@
import com.bakdata.conquery.util.io.IdColumnUtil;
import com.google.common.collect.ClassToInstanceMap;
import com.google.common.collect.MutableClassToInstanceMap;
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
import it.unimi.dsi.fastutil.ints.IntSet;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -114,29 +105,7 @@ public class QueryProcessor {
@Inject
private ConqueryConfig config;

private static CDateSet extractValidityDate(ResultType dateType, Object dateValue) {
if (dateType instanceof ResultType.DateRangeT) {
return CDateSet.create(CDateRange.fromList((List<? extends Number>) dateValue));

}

if (dateType instanceof ResultType.DateT) {
return CDateSet.create(CDateRange.exactly((Integer) dateValue));
}

if (dateType instanceof ResultType.ListT listT) {
final CDateSet out = CDateSet.createEmpty();

for (Object date : ((List<?>) dateValue)) {
out.addAll(extractValidityDate(listT.getElementType(), date));
}

// since they are ordered, we can be sure this is always the correct span
return out;
}

throw new IllegalStateException("Unexpected date Type %s".formatted(dateType));
}

public Stream<ExecutionStatus> getAllQueries(Dataset dataset, HttpServletRequest req, Subject subject, boolean allProviders) {
final Collection<ManagedExecution> allQueries = storage.getAllExecutions();
Expand Down Expand Up @@ -567,7 +536,7 @@ public Stream<Map<String, String>> resolveEntities(Subject subject, List<FilterV
final IdPrinter printer = IdColumnUtil.getIdPrinter(subject, execution, namespace, ids);

// For each included entity emit a Map of { Id-Name -> Id-Value }
return result.streamResults()
return result.streamResults(OptionalLong.empty())
.map(printer::createId)
.map(entityPrintId -> {
final Map<String, String> out = new HashMap<>();
Expand All @@ -590,72 +559,25 @@ public ResultStatistics getResultStatistics(ManagedQuery managedQuery) {
final Query query = managedQuery.getQuery();
final List<ResultInfo> resultInfos = query.getResultInfos();

final RandomGenerator random = new Random();
final int requiredSamples = config.getFrontend().getVisualisationSamples();

final Optional<ResultInfo>
dateInfo =
query.getResultInfos().stream().filter(info -> info.getSemantics().contains(new SemanticType.EventDateT())).findFirst();

final int totalSamples = managedQuery.getLastResultCount().intValue();
final int dateIndex = dateInfo.map(resultInfos::indexOf).orElse(0 /*Discarded if dateInfo is not present*/);

//We collect about $requiredSamples values as samples for visualisation, while streaming the values.
// Note that nextInt produces values > 0 and < totalSamples. This is equivalent to `P(k) = $requiredSamples/$totalSamples` but terser.
final BooleanSupplier samplePicker;
final Locale locale = I18n.LOCALE.get();
final NumberFormat decimalFormat = NumberFormat.getNumberInstance(locale);
decimalFormat.setMaximumFractionDigits(2);

if (totalSamples <= requiredSamples) {
samplePicker = () -> true;
}
else {
samplePicker = () -> random.nextInt(totalSamples) < requiredSamples;
}
final NumberFormat integerFormat = NumberFormat.getNumberInstance(locale);

final boolean hasValidityDates = resultInfos.get(0).getSemantics().contains(new SemanticType.EventDateT());
final ResultType dateType = resultInfos.get(0).getType();

final PrintSettings printSettings = new PrintSettings(false, I18n.LOCALE.get(), managedQuery.getNamespace(), config, null);
final PrintSettings printSettings =
new PrintSettings(true, locale, managedQuery.getNamespace(), config, null, null, decimalFormat, integerFormat);
final UniqueNamer uniqueNamer = new UniqueNamer(printSettings);


final List<ColumnStatsCollector> statsCollectors = resultInfos.stream()
.map(info -> ColumnStatsCollector.getStatsCollector(info, printSettings, samplePicker, info.getType(), uniqueNamer))
.collect(Collectors.toList());

final IntSet entities = new IntOpenHashSet();
final AtomicInteger lines = new AtomicInteger();

final AtomicReference<CDateRange> span = new AtomicReference<>(null);


managedQuery.streamResults()
.peek(result -> entities.add(result.getEntityId()))
.map(EntityResult::listResultLines)
.flatMap(List::stream)
.forEach(line -> {

if (hasValidityDates) {
final CDateSet dateSet = extractValidityDate(dateType, line[0]);
span.getAndAccumulate(dateSet.span(), (old, incoming) -> incoming.spanClosed(old));
}

lines.incrementAndGet();

for (int col = 0; col < line.length; col++) {
final ColumnStatsCollector collector = statsCollectors.get(col);
if (collector == null) {
continue;
}

collector.consume(line[col]);
}
});

return new ResultStatistics(
entities.size(),
lines.get(),
statsCollectors.stream()
.filter(Objects::nonNull) // Not all columns produces stats
.map(ColumnStatsCollector::describe)
.toList(),
span.get().toSimpleRange()
);
return ResultStatistics.collectResultStatistics(managedQuery, resultInfos, dateInfo, dateIndex, printSettings, uniqueNamer, config);
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,13 @@
import javax.validation.constraints.NotEmpty;

import com.bakdata.conquery.io.cps.CPSType;
import com.bakdata.conquery.models.config.auth.AuthorizationConfig;
import com.bakdata.conquery.models.auth.basic.LocalAuthenticationRealm;
import com.fasterxml.jackson.annotation.JsonCreator;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import com.bakdata.conquery.models.config.auth.AuthorizationConfig;

/**
* Container for holding a password. This credential type is used by the
* {@link LocalAuthenticationRealm} and can be used in the {@link AuthorizationConfig}.
* Container for holding a plain-text password. This credential type is used by the
* {@link LocalAuthenticationRealm} and can be used in the {@link AuthorizationConfig}.
*/
@CPSType(base = CredentialType.class, id = "PASSWORD")
@Data
@RequiredArgsConstructor(onConstructor = @__({@JsonCreator}))
@AllArgsConstructor
public class PasswordCredential implements CredentialType {

@NotEmpty
private char[] password;
public record PasswordCredential(@NotEmpty String password) implements CredentialType {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.bakdata.conquery.apiv1.auth;

import javax.validation.constraints.NotEmpty;

import com.bakdata.conquery.io.cps.CPSType;

@CPSType(base = CredentialType.class, id = "PASSWORD_HASH")
public record PasswordHashCredential(@NotEmpty String hash) implements CredentialType {
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.bakdata.conquery.apiv1.auth;

import java.util.Collections;
import java.util.List;
import java.util.Set;

import javax.validation.Valid;
Expand Down Expand Up @@ -45,9 +44,8 @@ public class ProtoUser {
* {@link UserManageable}, such as {@link LocalAuthenticationRealm}).
*/
@Builder.Default
@NotNull
@Valid
private List<CredentialType> credentials = Collections.emptyList();
private CredentialType credential = null;

public User createOrOverwriteUser(@NonNull MetaStorage storage) {
if (label == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ public class UsernamePasswordToken {
@NotEmpty
private String user;
@NotEmpty
private char[] password;
private String password;
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public abstract class CQElement implements Visitable {
*/
@Setter
@Getter
private String label = null;
private String label;

public String getUserOrDefaultLabel(Locale locale) {
// Prefer the user label
Expand All @@ -50,11 +50,11 @@ public String getUserOrDefaultLabel(Locale locale) {
@NotNull
public String defaultLabel(Locale locale) {
// Fallback to CPSType#id() implementation is provided or class name
CPSType type = this.getClass().getAnnotation(CPSType.class);
final CPSType type = getClass().getAnnotation(CPSType.class);
if (type != null) {
return type.id();
}
return this.getClass().getSimpleName();
return getClass().getSimpleName();
}

/**
Expand All @@ -70,14 +70,13 @@ public String defaultLabel(Locale locale) {

public abstract QPNode createQueryPlan(QueryPlanContext context, ConceptQueryPlan plan);

public Set<ManagedExecutionId> collectRequiredQueries() {
Set<ManagedExecutionId> set = new HashSet<>();
this.collectRequiredQueries(set);
public final Set<ManagedExecutionId> collectRequiredQueries() {
final Set<ManagedExecutionId> set = new HashSet<>();
collectRequiredQueries(set);
return set;
}

public void collectRequiredQueries(Set<ManagedExecutionId> requiredQueries) {
}
public abstract void collectRequiredQueries(Set<ManagedExecutionId> requiredQueries) ;

@JsonIgnore
public abstract List<ResultInfo> getResultInfos();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import java.util.Collections;
import java.util.List;
import java.util.Set;

import com.bakdata.conquery.io.cps.CPSType;
import com.bakdata.conquery.models.identifiable.ids.specific.ManagedExecutionId;
import com.bakdata.conquery.models.query.QueryExecutionContext;
import com.bakdata.conquery.models.query.QueryPlanContext;
import com.bakdata.conquery.models.query.QueryResolveContext;
Expand All @@ -26,6 +28,11 @@ public QPNode createQueryPlan(QueryPlanContext context, ConceptQueryPlan plan) {
return new Yes(context.getDataset().getAllIdsTable());
}

@Override
public void collectRequiredQueries(Set<ManagedExecutionId> requiredQueries) {

}

@Override
public List<ResultInfo> getResultInfos() {
return Collections.emptyList();
Expand Down
Loading

0 comments on commit a1dea24

Please sign in to comment.