timsaucer commented on code in PR #1475:
URL:
https://github.com/apache/datafusion-python/pull/1475#discussion_r3051556640
##########
python/datafusion/context.py:
##########
@@ -1141,6 +1142,120 @@ def session_id(self) -> str:
"""Return an id that uniquely identifies this
:py:class:`SessionContext`."""
return self.ctx.session_id()
+ def session_start_time(self) -> str:
+ """Return the session start time as an RFC 3339 formatted string.
+
+ Examples:
+ >>> ctx = SessionContext()
+ >>> start_time = ctx.session_start_time()
+ >>> assert "T" in start_time # RFC 3339 contains a 'T' separator
+ """
+ return self.ctx.session_start_time()
+
+ def enable_ident_normalization(self) -> bool:
+ """Return whether identifier normalization (lowercasing) is enabled.
+
+ Examples:
+ >>> ctx = SessionContext()
+ >>> assert isinstance(ctx.enable_ident_normalization(), bool)
+ """
+ return self.ctx.enable_ident_normalization()
+
+ def parse_sql_expr(self, sql: str, schema: DFSchema) -> Expr:
+ """Parse a SQL expression string into a logical expression.
+
+ Args:
+ sql: SQL expression string.
+ schema: Schema to use for resolving column references.
+
+ Returns:
+ Parsed expression.
+
+ Examples:
+ >>> from datafusion.common import DFSchema
+ >>> ctx = SessionContext()
+ >>> schema = DFSchema.empty()
+ >>> expr = ctx.parse_sql_expr("1 + 2", schema)
+ >>> assert "Int64(1) + Int64(2)" in str(expr)
+ """
+ from datafusion.expr import Expr # noqa: PLC0415
+
+ return Expr(self.ctx.parse_sql_expr(sql, schema))
+
+ def execute_logical_plan(self, plan: LogicalPlan) -> DataFrame:
+ """Execute a :py:class:`~datafusion.plan.LogicalPlan` and return a
DataFrame.
+
+ Args:
+ plan: Logical plan to execute.
+
+ Returns:
+ DataFrame resulting from the execution.
+
+ Examples:
+ >>> ctx = SessionContext()
+ >>> df = ctx.from_pydict({"a": [1, 2, 3]})
+ >>> plan = df.logical_plan()
+ >>> df2 = ctx.execute_logical_plan(plan)
+ >>> df2.collect()[0].column(0)
+ <pyarrow.lib.Int64Array object at ...>
+ [
+ 1,
+ 2,
+ 3
+ ]
+ """
+ return DataFrame(self.ctx.execute_logical_plan(plan._raw_plan))
+
+ def refresh_catalogs(self) -> None:
+ """Refresh catalog metadata.
+
+ Examples:
+ >>> ctx = SessionContext()
+ >>> ctx.refresh_catalogs()
+ """
+ self.ctx.refresh_catalogs()
+
+ def remove_optimizer_rule(self, name: str) -> bool:
+ """Remove an optimizer rule by name.
+
+ Args:
+ name: Name of the optimizer rule to remove.
+
+ Returns:
+ True if a rule with the given name was found and removed.
+
+ Examples:
+ >>> ctx = SessionContext()
+ >>> ctx.remove_optimizer_rule("nonexistent_rule")
+ False
+ """
+ return self.ctx.remove_optimizer_rule(name)
+
+ def table_provider(self, name: str) -> Table:
+ """Return the :py:class:`~datafusion.catalog.Table` for the given
table name.
+
+ Args:
+ name: Name of the table.
+
+ Returns:
+ The table provider.
+
+ Raises:
+ KeyError: If the table is not found.
+
+ Examples:
+ >>> import pyarrow as pa
+ >>> ctx = SessionContext()
+ >>> batch = pa.RecordBatch.from_pydict({"x": [1, 2]})
+ >>> ctx.register_record_batches("my_table", [[batch]])
+ >>> tbl = ctx.table_provider("my_table")
+ >>> tbl.schema
+ x: int64
+ """
+ from datafusion.catalog import Table # noqa: PLC0415
+
+ return Table(self.ctx.table_provider(name))
Review Comment:
Same, I think we need the wrapper.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]