diff --git a/app/components/debug-panel/DebugPanel.tsx b/app/components/debug-panel/DebugPanel.tsx index 31a4b7f05..f6752826a 100644 --- a/app/components/debug-panel/DebugPanel.tsx +++ b/app/components/debug-panel/DebugPanel.tsx @@ -125,8 +125,7 @@ const DebugConfigurator = () => { size="small" href={`${sparqlEditorUrl}#query=${encodeURIComponent( `#pragma describe.strategy cbd - #pragma join.hash off - + DESCRIBE <${cube.iri}>` )}&requestMethod=POST`} target="_blank" diff --git a/app/graphql/context.tsx b/app/graphql/context.tsx index bd3623612..6efb5b990 100644 --- a/app/graphql/context.tsx +++ b/app/graphql/context.tsx @@ -10,9 +10,9 @@ import { LRUCache } from "typescript-lru-cache"; import { SPARQL_GEO_ENDPOINT } from "@/domain/env"; import { Awaited } from "@/domain/types"; import { Timings } from "@/gql-flamegraph/resolvers"; -import { createSource } from "@/rdf/create-source"; +import { createSource, pragmas } from "@/rdf/create-source"; import { ExtendedCube } from "@/rdf/extended-cube"; -import { timed, TimingCallback } from "@/utils/timed"; +import { TimingCallback, timed } from "@/utils/timed"; import { createCubeDimensionValuesLoader } from "../rdf/queries"; import { @@ -27,7 +27,7 @@ import { RequestQueryMeta } from "./query-meta"; export const MAX_BATCH_SIZE = 500; export const getRawCube = async (sparqlClient: ParsingClient, iri: string) => { - const source = createSource(sparqlClient); + const source = createSource(sparqlClient, pragmas); const cube = new ExtendedCube({ parent: source, term: rdf.namedNode(iri), diff --git a/app/rdf/create-source.ts b/app/rdf/create-source.ts index 1ce24882b..46d762cf1 100644 --- a/app/rdf/create-source.ts +++ b/app/rdf/create-source.ts @@ -6,11 +6,14 @@ export const pragmas = `#pragma describe.strategy cbd #pragma join.hash off `; -export const createSource = (sparqlClient: ParsingClient) => { +export const createSource = ( + sparqlClient: ParsingClient, + queryPrefix?: string +) => { return new Source({ client: sparqlClient, queryOperation: "postUrlencoded", - queryPrefix: pragmas, + queryPrefix, sourceGraph: rdf.defaultGraph(), }); }; diff --git a/app/rdf/queries.ts b/app/rdf/queries.ts index 4e5e5e0f6..1f935c8f0 100644 --- a/app/rdf/queries.ts +++ b/app/rdf/queries.ts @@ -9,7 +9,7 @@ import { LRUCache } from "typescript-lru-cache"; import { PromiseValue, truthy } from "@/domain/types"; import { DataCubeComponentFilter } from "@/graphql/resolver-types"; -import { pragmas } from "@/rdf/create-source"; +import { createSource, pragmas } from "@/rdf/create-source"; import { ExtendedCube } from "@/rdf/extended-cube"; import { FilterValueMulti, Filters } from "../configurator"; @@ -610,6 +610,14 @@ export const getCubeObservations = async ({ filters: observationFilters, }); + // In order to fix an error with cartesian products introduced in preview query + // when using #pragma join.hash off, we need to have a clean source without + // decorating the sparql client. However we still need to keep the pragmas + // for the full query, to vastly improve performance. + observationsView.getMainSource = preview + ? () => createSource(sparqlClient) + : cubeView.getMainSource; + const { query, observationsRaw } = await fetchViewObservations({ preview, limit, diff --git a/app/rdf/query-literals.ts b/app/rdf/query-literals.ts index da8f09d34..a4d24c8de 100644 --- a/app/rdf/query-literals.ts +++ b/app/rdf/query-literals.ts @@ -1,6 +1,6 @@ import { SELECT, sparql } from "@tpluscode/sparql-builder"; import uniqBy from "lodash/uniqBy"; -import { NamedNode, Literal } from "rdf-js"; +import { Literal, NamedNode } from "rdf-js"; import ParsingClient from "sparql-http-client/ParsingClient"; import { LRUCache } from "typescript-lru-cache"; diff --git a/app/typings/rdf.d.ts b/app/typings/rdf.d.ts index d62eaa34b..5a581bf4f 100644 --- a/app/typings/rdf.d.ts +++ b/app/typings/rdf.d.ts @@ -116,6 +116,7 @@ declare module "rdf-cube-view-query" { addDimension(dimension: Dimension): View; createDimension(options: $FixMe): Dimension; setDefaultColumns(): void; + getMainSource(): Source; } export type SourceOptions = NodeInit & {