Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 0.8.1 #332

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mindsdb_sql/__about__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
__title__ = 'mindsdb_sql'
__package_name__ = 'mindsdb_sql'
__version__ = '0.8.0'
__version__ = '0.8.1'
__description__ = "Pure python SQL parser"
__email__ = "[email protected]"
__author__ = 'MindsDB Inc'
Expand Down
10 changes: 5 additions & 5 deletions mindsdb_sql/parser/dialects/mindsdb/knowledge_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class CreateKnowledgeBase(ASTNode):
def __init__(
self,
name,
model,
model=None,
storage=None,
from_select=None,
params=None,
Expand Down Expand Up @@ -37,13 +37,13 @@ def __init__(
def to_tree(self, *args, level=0, **kwargs):
ind = indent(level)
storage_str = f"{ind} storage={self.storage.to_string()},\n" if self.storage else ""
model_str = f"{ind} model={self.model.to_string()},\n" if self.model else ""
out_str = f"""
{ind}CreateKnowledgeBase(
{ind} if_not_exists={self.if_not_exists},
{ind} name={self.name.to_string()},
{ind} from_query={self.from_query.to_tree(level=level + 1) if self.from_query else None},
{ind} model={self.model.to_string()},
{storage_str}{ind} params={self.params}
{model_str}{storage_str}{ind} params={self.params}
{ind})
"""
return out_str
Expand All @@ -56,13 +56,13 @@ def get_string(self, *args, **kwargs):
f"FROM ({self.from_query.get_string()})" if self.from_query else ""
)
storage_str = f" STORAGE = {self.storage.to_string()}" if self.storage else ""
model_str = f" MODEL = {self.model.to_string()},\n" if self.model else ""

out_str = (
f"CREATE KNOWLEDGE_BASE {'IF NOT EXISTS' if self.if_not_exists else ''}{self.name.to_string()} "
f"{from_query_str} "
f"USING {using_str},"
f" MODEL = {self.model.to_string()}, "
f"{storage_str}"
f"{model_str}{storage_str}"
)

return out_str
Expand Down
8 changes: 3 additions & 5 deletions mindsdb_sql/parser/dialects/mindsdb/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,9 @@ def create_kb(self, p):
# convert to identifier
storage = Identifier(storage)

if not model:
if isinstance(model, str):
# convert to identifier
model = Identifier(model)
raise ParsingException('Missing model parameter')
if isinstance(model, str):
# convert to identifier
model = Identifier(model)

if_not_exists = p.if_not_exists_or_empty

Expand Down
36 changes: 31 additions & 5 deletions tests/test_parser/test_mindsdb/test_knowledgebase.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
)


def test_create_knowledeg_base():
def test_create_knowledge_base():
# create without select
sql = """
CREATE KNOWLEDGE_BASE my_knowledge_base
Expand Down Expand Up @@ -94,15 +94,24 @@ def test_create_knowledeg_base():
assert ast == expected_ast

# create without MODEL
# TODO: this should be an error
# we may allow this in the future when we have a default model
sql = """
CREATE KNOWLEDGE_BASE my_knowledge_base
USING
STORAGE = my_vector_database.some_table
"""
with pytest.raises(Exception):
ast = parse_sql(sql, dialect="mindsdb")

expected_ast = CreateKnowledgeBase(
name=Identifier("my_knowledge_base"),
if_not_exists=False,
model=None,
storage=Identifier(parts=["my_vector_database", "some_table"]),
from_select=None,
params={},
)

ast = parse_sql(sql, dialect="mindsdb")

assert ast == expected_ast

# create without STORAGE
sql = """
Expand Down Expand Up @@ -141,6 +150,23 @@ def test_create_knowledeg_base():
)
assert ast == expected_ast

# create without USING ie no storage or model
# todo currently this is not supported by the parser

# sql = """
# CREATE KNOWLEDGE_BASE my_knowledge_base;
# """
# ast = parse_sql(sql, dialect="mindsdb")
# expected_ast = CreateKnowledgeBase(
# name=Identifier("my_knowledge_base"),
# if_not_exists=False,
# model=None,
# storage=None,
# from_select=None,
# params={},
# )
# assert ast == expected_ast

# create with params
sql = """
CREATE KNOWLEDGE_BASE my_knowledge_base
Expand Down