# Chalk DataFrames Reference: Execution and Inspection
source: https://docs.chalk.ai/dataframe-docs#section-execution-and-inspection

Methods for executing query plans and inspecting DataFrame structure.

- `run` — execute and return a materialized [`DataFrame`](https://docs.chalk.ai/dataframe-docs#DataFrame)
- `to_arrow` — execute and return a `pyarrow.Table`
- `write` / `write_parquet` — execute and persist output files
- `explain_logical` / `explain_physical` — inspect the query plan
- `get_plan` / `get_tables` — access internal plan and table state

## `run(tables, remote, resource_group, correlation_id)`
source: https://docs.chalk.ai/dataframe-docs#DataFrame.run

Execute the query plan and return a materialized DataFrame.

**Parameters**

- `tables`: `Mapping[str, MaterializedTable]` = `_empty_table_dict`
  Optional mapping of table names to materialized Arrow data for execution. Ignored when `remote=True`.
- `remote`: `bool` = `False`
  If [`True`](https://docs.python.org/3/library/constants.html#True), submit the plan for remote async execution.
- `resource_group`: `str | None` = `None`
  Optional resource group for remote execution. Only used when `remote=True`.
- `correlation_id`: `str | None` = `None`
  Optional correlation ID for tracking. Only used when `remote=True`.

**Returns**

`MaterializedDataFrame`

**Examples**

```python
from chalkdf import DataFrame
from chalk.features import _
df = DataFrame.from_dict({"x": [1, 2, 3], "y": [4, 5, 6]})
filtered = df.filter(_.x > 1)
materialized = filtered.run()
job = filtered.run(remote=True)
```

## `to_arrow(tables)`
source: https://docs.chalk.ai/dataframe-docs#DataFrame.to_arrow

Execute the query plan and return the result as a PyArrow Table.

**Parameters**

- `tables`: `Mapping[str, MaterializedTable]` = `_empty_table_dict`
  Optional mapping of table names to materialized Arrow data for execution.

**Returns**

`pyarrow.Table`

**Examples**

```python
from chalkdf import DataFrame
from chalk.features import _
df = DataFrame.from_dict({"x": [1, 2, 3], "y": [4, 5, 6]})
filtered = df.filter(_.x > 1)
arrow_table = filtered.to_arrow()
```

## `write(target_path, target_file_name, file_format, serde_parameters, compression, ensure_files, connector_id, return_table_write_result)`
source: https://docs.chalk.ai/dataframe-docs#DataFrame.write

Execute the DataFrame plan and write the output files immediately.

This is the eager counterpart to `write_lazy`: it builds the write plan _and_ runs it in one step.

By default (`return_table_write_result=False`) the method returns [`None`](https://docs.python.org/3/library/constants.html#None) after the write completes. Pass `return_table_write_result=True` to receive the raw `TableWrite` result MaterializedDataFrame instead.

**Parameters**

- `target_path`: `str`
  Directory to write output files.
- `target_file_name`: `str | None` = `None`
  Optional explicit file name.
- `file_format`: `str` = `'parquet'`
  Output format (default `parquet`).
- `serde_parameters`: `Mapping[str, str] | None` = `None`
  Optional SerDe options for text formats.
- `compression`: `str | None` = `None`
  Optional compression codec.
- `ensure_files`: `bool` = `False`
  Ensure writers emit files even if no rows were produced.
- `connector_id`: `str | None` = `None`
  Optional connector id override.
- `return_table_write_result`: `bool` = `False`
  If [`True`](https://docs.python.org/3/library/constants.html#True), return the raw TableWrite result DataFrame. If [`False`](https://docs.python.org/3/library/constants.html#False) (default), return [`None`](https://docs.python.org/3/library/constants.html#None).

**Returns**

`MaterializedDataFrame | None`

## `write_parquet(output_uri_prefix, skip_planning_time_validation, return_table_write_result)`
source: https://docs.chalk.ai/dataframe-docs#DataFrame.write_parquet

Write the DataFrame as Parquet files using an auto-configured connector.

Convenience method that simplifies writing Parquet files compared to the more general `write`. The connector is selected automatically based on the URI scheme.

By default (`return_table_write_result=False`) the method returns [`None`](https://docs.python.org/3/library/constants.html#None) after the write completes. Pass `return_table_write_result=True` to receive the raw `TableWrite` result MaterializedDataFrame instead.

**Parameters**

- `output_uri_prefix`: `str`
  URI prefix where Parquet files will be written. Supports local (`file://`), S3 (`s3://`), and GCS (`gs://`) URIs.
- `skip_planning_time_validation`: `bool` = `False`
  Whether to skip validation at planning time (default: [`False`](https://docs.python.org/3/library/constants.html#False)).
- `return_table_write_result`: `bool` = `False`
  If [`True`](https://docs.python.org/3/library/constants.html#True), return the raw TableWrite result DataFrame. If [`False`](https://docs.python.org/3/library/constants.html#False) (default), return [`None`](https://docs.python.org/3/library/constants.html#None).

**Returns**

`MaterializedDataFrame | None`

**Examples**

```python
from chalkdf import DataFrame
df = DataFrame.from_dict({"x": [1, 2, 3], "y": [4, 5, 6]})
df.write_parquet("file:///tmp/output/")  # returns None
result = df.write_parquet("gs://my-bucket/output/", return_table_write_result=True)
```

## `explain_logical(simplified)`
source: https://docs.chalk.ai/dataframe-docs#DataFrame.explain_logical

Return a string representation of the logical query plan.

**Returns**

`str`

**Examples**

```python
from chalkdf import DataFrame
from chalk.features import _
df = DataFrame.from_dict({"x": [1, 2, 3], "y": [4, 5, 6]})
filtered = df.filter(_.x > 1)
print(filtered.explain_logical())
```

## `explain_physical()`
source: https://docs.chalk.ai/dataframe-docs#DataFrame.explain_physical

Return a string representation of the physical execution plan.

**Returns**

`str`

**Examples**

```python
from chalkdf import DataFrame
from chalk.features import _
df = DataFrame.from_dict({"x": [1, 2, 3], "y": [4, 5, 6]})
filtered = df.filter(_.x > 1)
print(filtered.explain_physical())
```

## `get_plan()`
source: https://docs.chalk.ai/dataframe-docs#DataFrame.get_plan

Expose the underlying `ChalkTable` plan.

## `get_tables()`
source: https://docs.chalk.ai/dataframe-docs#DataFrame.get_tables

Return the mapping of materialized tables for this DataFrame.
