Skip to content

Commit

Permalink
support select star
Browse files Browse the repository at this point in the history
  • Loading branch information
jychen7 committed Jan 28, 2022
1 parent c55d7cb commit 220f2f0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
2 changes: 2 additions & 0 deletions bigtableql/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
RESERVED_ROWKEY = "_row_key"
RESERVED_TIMESTAMP = "_timestamp"
DEFAULT_SEPARATOR = "#"

SELECT_STAR = "Wildcard"
19 changes: 13 additions & 6 deletions bigtableql/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
import pyarrow
from typing import List
from bigtableql import parser, composer, scanner, executor
from bigtableql import RESERVED_ROWKEY, RESERVED_TIMESTAMP, DEFAULT_SEPARATOR
from bigtableql import (
RESERVED_ROWKEY,
RESERVED_TIMESTAMP,
DEFAULT_SEPARATOR,
SELECT_STAR,
)


class Client:
Expand Down Expand Up @@ -52,13 +57,15 @@ def query(self, column_family_id: str, sql: str) -> List[pyarrow.RecordBatch]:

row_key_identifiers = table_catalog["row_key_identifiers"]
non_qualifiers = set(row_key_identifiers) | {RESERVED_TIMESTAMP}
qualifiers = (projection | selection) - non_qualifiers

columns = table_catalog["column_families"][column_family_id]["columns"].keys()
if SELECT_STAR in projection:
qualifiers = set(columns)
else:
qualifiers = (projection | selection) - non_qualifiers

for qualifier in qualifiers:
if (
qualifier
not in table_catalog["column_families"][column_family_id]["columns"]
):
if qualifier not in columns:
raise Exception(
f"table {table_name}, column_family {column_family_id}: {qualifier} not found"
)
Expand Down
6 changes: 5 additions & 1 deletion bigtableql/parser.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import sqloxide
import functools
from typing import Tuple
from bigtableql import SELECT_STAR

BINARY_OPERATION = "BinaryOp"
FUNCTION_OPERATION = "Function"
Expand Down Expand Up @@ -38,7 +39,10 @@ def _parse_table_name(select_from) -> str:
return select_from[0]["relation"]["Table"]["name"][0]["value"]


def _parse_projection(select_projection) -> set:
def _parse_projection(select_projection: list) -> set:
if SELECT_STAR in select_projection:
return {SELECT_STAR}

projection = [
[
_parse_identifier_key(arg["Unnamed"])
Expand Down
8 changes: 8 additions & 0 deletions tests/sql.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@
- {"_row_key": ["abc"]}
compose_success:
- "abc"
- sql: select *, age from users where "_row_key" = 'abc'
parse_success:
- "users"
- ["Wildcard"]
- ["_row_key"]
- {"_row_key": ["abc"]}
compose_success:
- "abc"
- sql: select age from users where "_row_key" = 'abc' and gender = 'M'
parse_success:
- "users"
Expand Down

0 comments on commit 220f2f0

Please sign in to comment.