Skip to content

Commit

Permalink
Merge pull request #11 from yugabyte/configuration-report
Browse files Browse the repository at this point in the history
Configuration reporting for all reports
  • Loading branch information
qvad authored May 19, 2023
2 parents 00b05db + 94ea070 commit d7be9ae
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 36 deletions.
8 changes: 4 additions & 4 deletions src/db/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from config import Config, ConnectionConfig, DDLStep
from objects import Query, EPNode, ExecutionPlan, ListOfOptimizations, Table, Optimization, \
ListOfQueries, ResultsLoader
CollectResult, ResultsLoader
from db.database import Database
from utils import evaluate_sql, allowed_diff

Expand Down Expand Up @@ -73,7 +73,7 @@ def get_results_loader(self):
return PostgresResultsLoader()

def get_list_queries(self):
return PostgresListOfQueries()
return PostgresCollectResult()


class Connection:
Expand Down Expand Up @@ -447,12 +447,12 @@ def add_optimization(self, explain_hints, optimizations):
)


class PostgresListOfQueries(ListOfQueries):
class PostgresCollectResult(CollectResult):
queries: List[PostgresQuery] = None


class PostgresResultsLoader(ResultsLoader):

def __init__(self):
super().__init__()
self.clazz = PostgresListOfQueries
self.clazz = PostgresCollectResult
6 changes: 3 additions & 3 deletions src/db/yugabyte.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from config import ConnectionConfig
from db.postgres import Postgres, PostgresExecutionPlan, PLAN_TREE_CLEANUP, PostgresQuery
from objects import ExecutionPlan, ListOfQueries, ResultsLoader
from objects import ExecutionPlan, CollectResult, ResultsLoader
from utils import evaluate_sql

DEFAULT_USERNAME = 'yugabyte'
Expand Down Expand Up @@ -297,12 +297,12 @@ def stop_database(self):
shell=True)


class YugabyteListOfQueries(ListOfQueries):
class YugabyteCollectResult(CollectResult):
queries: List[YugabyteQuery] = None


class YugabyteResultsLoader(ResultsLoader):

def __init__(self):
super().__init__()
self.clazz = YugabyteListOfQueries
self.clazz = YugabyteCollectResult
9 changes: 5 additions & 4 deletions src/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ class Optimization(Query):


@dataclasses.dataclass
class ListOfQueries:
class CollectResult:
db_version: str = ""
git_message: str = ""
config: str = ""
model_queries: List[str] = None
queries: List[Type[Query]] = None

Expand All @@ -93,7 +94,7 @@ def append(self, new_element):
else:
self.queries.append(new_element)

# CPUs are cheap in 2022
# CPUs are cheap
self.queries.sort(key=lambda q: q.query_hash)


Expand Down Expand Up @@ -158,13 +159,13 @@ def default(self, o):
class ResultsLoader:

def __init__(self):
self.clazz = ListOfQueries
self.clazz = CollectResult

def get_queries_from_previous_result(self, previous_execution_path):
with open(previous_execution_path, "r") as prev_result:
return from_dict(self.clazz, json.load(prev_result), DaciteConfig(check_types=False))

def store_queries_to_file(self, queries: Type[ListOfQueries], output_json_name: str):
def store_queries_to_file(self, queries: Type[CollectResult], output_json_name: str):
if not os.path.isdir("report"):
os.mkdir("report")

Expand Down
10 changes: 9 additions & 1 deletion src/reports/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(self):
f":source-highlighter: coderay\n" \
f":coderay-linenums-mode: inline\n\n"

self._start_collapsible("Configuration")
self._start_collapsible("Reporting configuration")
self._start_source()
self.report += str(self.config)
self._end_source()
Expand Down Expand Up @@ -50,6 +50,14 @@ def report_model(self, model_queries):
self._end_source()
self._end_collapsible()

def report_config(self, config, collapsible_name):
if config:
self._start_collapsible(f"Collect configuration {collapsible_name}")
self._start_source(["sql"])
self.report += config
self._end_source()
self._end_collapsible()

def _add_double_newline(self):
self.report += "\n\n"

Expand Down
8 changes: 5 additions & 3 deletions src/reports/adoc/comparison.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from sql_formatter.core import format_sql

from objects import ListOfQueries, Query
from objects import CollectResult, Query
from reports.abstract import Report


Expand All @@ -12,12 +12,14 @@ def __init__(self):

@classmethod
def generate_report(cls,
loq_yb: ListOfQueries,
loq_pg: ListOfQueries):
loq_yb: CollectResult,
loq_pg: CollectResult):
report = ComparisonReport()

report.define_version(loq_yb.db_version, loq_pg.db_version)
report.report_model(loq_yb.model_queries)
report.report_config(loq_yb.config, "YB")
report.report_config(loq_pg.config, "PG")

for query in zip(loq_yb.queries, loq_pg.queries):
report.add_query(*query)
Expand Down
8 changes: 5 additions & 3 deletions src/reports/adoc/regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from sql_formatter.core import format_sql

from objects import ListOfQueries, Query
from objects import CollectResult, Query
from reports.abstract import Report


Expand All @@ -28,13 +28,15 @@ def __init__(self):
def generate_report(cls,
v1_name: str,
v2_name: str,
loq_v1: ListOfQueries,
loq_v2: ListOfQueries):
loq_v1: CollectResult,
loq_v2: CollectResult):
report = RegressionReport()

report.define_version_names(v1_name, v2_name)
report.define_version(loq_v1.db_version, loq_v2.db_version)
report.report_model(loq_v1.model_queries)
report.report_config(loq_v1.config, "YB")
report.report_config(loq_v2.config, "PG")

for query in zip(loq_v1.queries, loq_v2.queries):
if query[0].query_hash != query[1].query_hash:
Expand Down
6 changes: 4 additions & 2 deletions src/reports/adoc/score.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from matplotlib import rcParams
from sql_formatter.core import format_sql

from objects import ListOfQueries, Query
from objects import CollectResult, Query
from reports.abstract import Report
from utils import allowed_diff

Expand All @@ -26,11 +26,13 @@ def __init__(self):
}

@classmethod
def generate_report(cls, loq: ListOfQueries, pg_loq: ListOfQueries = None):
def generate_report(cls, loq: CollectResult, pg_loq: CollectResult = None):
report = ScoreReport()

report.define_version(loq.db_version)
report.report_model(loq.model_queries)
report.report_config(loq.config, "YB")
report.report_config(pg_loq.config, "PG")

for qid, query in enumerate(loq.queries):
report.add_query(query, pg_loq.queries[qid] if pg_loq else None)
Expand Down
14 changes: 7 additions & 7 deletions src/reports/adoc/selectivity.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from sql_formatter.core import format_sql

from objects import ListOfQueries, Query
from objects import CollectResult, Query
from reports.abstract import Report
from utils import allowed_diff

Expand All @@ -20,12 +20,12 @@ def get_report_name(self):

@classmethod
def generate_report(cls,
loq_default: ListOfQueries,
loq_default_analyze: ListOfQueries,
loq_ta: ListOfQueries,
loq_ta_analyze: ListOfQueries,
loq_stats: ListOfQueries,
loq_stats_analyze: ListOfQueries):
loq_default: CollectResult,
loq_default_analyze: CollectResult,
loq_ta: CollectResult,
loq_ta_analyze: CollectResult,
loq_stats: CollectResult,
loq_stats_analyze: CollectResult):
report = SelectivityReport()

report.report_model(loq_default.model_queries)
Expand Down
6 changes: 4 additions & 2 deletions src/reports/adoc/taqo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from matplotlib import pyplot as plt
from sql_formatter.core import format_sql

from objects import ListOfQueries, Query
from objects import CollectResult, Query
from reports.abstract import Report
from utils import allowed_diff

Expand All @@ -22,11 +22,13 @@ def __init__(self):
self.better_plan_found = []

@classmethod
def generate_report(cls, loq: ListOfQueries, pg_loq: ListOfQueries = None):
def generate_report(cls, loq: CollectResult, pg_loq: CollectResult = None):
report = TaqoReport()

report.define_version(loq.db_version)
report.report_model(loq.model_queries)
report.report_config(loq.config, "YB")
report.report_config(pg_loq.config, "PG")

for qid, query in enumerate(loq.queries):
report.add_query(query, pg_loq.queries[qid] if pg_loq else None)
Expand Down
4 changes: 2 additions & 2 deletions src/reports/xls/regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from sql_formatter.core import format_sql

from objects import ListOfQueries, Query
from objects import CollectResult, Query
from reports.abstract import Report


Expand All @@ -15,7 +15,7 @@ def __init__(self):
self.queries = {}

@classmethod
def generate_report(cls, first_loq: ListOfQueries, second_loq: ListOfQueries):
def generate_report(cls, first_loq: CollectResult, second_loq: CollectResult):
report = RegressionXlsReport()

for qid, query in enumerate(first_loq.queries):
Expand Down
4 changes: 2 additions & 2 deletions src/reports/xls/score.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from matplotlib import pyplot as plt
from sql_formatter.core import format_sql

from objects import ListOfQueries, Query
from objects import CollectResult, Query
from db.postgres import PostgresQuery
from reports.abstract import Report

Expand All @@ -17,7 +17,7 @@ def __init__(self):
self.queries = {}

@classmethod
def generate_report(cls, loq: ListOfQueries, pg_loq: ListOfQueries = None):
def generate_report(cls, loq: CollectResult, pg_loq: CollectResult = None):
report = ScoreXlsReport()

for qid, query in enumerate(loq.queries):
Expand Down
3 changes: 1 addition & 2 deletions src/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def evaluate(self):
loq.model_queries, loq.queries = self.run_ddl_and_testing_queries(
self.sut_database.connection.conn, self.config.with_optimizations)
loq.git_message = commit_message
loq.config = str(self.config)

self.logger.info(f"Storing results to report/{self.config.output}")
loader.store_queries_to_file(loq, self.config.output)
Expand All @@ -62,8 +63,6 @@ def evaluate(self):
def run_ddl_and_testing_queries(self,
connection,
evaluate_optimizations=False):
queries = []
model_queries = []
try:
model = get_test_model()
created_tables, model_queries = model.create_tables(connection)
Expand Down
2 changes: 1 addition & 1 deletion src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def allowed_diff(config, original_execution_time, optimization_execution_time):


def get_md5(string: str):
return str(hashlib.md5(string.encode('utf-8')).hexdigest())
return hashlib.md5(string.encode('utf-8')).hexdigest()


def get_bool_from_str(string: str):
Expand Down

0 comments on commit d7be9ae

Please sign in to comment.