Skip to content

Commit

Permalink
Allow selecting different triple pattern cardinality estimator
Browse files Browse the repository at this point in the history
  • Loading branch information
surilindur committed Oct 26, 2023
1 parent e5e57b9 commit 0cc2468
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"ccqsc:config/config-base-adaptive.json",
"ccqsc:config/override/disable-aggregate-store.json",
"ccqsc:config/rdf-metadata-extract/actors.json",
"ccqsc:config/rdf-metadata-accumulate/actors-predicate-count.json",
"ccqsc:config/rdf-metadata-accumulate/actors.json",
"ccqsc:config/rdf-join/actors.json"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,23 @@
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/config-query-sparql-components/^0.0.0/components/context.jsonld",
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-rdf-metadata-accumulate-void-description/^0.0.0/components/context.jsonld"
],
"import": [
"ccqsc:config/rdf-metadata-accumulate/cardinality-estimators.json"
],
"@id": "urn:comunica:default:Runner",
"@type": "Runner",
"actors": [
"@graph": [
{
"@id": "urn:comunica:default:rdf-metadata-accumulate/triple-pattern-cardinality-estimator#void-description-predicate-count",
"@type": "TriplePatternCardinalityEstimatorVoIDDescriptionPredicateCount"
},
{
"@id": "urn:comunica:default:rdf-metadata-accumulate/actors#void-description",
"@type": "ActorRdfMetadataAccumulateVoIDDescription",
"cardinalityEstimator": {
"@id": "urn:comunica:default:rdf-metadata-accumulate/void-cardinality-estimators#predicate-count"
}
"@id": "urn:comunica:default:Runner",
"@type": "Runner",
"actors": [
{
"@id": "urn:comunica:default:rdf-metadata-accumulate/actors#void-description",
"@type": "ActorRdfMetadataAccumulateVoIDDescription",
"triplePatternCardinalityEstimator": {
"@id": "urn:comunica:default:rdf-metadata-accumulate/triple-pattern-cardinality-estimator#void-description-predicate-count"
}
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"@context": [
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/runner/^2.0.0/components/context.jsonld",
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/config-query-sparql-components/^0.0.0/components/context.jsonld",
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-rdf-metadata-accumulate-void-description/^0.0.0/components/context.jsonld"
],
"@graph": [
{
"@id": "urn:comunica:default:rdf-metadata-accumulate/triple-pattern-cardinality-estimator#void-description",
"@type": "TriplePatternCardinalityEstimatorVoIDDescription"
},
{
"@id": "urn:comunica:default:Runner",
"@type": "Runner",
"actors": [
{
"@id": "urn:comunica:default:rdf-metadata-accumulate/actors#void-description",
"@type": "ActorRdfMetadataAccumulateVoIDDescription",
"triplePatternCardinalityEstimator": {
"@id": "urn:comunica:default:rdf-metadata-accumulate/triple-pattern-cardinality-estimator#void-description"
}
}
]
}
]
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@ After installing, this package can be added to your engine's configuration as fo
* `useCardinality`: Whether to restart join based on changes in metadata cardinality.
* `useTimeout`: Whether to restart join using a timeout.
* `allowUnlimitedRestarts`: Whether the restart should be allowed to take place more than once.
* `restartMessage`: The message to print to console when restarting a join.
* `timeout`: The timeout value on milliseconds for restarting the join.
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export interface IActorRdfJoinInnerMultiAdaptiveHeuristicsArgs extends IActorRdf
mediatorJoinEntriesSort: MediatorRdfJoinEntriesSort;
/**
* Whether the join should be restarted after metadata cardinality value changes.
* @default {false}
* @default {true}
*/
useCardinality: boolean;
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ import { KeysQueryOperation, KeysRdfResolveQuadPattern } from '@comunica/context
import type { IActorTest } from '@comunica/core';
import type { QueryResultCardinality } from '@comunica/types';
import type { Algebra } from 'sparqlalgebrajs';
import type { ICardinalityEstimatorVoIDDescription } from './CardinalityEstimatorVoIDDescription';
import type { TriplePatternCardinalityEstimator } from './TriplePatternCardinalityEstimator';

/**
* A comunica Predicate Count RDF Metadata Accumulate Actor.
*/
export class ActorRdfMetadataAccumulateVoIDDescription extends ActorRdfMetadataAccumulate {
protected readonly cardinalityEstimator: ICardinalityEstimatorVoIDDescription;
protected readonly triplePatternCardinalityEstimator: TriplePatternCardinalityEstimator;

public constructor(args: IActorRdfMetadataAccumulateVoIDDescriptionArgs) {
super(args);
this.cardinalityEstimator = args.cardinalityEstimator;
this.triplePatternCardinalityEstimator = args.triplePatternCardinalityEstimator;
}

public async test(action: IActionRdfMetadataAccumulate): Promise<IActorTest> {
Expand Down Expand Up @@ -50,7 +50,7 @@ export class ActorRdfMetadataAccumulateVoIDDescription extends ActorRdfMetadataA
for (const source of sources.keys()) {
const matchingDescription = this.getDescriptionWithLongestMatch(source, descriptions);
if (matchingDescription) {
const estimatedCardinality = this.cardinalityEstimator.estimate(matchingDescription, pattern);
const estimatedCardinality = this.triplePatternCardinalityEstimator.estimate(matchingDescription, pattern);
if (estimatedCardinality && (!bestDataset || matchingDescription.dataset.length > bestDataset.length)) {
bestEstimate = estimatedCardinality;
bestDataset = matchingDescription.dataset;
Expand Down Expand Up @@ -107,5 +107,5 @@ export interface IActorRdfMetadataAccumulateVoIDDescriptionArgs extends IActorRd
/**
* Instance of a triple pattern cardinality estimator for VoID descriptions.
*/
cardinalityEstimator: ICardinalityEstimatorVoIDDescription;
triplePatternCardinalityEstimator: TriplePatternCardinalityEstimator;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@ import type { Algebra } from 'sparqlalgebrajs';

const RDF_TYPE = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type';

export interface ICardinalityEstimatorVoIDDescription {
export interface ITriplePatternCardinalityEstimator {
estimate: (description: IVoIDDescription, pattern: Algebra.Pattern) => number | undefined;
}

export abstract class TriplePatternCardinalityEstimator implements ITriplePatternCardinalityEstimator {
public abstract estimate(description: IVoIDDescription, pattern: Algebra.Pattern): number | undefined;
}

/**
* Naïve triple pattern cardinality estimator that only checkes the predicate and used the total
* number of triples with that predicate from the property partitions
*/
export class CardinalityEstimatorVoIDDescriptionPredicateCount implements ICardinalityEstimatorVoIDDescription {
export class TriplePatternCardinalityEstimatorVoIDDescriptionPredicateCount extends TriplePatternCardinalityEstimator {
public estimate(description: IVoIDDescription, pattern: Algebra.Pattern): number | undefined {
if (pattern.predicate.termType === 'NamedNode') {
return description.propertyPartitions.get(pattern.predicate.value)?.triples;
Expand All @@ -26,7 +30,7 @@ export class CardinalityEstimatorVoIDDescriptionPredicateCount implements ICardi
* The separately listed special cases from the table for when predicate is rdf:type are mostly covered
* by the same code as the other cases. The corresponding cases are commented in the statements.
*/
export class CardinalityEstimatorVoIDDescriptionFormulae implements ICardinalityEstimatorVoIDDescription {
export class TriplePatternCardinalityEstimatorVoIDDescription extends TriplePatternCardinalityEstimator {
public estimate(description: IVoIDDescription, pattern: Algebra.Pattern): number | undefined {
if (pattern.predicate.termType === 'NamedNode') {
const pp = description.propertyPartitions.get(pattern.predicate.value);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './ActorRdfMetadataAccumulateVoIDDescription';
export * from './CardinalityEstimatorVoIDDescription';
export * from './TriplePatternCardinalityEstimator';

0 comments on commit 0cc2468

Please sign in to comment.