Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: Initial DataCubeComponents / dimension values query optimizations #1360

Merged
merged 19 commits into from
Feb 27, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 53 additions & 33 deletions app/rdf/query-dimension-values.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,39 +232,59 @@ const getQueryFilters = (
cube: ExtendedCube,
dimensionIri: string | undefined
) => {
return filtersList.length > 0
? filtersList.map(([iri, value], i) => {
const dimension = cube.dimensions.find((d) => d.path?.value === iri);

// Ignore the current dimension
if (!dimension || dimensionIri === iri) {
return "";
}

// Ignore filters with no value or with the special value
if (
value.type === "single" &&
(value.value === FIELD_VALUE_NONE || isDynamicMaxValue(value.value))
) {
return "";
}

// Ignore range filters for now
if (value.type === "range") {
return "";
}

const versioned = dimension ? dimensionIsVersioned(dimension) : false;

return sparql`${
versioned
? sparql`?dimension${i} ${ns.schema.sameAs} ?dimension_unversioned${i}.`
: ""
}
?observation <${iri}> ?dimension${i}.
${formatFilterIntoSparqlFilter(value, dimension, versioned, i)}`;
})
: "";
if (filtersList.length === 0) {
return "";
}

let i = 0;
const filterDimensionIris = filtersList.map(([iri]) => iri);
// Also include other dimensions to make sure we don't return values that could
// result in no observations
bprusinowski marked this conversation as resolved.
Show resolved Hide resolved
const otherDimensionFilters = cube.dimensions
.filter(
(dim) =>
!filterDimensionIris.includes(dim.path?.value ?? "") ||
dim.path?.equals(ns.cube.observedBy)
)
.map((dim) => `?observation <${dim.path?.value}> ?dimension${i++} .`);
const filterDimensionFilters = filtersList.map(([iri, value], j) => {
const dimension = cube.dimensions.find((d) => d.path?.value === iri);

// Ignore the current dimension
if (!dimension || dimensionIri === iri) {
return "";
}

// Ignore filters with no value or with the special value
if (
value.type === "single" &&
(value.value === FIELD_VALUE_NONE || isDynamicMaxValue(value.value))
) {
return "";
}

// Ignore range filters for now
if (value.type === "range") {
return "";
}

const versioned = dimension ? dimensionIsVersioned(dimension) : false;

return sparql`${
versioned
? sparql`?dimension${i + j} ${ns.schema.sameAs} ?dimension_unversioned${
i + j
} .`
: ""
}
?observation <${iri}> ?dimension${i + j} .
${formatFilterIntoSparqlFilter(value, dimension, versioned, i + j)}`;
});

return `
${otherDimensionFilters.join("\n")}
${filterDimensionFilters.join("\n")}
`;
bprusinowski marked this conversation as resolved.
Show resolved Hide resolved
};

type MinMaxResult = [{ minValue: LiteralExt; maxValue: LiteralExt }];
Expand Down
Loading