Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
d278f1e
Say "graph databases" instead of "engines" in the `qeval` help
tanmay-9 Oct 10, 2026
8e8502c
Add shared `status` and `stop` commands for the graph databases in `q…
tanmay-9 Oct 10, 2026
4df3ef9
Add shared `query` and `benchmark-queries` commands and an endpoint p…
tanmay-9 Oct 10, 2026
bee679b
Add a shared `setup-config` command for the graph databases in `qeval`
tanmay-9 Oct 10, 2026
da603b4
Add a shared `index-stats` command for the graph databases in `qeval`
tanmay-9 Oct 10, 2026
39fcda0
Rename the shared `qeval` commands to `Base...Command` in `qeval/base…
tanmay-9 Oct 10, 2026
8e70388
Set `pin_to_cache` as a parser default in the shared `query` command
tanmay-9 Oct 10, 2026
b597433
Let engines choose the index-stats command and cache clearing in `ben…
tanmay-9 Oct 10, 2026
720b5e2
Merge remote-tracking branch 'origin/main' into qeval-base-commands
tanmay-9 Oct 13, 2026
d8b8681
Read the SPARQL endpoint path and the `status` regex from hooks inste…
tanmay-9 Oct 13, 2026
25052fa
Use `/` as the SPARQL endpoint path of QLever, so that every endpoint…
tanmay-9 Oct 13, 2026
e15c7e7
Let engines choose the `--accept` choices and whether `--pin-to-cache…
tanmay-9 Oct 13, 2026
9d58ea4
Merge remote-tracking branch 'origin/main' into qeval-base-commands
tanmay-9 Oct 21, 2026
4d76479
Merge remote-tracking branch 'origin/main' into qeval-base-commands
hannahbast Oct 22, 2026
3238bdb
Report a missing container in the shared `stop` command
hannahbast Oct 22, 2026
6ebfa09
Merge remote-tracking branch 'origin/main' into qeval-base-commands
tanmay-9 Nov 2, 2026
ab07735
Match qeval's BaseStopCommand with qlever's and add tests for all the…
tanmay-9 Nov 2, 2026
da3d707
Make sure that status_command of corresponding engine is run when sto…
tanmay-9 Nov 2, 2026
28eeccd
Merge remote-tracking branch 'origin/main' into qeval-base-commands
tanmay-9 Nov 13, 2026
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
Empty file.
22 changes: 22 additions & 0 deletions src/qeval/base_commands/benchmark_queries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from __future__ import annotations

from abc import abstractmethod

from qeval.base_commands.index_stats import BaseIndexStatsCommand
from qlever.commands.benchmark_queries import (
BenchmarkQueriesCommand as QleverBenchmarkQueriesCommand,
)


class BaseBenchmarkQueriesCommand(QleverBenchmarkQueriesCommand):
"""
Run benchmark queries against the SPARQL endpoint of an engine.
"""

@abstractmethod
def index_stats_command(self) -> BaseIndexStatsCommand:
"""The command that reads the index time and size of the engine."""

def can_clear_cache(self, args, engine: str | None) -> bool:
# Clearing the cache before each query only works for QLever.
return False
81 changes: 81 additions & 0 deletions src/qeval/base_commands/index_stats.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
from __future__ import annotations

from abc import abstractmethod
from pathlib import Path

from qlever.commands.index_stats import (
IndexStatsCommand as QleverIndexStatsCommand,
)
from qlever.commands.index_stats import (
get_size_unit,
get_size_unit_factor,
get_time_unit,
get_time_unit_factor,
)
from qlever.log import log
from qlever.util import get_total_file_size


def read_index_log(log_file_name: str | Path) -> str | None:
"""
The text of the index log, or None if it cannot be read, which is
reported as an error.
"""
try:
return Path(log_file_name).read_text(errors="replace")
except OSError as e:
log.error(f"Problem reading index log file {log_file_name}: {e}")
return None


class BaseIndexStatsCommand(QleverIndexStatsCommand):
"""
Show how long the index build of an engine took and how much space its
index uses, from the durations in its index log and the size of its
index files.
"""

@abstractmethod
def index_size_patterns(self, args) -> list[str]:
"""The glob patterns of the index files, whose sizes add up."""

@abstractmethod
def parse_index_durations(self, log_text: str) -> dict[str, float]:
"""
How long each phase of the build took in seconds, from the text of
the index log, in the order to show them. The result files of
`benchmark-queries` take the index time from the "TOTAL time" entry.
"""

def index_durations(self, log_file_name: str | Path) -> dict[str, float]:
"""
Read the index log and parse it. Empty if the log cannot be read.
"""
log_text = read_index_log(log_file_name)
if log_text is None:
return {}
return self.parse_index_durations(log_text)

