Skip to content

Commit

Permalink
backup
Browse files Browse the repository at this point in the history
  • Loading branch information
dexamundsen committed Jan 29, 2025
1 parent 0612fb9 commit c6aee21
Showing 1 changed file with 105 additions and 27 deletions.
132 changes: 105 additions & 27 deletions service/src/main/java/bio/terra/tanagra/service/UnderlayService.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import bio.terra.tanagra.api.field.ValueDisplayField;
import bio.terra.tanagra.api.filter.EntityFilter;
import bio.terra.tanagra.api.query.PageMarker;
import bio.terra.tanagra.api.query.count.CountInstance;
import bio.terra.tanagra.api.query.count.CountQueryRequest;
import bio.terra.tanagra.api.query.count.CountQueryResult;
import bio.terra.tanagra.api.query.hint.HintInstance;
Expand All @@ -35,6 +36,7 @@
import bio.terra.tanagra.service.accesscontrol.ResourceId;
import bio.terra.tanagra.underlay.ConfigReader;
import bio.terra.tanagra.underlay.Underlay;
import bio.terra.tanagra.underlay.entitymodel.Attribute;
import bio.terra.tanagra.underlay.entitymodel.Entity;
import bio.terra.tanagra.underlay.serialization.SZService;
import bio.terra.tanagra.underlay.serialization.SZUnderlay;
Expand Down Expand Up @@ -92,17 +94,19 @@ public UnderlayService(
this.underlayCache = ImmutableMap.copyOf(underlayCacheBuilder);

// pre-compute underlay-wide visualizations (underlayCache must be initialized before this)
underlayCache.forEach(
(name, cache) -> {
Underlay underlay = cache.underlay;

underlay.getClientConfig().getVisualizations().stream()
.parallel()
.forEach(
szViz -> {
cache.putUnderlayLevelVisualization(buildVisualization(underlay, szViz));
});
});
underlayCache.entrySet().parallelStream()
.forEach(
cachedUnderlayEntry -> {
Underlay underlay = cachedUnderlayEntry.getValue().getUnderlay();

underlay.getClientConfig().getVisualizations().parallelStream()
.forEach(
szViz -> {
cachedUnderlayEntry
.getValue()
.putUnderlayLevelVisualization(buildVisualization(underlay, szViz));
});
});
}

private Visualization buildVisualization(Underlay underlay, SZVisualization szViz) {
Expand Down Expand Up @@ -154,23 +158,98 @@ private Visualization buildVisualization(Underlay underlay, SZVisualization szVi
List<String> groupByAttributeNames =
vizDCSource.attributes.stream().map(a -> a.attribute).toList();

// TODO-DEX: merge results from multiple calls
CountQueryResult countQueryResult =
runCountQuery(
underlay,
selectorEntity,
countDistinctAttributeName,
groupByAttributeNames,
/* entityFilter= */ null,
OrderByDirection.DESCENDING,
/* limit= */ 1_000_000,
/* pageMarker= */ null,
/* pageSize= */ null);
List<CountInstance> countInstances = new ArrayList<>();
PageMarker pageMarker;
do {
CountQueryResult countQueryResult =
runCountQuery(
underlay,
selectorEntity,
countDistinctAttributeName,
groupByAttributeNames,
/* entityFilter= */ null,
OrderByDirection.DESCENDING,
/* limit= */ 1_000_000,
/* pageMarker= */ null,
/* pageSize= */ null);
pageMarker = countQueryResult.getPageMarker();
countInstances.addAll(countQueryResult.getCountInstances());
} while (pageMarker != null);

/*
countInstances.stream().map(
instance -> {
Map<String, ApiValueDisplay> attributes = new HashMap<>();
instance
.getEntityFieldValues()
.forEach(
(field, value) -> {
if (field instanceof AttributeField) {
attributes.put(
((AttributeField) field).getAttribute().getName(),
ToApiUtils.toApiObject(value));
}
});
attributes.forEach(
(k, v) -> {
DataValue value = null;
String display = v.getDisplay();
if (v.isIsRepeatedValue()) {
if (v.getRepeatedValue() != null) {
display = v.getRepeatedValue().stream().map(
l -> l.
)
}
display = v.getRepeatedValue()
} else {
}
}
);
FilterCountValue fc =
new FilterCountValue(Math.toIntExact(instance.getCount()),
null);
}
); */

List<VisualizationData> visualizationDataList = new ArrayList<>();
return new Visualization(szViz.name, szViz.title, visualizationDataList);
}

/*
public record DataValue(String key, Object val) {}
public record FilterCountValue(int count, Map<String, DataValue> value) {}
/*
export type FilterCountValue = {
count: number;
[x: string]: DataValue;
};
const value: FilterCountValue = {
count: count.count ?? 0,
};
processAttributes(value, count.attributes);
*/

public List<Underlay> listUnderlays(ResourceCollection authorizedIds) {
if (authorizedIds.isAllResources()) {
return underlayCache.values().stream()
Expand Down Expand Up @@ -325,11 +404,10 @@ public HintQueryResult getEntityLevelHints(
// For each attribute with a hint, calculate new hints with the filter
StringBuilder allSql = new StringBuilder();
List<HintInstance> allHintInstances = new ArrayList<>();
entityLevelHints.getHintInstances().stream()
.map(HintInstance::getAttribute)
.parallel()
entityLevelHints.getHintInstances().parallelStream()
.map(
attribute -> {
hintInstance -> {
Attribute attribute = hintInstance.getAttribute();
if (isRangeHint(attribute)) {
String sql =
WriteEntityLevelDisplayHints.buildRangeHintSql(
Expand Down

0 comments on commit c6aee21

Please sign in to comment.