Skip to content

Commit

Permalink
fix: motif_mining query (#913)
Browse files Browse the repository at this point in the history
This PR deprecates CREATE MATERIALIZE VIEW query from motif planning
notebook
  • Loading branch information
yulaicui authored Jun 30, 2023
1 parent b574fd7 commit 65bea12
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 7 deletions.
5 changes: 4 additions & 1 deletion evadb/optimizer/rules/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from evadb.optimizer.rules.rules_base import Promise, Rule, RuleType
from evadb.parser.types import JoinType, ParserOrderBySortType
from evadb.plan_nodes.apply_and_merge_plan import ApplyAndMergePlan
from evadb.plan_nodes.create_from_select_plan import CreateFromSelectPlan
from evadb.plan_nodes.exchange_plan import ExchangePlan
from evadb.plan_nodes.explain_plan import ExplainPlan
from evadb.plan_nodes.hash_join_build_plan import HashJoinBuildPlan
Expand Down Expand Up @@ -716,7 +717,9 @@ def check(self, before: Operator, context: OptimizerContext):
return True

def apply(self, before: LogicalCreate, context: OptimizerContext):
after = CreatePlan(before.video, before.column_list, before.if_not_exists)
after = CreateFromSelectPlan(
before.video, before.column_list, before.if_not_exists
)
for child in before.children:
after.append_child(child)
yield after
Expand Down
71 changes: 71 additions & 0 deletions evadb/plan_nodes/create_from_select_plan.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# coding=utf-8
# Copyright 2018-2023 EvaDB
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import List

from evadb.parser.create_statement import ColumnDefinition
from evadb.parser.table_ref import TableInfo
from evadb.plan_nodes.abstract_plan import AbstractPlan
from evadb.plan_nodes.types import PlanOprType


class CreateFromSelectPlan(AbstractPlan):
"""
This plan is used for storing information required for creating
a table from select query.
Arguments:
table_info {TableInfo} -- table info for view to be created in storage
col_list{List[ColumnDefinition]} -- column names in the view
if_not_exists {bool} -- Whether to override if there is existing view
"""

def __init__(
self,
table_info: TableInfo,
column_list: List[ColumnDefinition],
if_not_exists: bool = False,
):
super().__init__(PlanOprType.CREATE)
self._table_info = table_info
self._column_list = column_list
self._if_not_exists = if_not_exists

@property
def table_info(self):
return self._table_info

@property
def if_not_exists(self):
return self._if_not_exists

@property
def column_list(self):
return self._column_list

def __str__(self):
return "CreateFromSelectPlan(table_info={}, \
column_lists={}, \
if_not_exists={})".format(
self._table_info, self._column_list, self._if_not_exists
)

def __hash__(self) -> int:
return hash(
(
super().__hash__(),
self.table_info,
self.if_not_exists,
tuple(self.column_list),
)
)
5 changes: 3 additions & 2 deletions evadb/udfs/chatgpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"gpt-3.5-turbo-0301",
]


class ChatGPT(AbstractUDF):
"""
Arguments:
Expand Down Expand Up @@ -62,12 +63,12 @@ class ChatGPT(AbstractUDF):
In the above UDF invocation, the 'query' passed would be the user task to generate video summaries, and the
'content' passed would be the video transcripts that need to be used in order to generate the summary. Since
no prompt is passed, the default system prompt will be used.
Now assume the user wants to create the video summary in 50 words and in French. Instead of passing these instructions
along with each query, a prompt can be set as such:
prompt = "Generate your responses in 50 words or less. Also, generate the response in French."
cursor.table("video_transcripts").select(f"ChatGPT({question}, text, {prompt})")
cursor.table("video_transcripts").select(f"ChatGPT({question}, text, {prompt})")
In the above invocation, an additional argument is passed as prompt. While the query and content arguments remain
the same, the 'prompt' argument will be set as a system message in model params.
Expand Down
2 changes: 1 addition & 1 deletion script/test/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ fi

if [[ ( "$OSTYPE" != "msys" ) && ( "$MODE" = "NOTEBOOK" || "$MODE" = "ALL" ) ]];
then
PYTHONPATH=./ python -m pytest --durations=5 --nbmake --overwrite "./tutorials" --capture=sys --tb=short -v --log-level=WARNING --nbmake-timeout=3000 --ignore="tutorials/11-similarity-search-for-motif-mining.ipynb"
PYTHONPATH=./ python -m pytest --durations=5 --nbmake --overwrite "./tutorials" --capture=sys --tb=short -v --log-level=WARNING --nbmake-timeout=3000
notebook_test_code=$?
if [ "$notebook_test_code" != "0" ];
then
Expand Down
5 changes: 2 additions & 3 deletions tutorials/11-similarity-search-for-motif-mining.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -776,10 +776,9 @@
"source": [
"cursor.drop_table(\"reddit_object_table\").df()\n",
"create_index_query = \"\"\"\n",
" CREATE MATERIALIZED VIEW IF NOT EXISTS \n",
" reddit_object_table (name, data, bboxes,labels)\n",
" CREATE TABLE IF NOT EXISTS reddit_object_table\n",
" AS SELECT name, data, bboxes, labels FROM reddit_dataset\n",
" JOIN LATERAL UNNEST(Yolo(data)) AS Obj(labels, bboxes, scores)\"\"\"\n",
" JOIN LATERAL UNNEST(Yolo(data)) AS Obj(labels, bboxes, scores);\"\"\"\n",
"cursor.query(create_index_query).df()"
]
},
Expand Down

0 comments on commit 65bea12

Please sign in to comment.