def execute_time(
self, args, log_file_name: str
) -> dict[str, tuple[float | None, str]]:
"""
The duration of each phase, all in the same unit, picked to suit
the longest one.
"""
durations = self.index_durations(log_file_name)
if not durations:
return {}
time_unit = get_time_unit(args.time_unit, max(durations.values()))
unit_factor = get_time_unit_factor(time_unit)
return {
heading: (seconds / unit_factor, time_unit)
for heading, seconds in durations.items()
}

def execute_space(self, args) -> dict[str, tuple[float, str]]:
"""The total size of the index files, in a unit that suits it."""
index_size = get_total_file_size(self.index_size_patterns(args))
size_unit = get_size_unit(args.size_unit, index_size)
unit_factor = get_size_unit_factor(size_unit)
return {"TOTAL size": (index_size / unit_factor, size_unit)}
25 changes: 25 additions & 0 deletions src/qeval/base_commands/query.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from __future__ import annotations

from qlever.commands.query import QueryCommand as QleverQueryCommand


class BaseQueryCommand(QleverQueryCommand):
"""
Send a query to the SPARQL endpoint of an engine. QLever's option to pin
the result to its cache, and the access token that this needs, are left
out.
"""

def relevant_qleverfile_arguments(self) -> dict[str, list[str]]:
return {"server": ["host_name", "port"]}

def accept_header_choices(self) -> list[str]:
return [
"text/tab-separated-values",
"text/csv",
"application/sparql-results+json",
"application/sparql-results+xml",
]

def can_pin_to_cache(self) -> bool:
return False
82 changes: 82 additions & 0 deletions src/qeval/base_commands/setup_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
from __future__ import annotations

from abc import abstractmethod
from pathlib import Path

from qlever.commands.setup_config import (
SetupConfigCommand as QleverSetupConfigCommand,
)
from qlever.commands.setup_config import check_qleverfile_exists
from qlever.log import log
from qlever.qleverfile import Qleverfile


class BaseSetupConfigCommand(QleverSetupConfigCommand):
"""
Create a Qleverfile for an engine from one of QLever's pre-configured
Qleverfiles: keep only the parts that every engine needs, then add the
engine's image and its own settings.
"""

def filter_criteria(self) -> dict[str, list[str] | None]:
"""
The sections and options of a pre-configured Qleverfile to keep, by
default those that every engine needs. `None` keeps every option of
the section. An engine that needs more can add to what this returns.
"""
return {
"data": None,
"index": ["INPUT_FILES"],
"server": ["PORT"],
"runtime": ["SYSTEM", "IMAGE"],
"ui": ["UI_CONFIG"],
}

@abstractmethod
def image(self) -> str:
"""The container image of the engine."""

@abstractmethod
def engine_settings(self, args) -> dict[str, dict[str, str]]:
"""The engine's own Qleverfile values, as {section: {option: value}}."""

def execute(self, args) -> bool:
template_path = (
self.qleverfiles_path / f"Qleverfile.{args.config_name}"
)
self.show(
f"Create a Qleverfile from {template_path}, keeping only the "
"parts that apply to this graph database",
only_show=args.show,
)
if args.show:
return True

if check_qleverfile_exists(args.main_command_name):
return False

# Each step can override the values of the steps before it.
try:
qleverfile = Qleverfile.filter(
template_path, self.filter_criteria()
)
qleverfile.set("runtime", "IMAGE", self.image())
for section, options in self.engine_settings(args).items():
# Skip sections that the pre-configured Qleverfile lacks.
if qleverfile.has_section(section):
for option, value in options.items():
qleverfile.set(section, option, value)
for section, arg_name in self.override_args:
if arg_value := getattr(args, arg_name):
qleverfile.set(section, arg_name.upper(), str(arg_value))
with Path("Qleverfile").open("w") as qleverfile_file:
qleverfile.write(qleverfile_file)
except Exception as e:
log.error(f"Could not create the Qleverfile: {e}")
return False

log.info(
f'Created Qleverfile for config "{args.config_name}" in the '
"current directory"
)
return True
20 changes: 20 additions & 0 deletions src/qeval/base_commands/status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from __future__ import annotations

from abc import abstractmethod

from qlever.commands.status import StatusCommand as QleverStatusCommand


class BaseStatusCommand(QleverStatusCommand):
"""
Show the processes of an engine.
"""

@abstractmethod
def default_regex(self) -> str:
"""Regex for the command lines of the engine's processes."""

def description(self) -> str:
return (
"Show the processes of this graph database running on this machine"
)
36 changes: 36 additions & 0 deletions src/qeval/base_commands/stop.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from __future__ import annotations

from abc import abstractmethod

from qeval.base_commands.status import BaseStatusCommand
from qlever.commands.stop import StopCommand as QleverStopCommand


