A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
cache parsed SQL statements (#1820)
Akshay Agrawal8b29453427fa
diff --git a/marimo/_ast/cell.py b/marimo/_ast/cell.pyindex 711ea5a31a..c1c2451f23 100644--- a/marimo/_ast/cell.py+++ b/marimo/_ast/cell.py@@ -86,6 +86,11 @@ class CellOutput:output: Any = None+class ParsedSQLStatements:+ parsed: Optional[list[str]] = None++@dataclasses.dataclass(frozen=True)class CellImpl:# hash of code@@ -111,6 +116,10 @@ class CellImpl:_stale: CellStaleState = dataclasses.field(default_factory=CellStaleState)# cells can optionally hold a reference to their output_output: CellOutput = dataclasses.field(default_factory=CellOutput)+ # parsed sql statements+ _sqls: ParsedSQLStatements = dataclasses.field(+ default_factory=ParsedSQLStatements+ )def configure(self, update: dict[str, Any] | CellConfig) -> CellImpl:"""Update the cell config.@@ -127,13 +136,18 @@ class CellImpl:@propertydef sqls(self) -> list[str]:"""Return a list of SQL statements for this cell."""+ if self._sqls.parsed is not None:+ return self._sqls.parsed+try:visitor = SQLVisitor()visitor.visit(ast.parse(self.code))sqls = visitor.get_sqls()- return sqls+ self._sqls.parsed = sqlsexcept Exception:- return []+ self._sqls.parsed = []++ return self._sqls.parsed@propertydef stale(self) -> bool:diff --git a/marimo/_smoke_tests/altair/altair_brush.py b/marimo/_smoke_tests/altair/altair_brush.pyindex 9580c00337..58d5688a6b 100644--- a/marimo/_smoke_tests/altair/altair_brush.py+++ b/marimo/_smoke_tests/altair/altair_brush.py@@ -1,3 +1,4 @@+# Copyright 2024 Marimo. All rights reserved.import marimo__generated_with = "0.7.5"