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

georgia-tech-db / eva / b2a86723-af10-419d-b39f-db980c001926

25 Aug 2023 08:22PM UTC coverage: 93.727% (-3.0%) from 96.702%
b2a86723-af10-419d-b39f-db980c001926

push

circle-ci

gaurav274
fix user reference

10474 of 11175 relevant lines covered (93.73%)

0.94 hits per line

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

97.78
/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.
15
from typing import Iterator, Optional
1✔
16

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

30

31
def execute_query(
32
    evadb: EvaDBDatabase,
33
    query,
34
    report_time: bool = False,
35
    do_not_raise_exceptions: bool = False,
36
    do_not_print_exceptions: bool = False,
37
    **kwargs
38
) -> Iterator[Batch]:
39
    """
40
    Execute the query and return a result generator.
41
    """
42
    query_compile_time = Timer()
1✔
43
    plan_generator = kwargs.pop("plan_generator", PlanGenerator(evadb))
1✔
44
    with query_compile_time:
1✔
45
        stmt = Parser().parse(query)[0]
1✔
46

47
        # For certain statements, we plan to omit binder and optimizer to keep the code
48
        # clean. So, we handle such cases here and pass the statement directly to the
49
        # executor.
50
        if not isinstance(stmt, SKIP_BINDER_AND_OPTIMIZER_STATEMENTS):
1✔
51
            StatementBinder(StatementBinderContext(evadb.catalog)).bind(stmt)
1✔
52
            l_plan = StatementToPlanConverter().visit(stmt)
1✔
53
            p_plan = plan_generator.build(l_plan)
1✔
54
        else:
55
            p_plan = stmt
1✔
56
        output = PlanExecutor(evadb, p_plan).execute_plan(
57
            do_not_raise_exceptions, do_not_print_exceptions
58
        )
59

60
    if report_time is True:
1✔
61
        query_compile_time.log_elapsed_time("Query Compile Time")
×
62

63
    return output
1✔
64

65

66
def execute_query_fetch_all(
67
    evadb: EvaDBDatabase,
68
    query=None,
69
    report_time: bool = False,
70
    do_not_raise_exceptions: bool = False,
71
    do_not_print_exceptions: bool = False,
72
    **kwargs
73
) -> Optional[Batch]:
74
    """
75
    Execute the query and fetch all results into one Batch object.
76
    """
77
    output = execute_query(
78
        evadb,
79
        query,
80
        report_time,
81
        do_not_raise_exceptions,
82
        do_not_print_exceptions,
83
        **kwargs
84
    )
85
    if output:
1✔
86
        batch_list = list(output)
1✔
87
        return Batch.concat(batch_list, copy=False)
1✔
88

89

90
async def handle_request(evadb: EvaDBDatabase, client_writer, request_message):
1✔
91
    """
92
    Reads a request from a client and processes it
93

94
    If user inputs 'quit' stops the event loop
95
    otherwise just echoes user input
96
    """
97
    logger.debug("Receive request: --|" + str(request_message) + "|--")
1✔
98

99
    error = False
1✔
100
    error_msg = None
1✔
101
    query_runtime = Timer()
1✔
102
    with query_runtime:
1✔
103
        try:
1✔
104
            output_batch = execute_query_fetch_all(evadb, request_message)
1✔
105
        except Exception as e:
106
            error_msg = str(e)
107
            logger.exception(error_msg)
108
            error = True
109

110
    if not error:
1✔
111
        response = Response(
1✔
112
            status=ResponseStatus.SUCCESS,
113
            batch=output_batch,
114
            query_time=query_runtime.total_elapsed_time,
115
        )
116
    else:
117
        response = Response(
1✔
118
            status=ResponseStatus.FAIL,
119
            batch=None,
120
            error=error_msg,
121
        )
122

123
    query_runtime.log_elapsed_time("Query Response Time")
1✔
124

125
    logger.debug(response)
1✔
126

127
    response_data = Response.serialize(response)
1✔
128

129
    client_writer.write(b"%d\n" % len(response_data))
1✔
130
    client_writer.write(response_data)
1✔
131

132
    return response
1✔
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