• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

georgia-tech-db / eva / #850

08 Nov 2023 08:36PM UTC coverage: 0.0% (-77.0%) from 76.982%
#850

push

circleci

americast
fix metrics logic

0 of 1 new or added line in 1 file covered. (0.0%)

9789 existing lines in 252 files now uncovered.

0 of 12428 relevant lines covered (0.0%)

0.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/evadb/server/command_handler.py
1
# coding=utf-8
2
# Copyright 2018-2023 EvaDB
3
#
4
# Licensed under the Apache License, Version 2.0 (the "License");
5
# you may not use this file except in compliance with the License.
6
# You may obtain a copy of the License at
7
#
8
#     http://www.apache.org/licenses/LICENSE-2.0
9
#
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
# See the License for the specific language governing permissions and
14
# limitations under the License.
UNCOV
15
from typing import Iterator, Optional
×
16

UNCOV
17
from evadb.binder.statement_binder import StatementBinder
×
UNCOV
18
from evadb.binder.statement_binder_context import StatementBinderContext
×
UNCOV
19
from evadb.database import EvaDBDatabase
×
UNCOV
20
from evadb.executor.plan_executor import PlanExecutor
×
UNCOV
21
from evadb.models.server.response import Response, ResponseStatus
×
UNCOV
22
from evadb.models.storage.batch import Batch
×
UNCOV
23
from evadb.optimizer.plan_generator import PlanGenerator
×
UNCOV
24
from evadb.optimizer.statement_to_opr_converter import StatementToPlanConverter
×
UNCOV
25
from evadb.parser.parser import Parser
×
UNCOV
26
from evadb.parser.statement import AbstractStatement
×
UNCOV
27
from evadb.parser.utils import SKIP_BINDER_AND_OPTIMIZER_STATEMENTS
×
UNCOV
28
from evadb.utils.logging_manager import logger
×
UNCOV
29
from evadb.utils.stats import Timer
×
30

31

32
def execute_statement(
33
    evadb: EvaDBDatabase,
34
    stmt: AbstractStatement,
35
    do_not_raise_exceptions: bool = False,
36
    do_not_print_exceptions: bool = False,
37
    **kwargs
38
) -> Iterator[Batch]:
39
    # For certain statements, we plan to omit binder and optimizer to keep the code
40
    # clean. So, we handle such cases here and pass the statement directly to the
41
    # executor.
UNCOV
42
    plan_generator = kwargs.get("plan_generator", PlanGenerator(evadb))
×
UNCOV
43
    if not isinstance(stmt, SKIP_BINDER_AND_OPTIMIZER_STATEMENTS):
×
UNCOV
44
        StatementBinder(StatementBinderContext(evadb.catalog)).bind(stmt)
×
UNCOV
45
        logical_plan = StatementToPlanConverter().visit(stmt)
×
UNCOV
46
        physical_plan = plan_generator.build(logical_plan)
×
47
    else:
UNCOV
48
        physical_plan = stmt
×
49
    output = PlanExecutor(evadb, physical_plan).execute_plan(
50
        do_not_raise_exceptions, do_not_print_exceptions
51
    )
UNCOV
52
    if output:
×
UNCOV
53
        batch_list = list(output)
×
UNCOV
54
        return Batch.concat(batch_list, copy=False)
×
55

56

57
def execute_query(
58
    evadb: EvaDBDatabase,
59
    query,
60
    report_time: bool = False,
61
    do_not_raise_exceptions: bool = False,
62
    do_not_print_exceptions: bool = False,
63
    **kwargs
64
) -> Iterator[Batch]:
65
    """
66
    Execute the query and return a result generator.
67
    """
UNCOV
68
    query_compile_time = Timer()
×
69

UNCOV
70
    with query_compile_time:
×
UNCOV
71
        stmt = Parser().parse(query)[0]
×
72
        res_batch = execute_statement(
73
            evadb, stmt, do_not_raise_exceptions, do_not_print_exceptions, **kwargs
74
        )
75

UNCOV
76
    if report_time is True:
×
77
        query_compile_time.log_elapsed_time("Query Compile Time")
×
78

UNCOV
79
    return res_batch
×
80

81

82
def execute_query_fetch_all(
83
    evadb: EvaDBDatabase,
84
    query=None,
85
    report_time: bool = False,
86
    do_not_raise_exceptions: bool = False,
87
    do_not_print_exceptions: bool = False,
88
    **kwargs
89
) -> Optional[Batch]:
90
    """
91
    Execute the query and fetch all results into one Batch object.
92
    """
93
    res_batch = execute_query(
94
        evadb,
95
        query,
96
        report_time,
97
        do_not_raise_exceptions,
98
        do_not_print_exceptions,
99
        **kwargs
100
    )
UNCOV
101
    return res_batch
×
102

103

UNCOV
104
async def handle_request(evadb: EvaDBDatabase, client_writer, request_message):
×
105
    """
106
    Reads a request from a client and processes it
107

108
    If user inputs 'quit' stops the event loop
109
    otherwise just echoes user input
110
    """
UNCOV
111
    logger.debug("Receive request: --|" + str(request_message) + "|--")
×
112

UNCOV
113
    error = False
×
UNCOV
114
    error_msg = None
×
UNCOV
115
    query_runtime = Timer()
×
UNCOV
116
    with query_runtime:
×
UNCOV
117
        try:
×
UNCOV
118
            output_batch = execute_query_fetch_all(evadb, request_message)
×
119
        except Exception as e:
120
            error_msg = str(e)
121
            logger.exception(error_msg)
122
            error = True
123

UNCOV
124
    if not error:
×
UNCOV
125
        response = Response(
×
126
            status=ResponseStatus.SUCCESS,
127
            batch=output_batch,
128
            query_time=query_runtime.total_elapsed_time,
129
        )
130
    else:
UNCOV
131
        response = Response(
×
132
            status=ResponseStatus.FAIL,
133
            batch=None,
134
            error=error_msg,
135
        )
136

UNCOV
137
    query_runtime.log_elapsed_time("Query Response Time")
×
138

UNCOV
139
    logger.debug(response)
×
140

UNCOV
141
    response_data = Response.serialize(response)
×
142

UNCOV
143
    client_writer.write(b"%d\n" % len(response_data))
×
UNCOV
144
    client_writer.write(response_data)
×
145

UNCOV
146
    return response
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc