Skip to content

Commit

Permalink
[docs][YSQL][#2312] CREATE OPERATOR, DROP OPERATOR (#2343)
Browse files Browse the repository at this point in the history
* Add CREATE OPERATOR docs page

Do all steps in creating a docs page for `CREATE OPERATOR`.  Reference
Postgres docs in semantics.  Add a single, basic example.

* Add DROP OPERATOR docs page

Add a docs page for `DROP OPERATOR`.  Have semantics refer to the
Postgres docs.  Have one basic example.

* Address @ndeodhar's review comments

* Add `DROP OPERATOR` to one of the index files
* Add expected output for the `CREATE OPERATOR`example
* Fix the grammar for `DROP OPERATOR` to not only be correct but also
  have a nicer looking diagram

* Fix and improve the grammar for DROP AGGREGATE

Just like the fix on `DROP OPERATOR`, do the same for `DROP AGGREGATE`.
The grammar should be fixed, and the diagram should look a lot nicer.
  • Loading branch information
jaki committed Sep 17, 2019
1 parent 81742b7 commit 66f8ca0
Show file tree
Hide file tree
Showing 14 changed files with 281 additions and 17 deletions.
2 changes: 2 additions & 0 deletions docs/content/latest/api/ysql/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ DDL statements define the structures in a database, change their definitions, as
| [`CREATE CAST`](commands/ddl_create_cast) | Create a new cast |
| [`CREATE DATABASE`](commands/ddl_create_database) | Create a new database |
| [`CREATE INDEX`](commands/ddl_create_index) | Create a new index |
| [`CREATE OPPERATOR`](commands/ddl_create_operator) | Create a new operator |
| [`CREATE SCHEMA`](commands/ddl_create_schema) | Create a new schema (namespace) |
| [`CREATE SEQUENCE`](commands/ddl_create_sequence) | Create a new sequence generator |
| [`CREATE TABLE`](commands/ddl_create_table) | Create a new table |
Expand All @@ -49,6 +50,7 @@ DDL statements define the structures in a database, change their definitions, as
| [`DROP AGGREGATE`](commands/ddl_drop_aggregate) | Delete an aggregate |
| [`DROP CAST`](commands/ddl_drop_cast) | Delete a cast |
| [`DROP DATABASE`](commands/ddl_drop_database) | Delete a database from the system |
| [`DROP OPERATOR`](commands/ddl_drop_operator) | Delete an operator |
| [`DROP SEQUENCE`](commands/ddl_drop_sequence) | Delete a sequence generator |
| [`DROP TABLE`](commands/ddl_drop_table) | Delete a table from a database |
| [`DROP TYPE`](commands/ddl_drop_type) | Delete a user-defined type |
Expand Down
2 changes: 2 additions & 0 deletions docs/content/latest/api/ysql/commands/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ The following SQL statements are supported by the Yugabyte Structured Query Lang
| [`CREATE DOMAIN`](ddl_create_domain) | Create a new domain |
| [`CREATE INDEX`](ddl_create_index) | Create a new index |
| [`CREATE GROUP`](dcl_create_group) | Create a new group (role) |
| [`CREATE OPERATOR`](ddl_create_operator) | Create a new operator |
| [`CREATE ROLE`](dcl_create_role) | Create a new role (user or group) |
| [`CREATE USER`](dcl_create_user) | Create a new user (role) |
| [`CREATE SCHEMA`](ddl_create_schema) | Create a new schema (namespace) |
Expand All @@ -54,6 +55,7 @@ The following SQL statements are supported by the Yugabyte Structured Query Lang
| [`DROP DATABASE`](ddl_drop_database) | Delete a database from the system |
| [`DROP DOMAIN`](ddl_drop_domain) | Delete a domain |
| [`DROP GROUP`](dcl_drop_group) | Delete a group (role) |
| [`DROP OPERATOR`](ddl_drop_operator) | Delete an operator |
| [`DROP ROLE`](dcl_drop_role) | Delete a role (user or group) |
| [`DROP SEQUENCE`](ddl_drop_sequence) | Delete a sequence generator |
| [`DROP TABLE`](ddl_drop_table) | Deletes a table from a database |
Expand Down
72 changes: 72 additions & 0 deletions docs/content/latest/api/ysql/commands/ddl_create_operator.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
title: CREATE OPERATOR
linkTitle: CREATE OPERATOR
summary: Create a new operator
description: CREATE OPERATOR
menu:
latest:
identifier: api-ysql-commands-create-operator
parent: api-ysql-commands
aliases:
- /latest/api/ysql/ddl_create_operator/
isTocNested: true
showAsideToc: true
---

## Synopsis

Use the `CREATE OPERATOR` statement to create a new operator.

## Syntax

<ul class="nav nav-tabs nav-tabs-yb">
<li >
<a href="#grammar" class="nav-link active" id="grammar-tab" data-toggle="tab" role="tab" aria-controls="grammar" aria-selected="true">
<i class="fas fa-file-alt" aria-hidden="true"></i>
Grammar
</a>
</li>
<li>
<a href="#diagram" class="nav-link" id="diagram-tab" data-toggle="tab" role="tab" aria-controls="diagram" aria-selected="false">
<i class="fas fa-project-diagram" aria-hidden="true"></i>
Diagram
</a>
</li>
</ul>

<div class="tab-content">
<div id="grammar" class="tab-pane fade show active" role="tabpanel" aria-labelledby="grammar-tab">
{{% includeMarkdown "../syntax_resources/commands/create_operator,operator_option.grammar.md" /%}}
</div>
<div id="diagram" class="tab-pane fade" role="tabpanel" aria-labelledby="diagram-tab">
{{% includeMarkdown "../syntax_resources/commands/create_operator,operator_option.diagram.md" /%}}
</div>
</div>

## Semantics

See the semantics of each option in the [PostgreSQL docs][postgresql-docs-create-operator].

## Examples

Basic example.

```sql
yugabyte=# CREATE OPERATOR @#@ (
rightarg = int8,
procedure = numeric_fac
);
yugabyte=# SELECT @#@ 5;
```

```
?column?
----------
120
```

## See also

- [`DROP OPERATOR`](../ddl_drop_operator)

[postgresql-docs-create-operator]: https://www.postgresql.org/docs/current/sql-createoperator.html
66 changes: 66 additions & 0 deletions docs/content/latest/api/ysql/commands/ddl_drop_operator.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---
title: DROP OPERATOR
linkTitle: DROP OPERATOR
summary: Remove an operator
description: DROP OPERATOR
menu:
latest:
identifier: api-ysql-commands-drop-operator
parent: api-ysql-commands
aliases:
- /latest/api/ysql/ddl_drop_operator/
isTocNested: true
showAsideToc: true
---

## Synopsis

Use the `DROP OPERATOR` statement to remove an operator.

## Syntax

<ul class="nav nav-tabs nav-tabs-yb">
<li >
<a href="#grammar" class="nav-link active" id="grammar-tab" data-toggle="tab" role="tab" aria-controls="grammar" aria-selected="true">
<i class="fas fa-file-alt" aria-hidden="true"></i>
Grammar
</a>
</li>
<li>
<a href="#diagram" class="nav-link" id="diagram-tab" data-toggle="tab" role="tab" aria-controls="diagram" aria-selected="false">
<i class="fas fa-project-diagram" aria-hidden="true"></i>
Diagram
</a>
</li>
</ul>

<div class="tab-content">
<div id="grammar" class="tab-pane fade show active" role="tabpanel" aria-labelledby="grammar-tab">
{{% includeMarkdown "../syntax_resources/commands/drop_operator,operator_signature.grammar.md" /%}}
</div>
<div id="diagram" class="tab-pane fade" role="tabpanel" aria-labelledby="diagram-tab">
{{% includeMarkdown "../syntax_resources/commands/drop_operator,operator_signature.diagram.md" /%}}
</div>
</div>

## Semantics

See the semantics of each option in the [PostgreSQL docs][postgresql-docs-drop-operator].

## Examples

Basic example.

```sql
yugabyte=# CREATE OPERATOR @#@ (
rightarg = int8,
procedure = numeric_fac
);
yugabyte=# DROP OPERATOR @#@ (NONE, int8);
```

## See also

- [`CREATE OPERATOR`](../ddl_create_operator)

[postgresql-docs-drop-operator]: https://www.postgresql.org/docs/current/sql-dropoperator.html

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ comment_on ::= COMMENT ON
| INDEX object_name
| LARGE OBJECT large_object_oid
| MATERIALIZED VIEW object_name
| OPERATOR operator_name ( left_type , right_type )
| OPERATOR operator_name ( operator_signature )
| OPERATOR CLASS object_name USING index_method
| OPERATOR FAMILY object_name USING index_method
| POLICY policy_name ON table_name
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#### create_operator

<svg class="rrdiagram" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" width="937" height="80" viewbox="0 0 937 80"><path class="connector" d="M0 37h15m67 0h10m84 0h10m112 0h10m25 0h30m83 0h10m30 0h10m111 0h41m-300 0q5 0 5 5v20q0 5 5 5h5m94 0h10m30 0h10m121 0h5q5 0 5-5v-20q0-5 5-5m5 0h50m-5 0q-5 0-5-5v-17q0-5 5-5h159q5 0 5 5v17q0 5-5 5m-130 0h10m115 0h40m-224 0q5 0 5 5v8q0 5 5 5h199q5 0 5-5v-8q0-5 5-5m5 0h10m25 0h15"/><polygon points="0,44 5,37 0,30" style="fill:black;stroke-width:0"/><rect class="literal" x="15" y="20" width="67" height="25" rx="7"/><text class="text" x="25" y="37">CREATE</text><rect class="literal" x="92" y="20" width="84" height="25" rx="7"/><text class="text" x="102" y="37">OPERATOR</text><a xlink:href="../../syntax_resources/grammar_diagrams#operator-name"><rect class="rule" x="186" y="20" width="112" height="25"/><text class="text" x="196" y="37">operator_name</text></a><rect class="literal" x="308" y="20" width="25" height="25" rx="7"/><text class="text" x="318" y="37">(</text><rect class="literal" x="363" y="20" width="83" height="25" rx="7"/><text class="text" x="373" y="37">FUNCTION</text><rect class="literal" x="456" y="20" width="30" height="25" rx="7"/><text class="text" x="466" y="37">=</text><a xlink:href="../../syntax_resources/grammar_diagrams#function-name"><rect class="rule" x="496" y="20" width="111" height="25"/><text class="text" x="506" y="37">function_name</text></a><rect class="literal" x="363" y="50" width="94" height="25" rx="7"/><text class="text" x="373" y="67">PROCEDURE</text><rect class="literal" x="467" y="50" width="30" height="25" rx="7"/><text class="text" x="477" y="67">=</text><a xlink:href="../../syntax_resources/grammar_diagrams#procedure-name"><rect class="rule" x="507" y="50" width="121" height="25"/><text class="text" x="517" y="67">procedure_name</text></a><rect class="literal" x="698" y="20" width="24" height="25" rx="7"/><text class="text" x="708" y="37">,</text><a xlink:href="#operator-option"><rect class="rule" x="732" y="20" width="115" height="25"/><text class="text" x="742" y="37">operator_option</text></a><rect class="literal" x="897" y="20" width="25" height="25" rx="7"/><text class="text" x="907" y="37">)</text><polygon points="933,44 937,44 937,30 933,30" style="fill:black;stroke-width:0"/></svg>

#### operator_option

<svg class="rrdiagram" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" width="292" height="245" viewbox="0 0 292 245"><path class="connector" d="M0 22h35m74 0h10m30 0h10m73 0h45m-252 25q0 5 5 5h5m83 0h10m30 0h10m82 0h12q5 0 5-5m-242 30q0 5 5 5h5m105 0h10m30 0h10m67 0h5q5 0 5-5m-242 30q0 5 5 5h5m78 0h10m30 0h10m64 0h35q5 0 5-5m-242 30q0 5 5 5h5m79 0h10m30 0h10m71 0h27q5 0 5-5m-242 30q0 5 5 5h5m48 0h10m30 0h10m75 0h54q5 0 5-5m-242 30q0 5 5 5h5m70 0h157q5 0 5-5m-247-175q5 0 5 5v200q0 5 5 5h5m71 0h156q5 0 5-5v-200q0-5 5-5m5 0h15"/><polygon points="0,29 5,22 0,15" style="fill:black;stroke-width:0"/><rect class="literal" x="35" y="5" width="74" height="25" rx="7"/><text class="text" x="45" y="22">LEFTARG</text><rect class="literal" x="119" y="5" width="30" height="25" rx="7"/><text class="text" x="129" y="22">=</text><a xlink:href="../../syntax_resources/grammar_diagrams#left-type"><rect class="rule" x="159" y="5" width="73" height="25"/><text class="text" x="169" y="22">left_type</text></a><rect class="literal" x="35" y="35" width="83" height="25" rx="7"/><text class="text" x="45" y="52">RIGHTARG</text><rect class="literal" x="128" y="35" width="30" height="25" rx="7"/><text class="text" x="138" y="52">=</text><a xlink:href="../../syntax_resources/grammar_diagrams#right-type"><rect class="rule" x="168" y="35" width="82" height="25"/><text class="text" x="178" y="52">right_type</text></a><rect class="literal" x="35" y="65" width="105" height="25" rx="7"/><text class="text" x="45" y="82">COMMUTATOR</text><rect class="literal" x="150" y="65" width="30" height="25" rx="7"/><text class="text" x="160" y="82">=</text><a xlink:href="../../syntax_resources/grammar_diagrams#com-op"><rect class="rule" x="190" y="65" width="67" height="25"/><text class="text" x="200" y="82">com_op</text></a><rect class="literal" x="35" y="95" width="78" height="25" rx="7"/><text class="text" x="45" y="112">NEGATOR</text><rect class="literal" x="123" y="95" width="30" height="25" rx="7"/><text class="text" x="133" y="112">=</text><a xlink:href="../../syntax_resources/grammar_diagrams#neg-op"><rect class="rule" x="163" y="95" width="64" height="25"/><text class="text" x="173" y="112">neg_op</text></a><rect class="literal" x="35" y="125" width="79" height="25" rx="7"/><text class="text" x="45" y="142">RESTRICT</text><rect class="literal" x="124" y="125" width="30" height="25" rx="7"/><text class="text" x="134" y="142">=</text><a xlink:href="../../syntax_resources/grammar_diagrams#res-proc"><rect class="rule" x="164" y="125" width="71" height="25"/><text class="text" x="174" y="142">res_proc</text></a><rect class="literal" x="35" y="155" width="48" height="25" rx="7"/><text class="text" x="45" y="172">JOIN</text><rect class="literal" x="93" y="155" width="30" height="25" rx="7"/><text class="text" x="103" y="172">=</text><a xlink:href="../../syntax_resources/grammar_diagrams#join-proc"><rect class="rule" x="133" y="155" width="75" height="25"/><text class="text" x="143" y="172">join_proc</text></a><rect class="literal" x="35" y="185" width="70" height="25" rx="7"/><text class="text" x="45" y="202">HASHES</text><rect class="literal" x="35" y="215" width="71" height="25" rx="7"/><text class="text" x="45" y="232">MERGES</text><polygon points="288,29 292,29 292,15 288,15" style="fill:black;stroke-width:0"/></svg>

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
```
create_operator ::= CREATE OPERATOR operator_name (
{ FUNCTION = function_name
| PROCEDURE = procedure_name }
[ , operator_option [ ... ] ] )
operator_option ::= LEFTARG = left_type
| RIGHTARG = right_type
| COMMUTATOR = com_op
| NEGATOR = neg_op
| RESTRICT = res_proc
| JOIN = join_proc
| HASHES
| MERGES
```
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#### drop_aggregate

<svg class="rrdiagram" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" width="1294" height="85" viewbox="0 0 1294 85"><path class="connector" d="M0 37h15m53 0h10m94 0h30m32 0h10m64 0h20m-141 0q5 0 5 5v8q0 5 5 5h116q5 0 5-5v-8q0-5 5-5m5 0h10m121 0h10m25 0h10m143 0h10m25 0h50m-5 0q-5 0-5-5v-17q0-5 5-5h388q5 0 5 5v17q0 5-5 5m-359 0h10m121 0h10m25 0h10m143 0h10m25 0h40m-453 0q5 0 5 5v8q0 5 5 5h428q5 0 5-5v-8q0-5 5-5m5 0h30m77 0h22m-109 25q0 5 5 5h5m79 0h5q5 0 5-5m-104-25q5 0 5 5v33q0 5 5 5h89q5 0 5-5v-33q0-5 5-5m5 0h15"/><polygon points="0,44 5,37 0,30" style="fill:black;stroke-width:0"/><rect class="literal" x="15" y="20" width="53" height="25" rx="7"/><text class="text" x="25" y="37">DROP</text><rect class="literal" x="78" y="20" width="94" height="25" rx="7"/><text class="text" x="88" y="37">AGGREGATE</text><rect class="literal" x="202" y="20" width="32" height="25" rx="7"/><text class="text" x="212" y="37">IF</text><rect class="literal" x="244" y="20" width="64" height="25" rx="7"/><text class="text" x="254" y="37">EXISTS</text><a xlink:href="../../syntax_resources/grammar_diagrams#aggregate-name"><rect class="rule" x="338" y="20" width="121" height="25"/><text class="text" x="348" y="37">aggregate_name</text></a><rect class="literal" x="469" y="20" width="25" height="25" rx="7"/><text class="text" x="479" y="37">(</text><a xlink:href="#aggregate-signature"><rect class="rule" x="504" y="20" width="143" height="25"/><text class="text" x="514" y="37">aggregate_signature</text></a><rect class="literal" x="657" y="20" width="25" height="25" rx="7"/><text class="text" x="667" y="37">)</text><rect class="literal" x="732" y="20" width="24" height="25" rx="7"/><text class="text" x="742" y="37">,</text><a xlink:href="../../syntax_resources/grammar_diagrams#aggregate-name"><rect class="rule" x="766" y="20" width="121" height="25"/><text class="text" x="776" y="37">aggregate_name</text></a><rect class="literal" x="897" y="20" width="25" height="25" rx="7"/><text class="text" x="907" y="37">(</text><a xlink:href="#aggregate-signature"><rect class="rule" x="932" y="20" width="143" height="25"/><text class="text" x="942" y="37">aggregate_signature</text></a><rect class="literal" x="1085" y="20" width="25" height="25" rx="7"/><text class="text" x="1095" y="37">)</text><rect class="literal" x="1180" y="20" width="77" height="25" rx="7"/><text class="text" x="1190" y="37">CASCADE</text><rect class="literal" x="1180" y="50" width="79" height="25" rx="7"/><text class="text" x="1190" y="67">RESTRICT</text><polygon points="1290,44 1294,44 1294,30 1290,30" style="fill:black;stroke-width:0"/></svg>
<svg class="rrdiagram" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" width="866" height="100" viewbox="0 0 866 100"><path class="connector" d="M0 52h15m53 0h10m94 0h30m32 0h10m64 0h20m-141 0q5 0 5 5v8q0 5 5 5h116q5 0 5-5v-8q0-5 5-5m5 0h30m-5 0q-5 0-5-5v-20q0-5 5-5h165m24 0h165q5 0 5 5v20q0 5-5 5m-228 0h10m25 0h10m143 0h10m25 0h50m77 0h22m-109 25q0 5 5 5h5m79 0h5q5 0 5-5m-104-25q5 0 5 5v33q0 5 5 5h89q5 0 5-5v-33q0-5 5-5m5 0h15"/><polygon points="0,59 5,52 0,45" style="fill:black;stroke-width:0"/><rect class="literal" x="15" y="35" width="53" height="25" rx="7"/><text class="text" x="25" y="52">DROP</text><rect class="literal" x="78" y="35" width="94" height="25" rx="7"/><text class="text" x="88" y="52">AGGREGATE</text><rect class="literal" x="202" y="35" width="32" height="25" rx="7"/><text class="text" x="212" y="52">IF</text><rect class="literal" x="244" y="35" width="64" height="25" rx="7"/><text class="text" x="254" y="52">EXISTS</text><rect class="literal" x="518" y="5" width="24" height="25" rx="7"/><text class="text" x="528" y="22">,</text><a xlink:href="../../syntax_resources/grammar_diagrams#aggregate-name"><rect class="rule" x="358" y="35" width="121" height="25"/><text class="text" x="368" y="52">aggregate_name</text></a><rect class="literal" x="489" y="35" width="25" height="25" rx="7"/><text class="text" x="499" y="52">(</text><a xlink:href="#aggregate-signature"><rect class="rule" x="524" y="35" width="143" height="25"/><text class="text" x="534" y="52">aggregate_signature</text></a><rect class="literal" x="677" y="35" width="25" height="25" rx="7"/><text class="text" x="687" y="52">)</text><rect class="literal" x="752" y="35" width="77" height="25" rx="7"/><text class="text" x="762" y="52">CASCADE</text><rect class="literal" x="752" y="65" width="79" height="25" rx="7"/><text class="text" x="762" y="82">RESTRICT</text><polygon points="862,59 866,59 866,45 862,45" style="fill:black;stroke-width:0"/></svg>

#### aggregate_signature

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
```
drop_aggregate ::= DROP AGGREGATE [ IF EXISTS ] aggregate_name (
aggregate_signature )
[ ,aggregate_name(aggregate_signature ... ]
[ CASCADE | RESTRICT ]
drop_aggregate ::= DROP AGGREGATE [ IF EXISTS ]
{ aggregate_name ( aggregate_signature ) }
[ , ... ] [ CASCADE | RESTRICT ]
aggregate_signature ::= * | aggregate_arg [ , ... ]
| [ aggregate_arg [ , ... ] ] ORDER BY
Expand Down

0 comments on commit 66f8ca0

Please sign in to comment.