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

temporarily completely removing caching feature on SELECT #164

Merged
merged 1 commit into from
Oct 24, 2024
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
24 changes: 12 additions & 12 deletions jupyterlab_sql_editor/ipython_magic/sparksql/sparksql.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
pass

import pandas as pd
import sqlparse
from IPython import get_ipython
from IPython.core.magic import (
line_cell_magic,
Expand Down Expand Up @@ -127,7 +126,6 @@ def __init__(self, shell=None, **kwargs):
action="store_true",
help="Detailed information about SparkSQL magic",
)
@argument("--nocache", action="store_true", help="Do not use cache for SELECT statements")
@argument("--jsonnulls", action="store_true", help="Show nulls for JSON output")
def sparksql(self, line=None, cell=None, local_ns=None):
"Magic that works both as %sparksql and as %%sparksql"
Expand Down Expand Up @@ -211,18 +209,20 @@ def sparksql(self, line=None, cell=None, local_ns=None):
elif output == "sql":
return self.display_sql(sql)

sql_statement = sqlparse.format(sql, strip_comments=True)
parsed = sqlparse.parse(sql_statement.strip(" \t\n;"))
# TODO: Rework caching feature
# sql_statement = sqlparse.format(sql, strip_comments=True)
# parsed = sqlparse.parse(sql_statement.strip(" \t\n;"))

# Use previously cached results if sql statement hasn't changed and is a SELECT type statement
use_cache = (
True
if not args.nocache
and sql == self.cached_sql
and limit == self.cached_limit
and parsed[0].get_type() == "SELECT"
else False
)
# use_cache = (
# True
# if not args.nocache
# and sql == self.cached_sql
# and limit == self.cached_limit
# and parsed[0].get_type() == "SELECT"
# else False
# )
use_cache = False
if use_cache:
print("Using cached results")

Expand Down
5 changes: 3 additions & 2 deletions jupyterlab_sql_editor/ipython_magic/trino/trino.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ def __init__(self, shell=None, **kwargs):
action="store_true",
help="Detailed information about Trino magic",
)
@argument("--nocache", action="store_true", help="Do not use cache for SELECT statements")
@argument("--jsonnulls", action="store_true", help="Show nulls for JSON output")
def trino(self, line=None, cell=None, local_ns=None):
"Magic that works both as %trino and as %%trino"
Expand Down Expand Up @@ -197,8 +196,10 @@ def trino(self, line=None, cell=None, local_ns=None):
if not args.raw and not sql_lim and parsed[0].get_type() == "SELECT":
sql = f"{sql} \nLIMIT {limit+1}"

# TODO: Rework caching feature
# Use previously cached results if sql statement hasn't changed and is a SELECT type statement
use_cache = True if not args.nocache and sql == self.cached_sql and parsed[0].get_type() == "SELECT" else False
# use_cache = True if not args.nocache and sql == self.cached_sql and parsed[0].get_type() == "SELECT" else False
use_cache = False
if use_cache:
print("Using cached results")

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jupyterlab-sql-editor",
"version": "1.1.3",
"version": "1.2.0",
"description": "SQL editor support for formatting, syntax highlighting and code completion of SQL in cell magic, line magic, python string and file editor.",
"keywords": [
"jupyter",
Expand Down
Loading