<commit_before>---
layout: documentation
displayTitle: Execute SQL Expression
title: Execute SQL Expression
description: Execute SQL Expression
usesMathJax: true
includeOperationsMenu: true
---

Executes a Spark SQL expression provided by the user on a DataFrame connected to its input port.
Returns the results of the execution as a DataFrame.

Returns also a [Transformer](../classes/transformer.html) that can be later applied
to another [DataFrame](../classes/dataframe.html) with [Transform](transform.html) operation.

**Since**: Seahorse 0.4.0

## Input

<table>
<thead>
<tr>
<th style="width:15%">Port</th>
<th style="width:15%">Type Qualifier</th>
<th style="width:70%">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>0</code></td>
<td><code><a href="../classes/dataframe.html">DataFrame</a></code></td>
<td>A DataFrame that the SQL expression will be executed on.</td>
</tr>
</tbody>
</table>

## Output

<table>
<thead>
<tr>
<th style="width:15%">Port</th>
<th style="width:15%">Type Qualifier</th>
<th style="width:70%">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>0</code></td>
<td><code><a href="../classes/dataframe.html">DataFrame</a></code></td>
<td>The results of the SQL expression.</td>
</tr>
<tr>
<td><code>1</code></td><td>
<code><a href="../classes/transformer.html">Transformer</a></code></td>
<td>Transformer that allows to apply the operation on other DataFrames using
<a href="transform.html">Transform</a>.</td>
</tr>
</tbody>
</table>

## Parameters

<table class="table">
<thead>
<tr>
<th style="width:15%">Name</th>
<th style="width:15%">Type</th>
<th style="width:70%">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>dataframe id</code></td>
<td><code><a href="../parameter_types.html#string">String</a></code></td>
<td>An identifier that can be used in the SQL expression to refer to the input DataFrame.</td>
</tr>
<tr>
<td><code>expression</code></td>
<td><code><a href="../parameter_types.html#code-snippet">Code Snippet</a></code></td>
<td>The SQL expression to be executed. The expression must be a valid Spark SQL expression.</td>
</tr>
</tbody>
</table>

{% markdown operations/examples/ExecuteSqlExpression.md %}<commit_msg>Enhance execute sql expression documentation<commit_after>---
layout: documentation
displayTitle: Execute SQL Expression
title: Execute SQL Expression
description: Execute SQL Expression
usesMathJax: true
includeOperationsMenu: true
---

Executes a Spark SQL expression provided by the user on a `DataFrame` connected to its input port.
Returns the results of the execution as a `DataFrame`.

Also returns a [Transformer](../classes/transformer.html) that can be later applied
to another [DataFrame](../classes/dataframe.html) with a [Transform](transform.html) operation.

**Since**: Seahorse 0.4.0

## Input

<table>
<thead>
<tr>
<th style="width:15%">Port</th>
<th style="width:15%">Type Qualifier</th>
<th style="width:70%">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>0</code></td>
<td><code><a href="../classes/dataframe.html">DataFrame</a></code></td>
<td>The <code>DataFrame</code> that the SQL expression will be executed on.</td>
</tr>
</tbody>
</table>

## Output

<table>
<thead>
<tr>
<th style="width:15%">Port</th>
<th style="width:15%">Type Qualifier</th>
<th style="width:70%">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>0</code></td>
<td><code><a href="../classes/dataframe.html">DataFrame</a></code></td>
<td>The results of the SQL expression.</td>
</tr>
<tr>
<td><code>1</code></td><td>
<code><a href="../classes/transformer.html">Transformer</a></code></td>
<td><code>Transformer</code> that allows to apply the operation on another <code>DataFrames</code> using
<a href="transform.html">Transform</a>.</td>
</tr>
</tbody>
</table>

## Parameters

<table class="table">
<thead>
<tr>
<th style="width:15%">Name</th>
<th style="width:15%">Type</th>
<th style="width:70%">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>dataframe id</code></td>
<td><code><a href="../parameter_types.html#string">String</a></code></td>
<td>The identifier that can be used in the SQL expression to refer the input <code>DataFrame</code>.</td>
</tr>
<tr>
<td><code>expression</code></td>
<td><code><a href="../parameter_types.html#code-snippet">Code Snippet</a></code></td>
<td>The SQL expression to be executed. The expression must be a valid Spark SQL expression.</td>
</tr>
</tbody>
</table>

{% markdown operations/examples/ExecuteSqlExpression.md %}
{'fraction_non_alphanumeric': 0.20452002685164467, 'fraction_numerical': 0.01074065786529425, 'mean_word_length': 5.7218045112781954, 'pattern_counts': {'":': 0, '<': 239, '<?xml version=': 0, '>': 239, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3820100', 'n_tokens_mistral': 1570, 'n_tokens_neox': 1524, 'n_words': 404}