Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] View name is wrongly written uppercase in CREATE OR REPLACE VIEW my_view AS #79

Merged
merged 1 commit into from
Dec 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions docs/core.html
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,60 @@ <h4 id="preformat_statements" class="doc_header"><code>preformat_statements</cod
</div>
</div>

</div>
{% endraw %}

<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>With additional keyword <code>COMMENT</code></p>

</div>
</div>
</div>
{% raw %}

<div class="cell border-box-sizing code_cell rendered">
<div class="input">

<div class="inner_cell">
<div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">assert_and_print</span><span class="p">(</span>
<span class="n">preformat_statements</span><span class="p">(</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">create or replace table my_table comment=&#39;blabla&#39; as -- mytable</span>
<span class="sd">select distinct asdf, qwer, -- some comment</span>
<span class="sd">from table1</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="p">),</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">CREATE OR REPLACE TABLE my_table comment=&#39;blabla&#39; AS -- mytable[C]</span>
<span class="sd">SELECT DISTINCT asdf, qwer, -- some comment[C]</span>
<span class="sd">FROM table1</span>
<span class="sd">&quot;&quot;&quot;</span><span class="o">.</span><span class="n">rstrip</span><span class="p">()</span>
<span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">

<div class="output_area">

<div class="output_subarea output_stream output_stdout output_text">
<pre>
CREATE OR REPLACE TABLE my_table comment=&#39;blabla&#39; AS -- mytable[C]
SELECT DISTINCT asdf, qwer, -- some comment[C]
FROM table1
</pre>
</div>
</div>

</div>
</div>

</div>
{% endraw %}

Expand Down
55 changes: 52 additions & 3 deletions nbs/00_core.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The autoreload extension is already loaded. To reload it, use:\n",
" %reload_ext autoreload\n"
]
}
],
"source": [
"#hide\n",
"%load_ext autoreload\n",
Expand Down Expand Up @@ -147,8 +156,8 @@
"source": [
"#export\n",
"MAIN_STATEMENTS = [\n",
" \"create.*table\",\n",
" \"create.*view\",\n",
" \"create.*?table\", # regex for all variants: CREATE OR REPLACE TABLE, ...\n",
" \"create.*?view\", # regex\n",
" \"select distinct\",\n",
" \"select\",\n",
" \"from\",\n",
Expand Down Expand Up @@ -684,6 +693,46 @@
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"With additional keyword `COMMENT`"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"CREATE OR REPLACE TABLE my_table comment='blabla' AS -- mytable[C]\n",
"SELECT DISTINCT asdf, qwer, -- some comment[C]\n",
"FROM table1\n"
]
}
],
"source": [
"assert_and_print(\n",
" preformat_statements(\n",
"\"\"\"\n",
"create or replace table my_table comment='blabla' as -- mytable\n",
"select distinct asdf, qwer, -- some comment\n",
"from table1\n",
"\"\"\"\n",
" ),\n",
"\"\"\"\n",
"CREATE OR REPLACE TABLE my_table comment='blabla' AS -- mytable[C]\n",
"SELECT DISTINCT asdf, qwer, -- some comment[C]\n",
"FROM table1\n",
"\"\"\".rstrip()\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
4 changes: 2 additions & 2 deletions sql_formatter/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

# Cell
MAIN_STATEMENTS = [
"create.*table",
"create.*view",
"create.*?table", # regex for all variants: CREATE OR REPLACE TABLE, ...
"create.*?view", # regex
"select distinct",
"select",
"from",
Expand Down