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

Morry98 / sql-query-parser / 8096033456

25 Apr 2022 04:52PM UTC coverage: 54.854%. Remained the same
8096033456

push

github

Morry98
code-checks add workflow_dispatch

(cherry picked from commit 54d394370)

469 of 855 relevant lines covered (54.85%)

0.55 hits per line

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

0.0
/sql_query_parser/general_purpose/from_table.py
1
from typing import Tuple, Optional
×
2

3
from sql_query_parser.configurations import Configurations
×
4
from sql_query_parser.table import Table
×
5

6

7
def compute(
×
8
        word: str,
9
        config: Configurations
10
) -> Tuple[bool, Configurations]:
11
    if (len(config.keywords) > 0 and config.keywords[-1] == "from") or (
×
12
            len(config.keywords) > 1 and config.keywords[-2] == "from" and config.keywords[-1] == "as"):
13
        if "as" in word:
×
14
            config.add_keyword("as")
×
15
        else:
16
            if config.keywords[-1] == "as":
×
17
                __add_table_to_query(config=config, alias=word)
×
18
                config.pop_last_keyword()
×
19
            elif "," in word:
×
20
                word = word[:-1]
×
21
                config.add_parsing_value(parsing_value=(word, None))
×
22
                __add_table_to_query(config=config)
×
23
                config.pop_last_parsing_value()
×
24
            else:
25
                if len(config.parsing_value) > 0:
×
26
                    raise Exception(f"Parsing value already present when parsing from table with alias,"
×
27
                                    f" this case is not implemented. "
28
                                    f"table= {word}  parsing_values= {config.parsing_value}")
29
                config.add_parsing_value(parsing_value=(word, None))
×
30
        return True, config
×
31
    return False, config
×
32

33

34
def __add_table_to_query(
×
35
        config: Configurations,
36
        alias: Optional[str] = None
37
) -> None:
38
    parsing_table = config.pop_last_parsing_value()
×
39
    table_str = parsing_table[0]
×
40
    if alias is None:
×
41
        config.add_parsing_value(parsing_value=parsing_table)
×
42
        alias = parsing_table[1]
×
43
    elif parsing_table[1] is not None:
×
44
        raise Exception(f"Double alias for {table_str} table: {parsing_table[1]} and {alias}")
×
45
    alias = alias.replace(",", "") if alias is not None else None
×
46
    table_by_name = config.query.get_table_by_name_or_alias(table_str)
×
47
    table_by_alias = config.query.get_table_by_name_or_alias(alias)
×
48
    if table_by_name is not None and table_by_alias is not None:
×
49
        raise Exception(f"Found double table object for table {table_str} alias {alias}")
×
50
    table = table_by_alias if table_by_alias is not None else table_by_name
×
51
    if table is None and alias is not None:
×
52
        table = Table(alias=alias)
×
53
        config.query.add_table(table)
×
54
    elif table is None:
×
55
        raise ValueError("Null Table name and alias")
×
56
    table.name = table_str
×
57
    table.alias = alias if alias is not None else table.name
×
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

© 2026 Coveralls, Inc