class BaseStopCommand(QleverStopCommand):
"""
Stop the server of an engine for a given dataset, like QLever's `stop`
but without systemd: stop its container if there is one, otherwise kill
the processes that match a regex.
"""

@abstractmethod
def default_regex(self) -> str:
"""
Regex for the command line of the engine's server, where `%%NAME%%`
stands for the dataset name.
"""

@abstractmethod
def status_command(self) -> BaseStatusCommand:
"""The engine's `status` command, shown when no server matches."""

@abstractmethod
def status_regex(self) -> str:
"""Regex for the command lines of all the engine's servers."""

def description(self) -> str:
return "Stop the server of this graph database for a given dataset"

def systemd_unit(self, name: str) -> str | None:
# Only QLever runs its server as a systemd unit so far.
return None
3 changes: 2 additions & 1 deletion src/qeval/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def parse_command_line() -> argparse.Namespace:
tool_description = (
f"{SCRIPT_NAME} sets up, indexes, queries, and benchmarks "
"graph databases in a uniform way. "
f"Supported engines: {supported_engines}"
f"Supported graph databases: {supported_engines}"
)
parser = argparse.ArgumentParser(
description=colored(tool_description, attrs=["bold"])
Expand Down Expand Up @@ -99,6 +99,7 @@ def parse_command_line() -> argparse.Namespace:
script_name=SCRIPT_NAME,
engine_short_name=engine,
engine_display_name=engine_info.display_name,
endpoint_path=engine_info.endpoint_path,
main_command_name=main_command_name,
)
subparsers = engine_parser.add_subparsers(
Expand Down
9 changes: 6 additions & 3 deletions src/qeval/engines.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@

class Engine(NamedTuple):
"""
The package with the commands of an engine, and the name of the engine as
shown to the user.
The package with the commands of an engine, the name of the engine as
shown to the user, and the path of its SPARQL endpoint on the server.
"""

package: str
display_name: str
endpoint_path: str


ENGINES = {
"qlever": Engine(package="qlever", display_name="QLever"),
"qlever": Engine(
package="qlever", display_name="QLever", endpoint_path="/"
),
}


Expand Down
32 changes: 23 additions & 9 deletions src/qlever/commands/benchmark_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,23 @@ def additional_arguments(self, subparser) -> None:
),
)

def index_stats_command(self) -> IndexStatsCommand:
"""The command that reads the index time and size of the engine."""
return IndexStatsCommand()

def can_clear_cache(self, args, engine: str | None) -> bool:
"""
Whether the cache can be cleared before each query. Only QLever can
do that, so guess from the endpoint and the result file name.
"""
is_qlever = (
not args.sparql_endpoint
or args.sparql_endpoint.startswith("https://qlever")
)
if engine is not None:
is_qlever = is_qlever or "qlever" in engine.lower()
return is_qlever

def execute(self, args) -> bool:
# We can't have both `--remove-offset-and-limit` and `--limit`.
if args.remove_offset_and_limit and args.limit:
Expand Down Expand Up @@ -821,14 +838,8 @@ def execute(self, args) -> bool:
return False

# Clear cache only works for QLever.
is_qlever = (
not args.sparql_endpoint
or args.sparql_endpoint.startswith("https://qlever")
)
if engine is not None:
is_qlever = is_qlever or "qlever" in engine.lower()
if args.clear_cache == "yes":
if is_qlever:
if self.can_clear_cache(args, engine):
log.warning(
"Clearing the cache before each query"
" (only works for QLever)"
Expand All @@ -845,7 +856,8 @@ def execute(self, args) -> bool:
f"curl -sv https://qlever.dev/api/examples/{args.ui_config}"
)
sparql_endpoint = (
args.sparql_endpoint or f"{args.host_name}:{args.port}"
args.sparql_endpoint
or f"{args.host_name}:{args.port}{args.endpoint_path}"
)

self.show(
Expand Down Expand Up @@ -909,7 +921,9 @@ def execute(self, args) -> bool:
if args.result_file:
result_yml_query_records["timeout"] = timeout

index_time, index_size = compute_index_stats(IndexStatsCommand())
index_time, index_size = compute_index_stats(
self.index_stats_command()
)
result_yml_query_records["index_time"] = index_time
result_yml_query_records["index_size"] = index_size

Expand Down
5 changes: 2 additions & 3 deletions src/qlever/commands/index_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,8 @@ def execute(self, args) -> bool:
# that messages about a missing or incomplete log appear below it.
if not args.only_space:
self.show(
f"Breakdown of the time used for "
f"building the index, based on the timestamps for key "
f'lines in "{log_file_name}"',
"Breakdown of the time used for building the index, "
f'based on key lines in "{log_file_name}"',
only_show=args.show,
)

Expand Down
Loading
Loading