Skip to content

Commit

Permalink
enable mutation of semantics for EntityPreviewExecution
Browse files Browse the repository at this point in the history
  • Loading branch information
awildturtok committed Sep 23, 2024
1 parent b6d1361 commit 9a02984
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
package com.bakdata.conquery.models.query;

import java.util.HashSet;
import java.util.Set;

import com.bakdata.conquery.apiv1.query.concept.specific.CQConcept;
import com.bakdata.conquery.models.datasets.concepts.select.Select;
import com.bakdata.conquery.models.types.SemanticType;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;

/**
* Container class for the query API provide meta data for reach column in the
* csv result. This can be used for the result preview in the frontend.
*/
@Data
@Builder
@AllArgsConstructor
public class ColumnDescriptor {

/**
* The name of the column. This label should be generated as a unique label among the columns.
*/
private String label;
private final String label;

private String description;
private final String description;

/**
* If this descriptor originates from a {@link Select} which is a child of {@link CQConcept},
Expand All @@ -32,13 +29,23 @@ public class ColumnDescriptor {
* <p>
* Beware that this label must not be unique among the columns
*/
private String defaultLabel;
private final String defaultLabel;

/**
* The datatype that corresponds to this column.
*/
private String type;
private final String type;

private Set<SemanticType> semantics;
private final Set<SemanticType> semantics;

public ColumnDescriptor(String label, String defaultLabel, String description, String type, Set<SemanticType> semantics){

this.label = label;
this.description = description;
this.defaultLabel = defaultLabel;
this.type = type;
this.semantics = new HashSet<>();
this.semantics.addAll(semantics);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@ default List<ColumnDescriptor> generateColumnDescriptions(boolean isInitialized,

// First add the id columns to the descriptor list. The are the first columns
for (ResultInfo header : config.getIdColumns().getIdResultInfos(settings)) {
columnDescriptions.add(ColumnDescriptor.builder()
.label(uniqNamer.getUniqueName(header))
.type(ResultType.Primitive.STRING.typeInfo())
.semantics(header.getSemantics())
.build());
final ColumnDescriptor descriptor =
new ColumnDescriptor(uniqNamer.getUniqueName(header), null, null, ResultType.Primitive.STRING.typeInfo(), header.getSemantics());
columnDescriptions.add(descriptor);
}

final UniqueNamer collector = new UniqueNamer(settings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,16 +191,17 @@ private static List<ColumnDescriptor> createChronoColumnDescriptors(SingleTableR

for (ResultInfo info : query.getResultInfos(printSettings)) {
if (info instanceof SelectResultInfo selectResultInfo) {
final PreviewConfig.InfoCardSelect desc = select2desc.get(selectResultInfo.getSelect().getId());
final PreviewConfig.InfoCardSelect additionalInfo = select2desc.get(selectResultInfo.getSelect().getId());

// We build these by hand because they are labeled and described by config.
columnDescriptions.add(ColumnDescriptor.builder()
.label(desc.label())
.defaultLabel(desc.label())
.type(info.getType().typeInfo())
.semantics(info.getSemantics())
.description((desc.description() != null) ? desc.description() : selectResultInfo.getDescription()) // both might be null
.build());
final ColumnDescriptor descriptor = new ColumnDescriptor(
additionalInfo.label(),
additionalInfo.label(),
(additionalInfo.description() != null) ? additionalInfo.description() : selectResultInfo.getDescription(),// both might be null
info.getType().typeInfo(),
info.getSemantics()
);
columnDescriptions.add(descriptor);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static class Info extends ColumnDescriptor {
private final Object value;

public Info(String label, Object value, String typeInfo, String description, Set<SemanticType> semantics) {
super(label, description, label, typeInfo, semantics);
super(label, label, description, typeInfo, semantics);
this.value = value;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,12 @@ public final void addSemantics(SemanticType... incoming) {
public abstract String userColumnName();

public final ColumnDescriptor asColumnDescriptor(UniqueNamer collector) {
return ColumnDescriptor.builder()
.label(collector.getUniqueName(this))
.defaultLabel(defaultColumnName())
.type(getType().typeInfo())
.semantics(getSemantics())
.description(getDescription())
.build();
return new ColumnDescriptor(
collector.getUniqueName(this),
defaultColumnName(), getDescription(),
getType().typeInfo(),
getSemantics()
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
public class UniqueNamer {

private final PrintSettings settings;

/**
* Is used to track possible name duplicates for column names and provide an index to enumerate these.
* This lowers the risk of duplicate column names in the result.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public void execute(String name, TestConquery testConquery) throws Exception {

assertThat(infos.columns()).containsExactly(
new ColumnDescriptor(
"Values", "Description", "Values", "LIST[STRING]",
"Values", "Values", "Description", "LIST[STRING]",
Set.of(new SemanticType.SelectResultT(
conquery.getNamespace().getCentralRegistry().resolve(valuesSelectId)
))
Expand Down

0 comments on commit 9a02984

Please sign in to comment.