diff --git a/ibis/backends/pyspark/__init__.py b/ibis/backends/pyspark/__init__.py index c5bbe4a11f39e..31b5180631f80 100644 --- a/ibis/backends/pyspark/__init__.py +++ b/ibis/backends/pyspark/__init__.py @@ -413,11 +413,16 @@ def _register_udfs(self, expr: ir.Expr) -> None: self._session.udf.register("unwrap_json_float", unwrap_json_float) def _register_in_memory_table(self, op: ops.InMemoryTable) -> None: - schema = PySparkSchema.from_ibis(op.schema) - df = self._session.createDataFrame(data=op.data.to_frame(), schema=schema) + session = self._session + df = session.createDataFrame( + data=op.data.to_frame(), schema=PySparkSchema.from_ibis(op.schema) + ) + name = op.name + with contextlib.suppress(AnalysisException): - self._session.catalog.dropTempView(op.name) - df.createTempView(op.name) + session.catalog.dropTempView(name) + + df.createTempView(name) def _finalize_memtable(self, name: str) -> None: self._session.catalog.dropTempView(name)