Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Eventual Inc Daft Session Sql

From Leeroopedia
Revision as of 14:53, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Eventual_Inc_Daft_Session_Sql.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Knowledge Sources
Domains Data_Engineering, SQL
Last Updated 2026-02-08 00:00 GMT

Overview

Concrete tool for executing SQL statements within a session context with full catalog awareness provided by the Daft library.

Description

The sql method on Session executes a SQL statement using the session's internal state for table resolution. It passes the SQL string, the session's Rust PySession, an empty CTE map, and the current planning configuration to the Rust sql_exec function. If the result is a PyBuilder (data statement), it wraps it in a DataFrame. If the result is None (non-data statement like DDL), it returns None. Any other return type raises a ValueError.

Usage

Call sess.sql("SQL_STATEMENT") on a Session instance. Use for catalog-aware SQL execution within session-managed workflows.

Code Reference

Source Location

  • Repository: Daft
  • File: daft/session.py
  • Lines: L144-161

Signature

def sql(self, sql: str) -> DataFrame | None

Import

from daft.session import Session

sess = Session()
result = sess.sql("SELECT * FROM catalog.namespace.table")

I/O Contract

Inputs

Name Type Required Description
sql str Yes SQL statement to execute. Supports DQL (SELECT), DDL (CREATE TABLE), and DML (INSERT) statements.

Outputs

Name Type Description
return None A DataFrame for data statements (SELECT, etc.), or None for non-data statements (DDL operations).

Usage Examples

Basic Usage

from daft.session import Session
import daft

sess = Session()

# Register a temp table
sess.create_temp_table("T", daft.from_pydict({"x": [1, 2, 3]}))

# Execute SQL query
df = sess.sql("SELECT * FROM T WHERE x > 1")
df.show()

Catalog-Aware Query

from daft.session import Session

sess = Session()
sess.attach_catalog(my_catalog, "analytics")
sess.set_catalog("analytics")
sess.set_namespace("production")

# Query resolves through the catalog
df = sess.sql("SELECT * FROM users WHERE active = true")

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment