From d34cb59fb311c3d700e4f4f877b61b17cea313ee Mon Sep 17 00:00:00 2001 From: Huaxin Gao Date: Wed, 29 Apr 2020 09:17:23 +0900 Subject: [PATCH] [SPARK-31556][SQL][DOCS] Document LIKE clause in SQL Reference ### What changes were proposed in this pull request? Document LIKE clause in SQL Reference ### Why are the changes needed? To make SQL Reference complete ### Does this PR introduce any user-facing change? Yes Screen Shot 2020-04-25 at 5 49 57 PM Screen Shot 2020-04-25 at 5 50 24 PM Screen Shot 2020-04-25 at 5 50 42 PM ### How was this patch tested? Manually build and check Closes #28332 from huaxingao/where_clause. Authored-by: Huaxin Gao Signed-off-by: Takeshi Yamamuro --- docs/_data/menu-sql.yaml | 2 + docs/sql-ref-syntax-aux-show-databases.md | 13 ++- docs/sql-ref-syntax-aux-show-functions.md | 8 +- docs/sql-ref-syntax-aux-show-table.md | 14 +-- docs/sql-ref-syntax-aux-show-tables.md | 10 +- docs/sql-ref-syntax-aux-show-views.md | 12 +-- docs/sql-ref-syntax-qry-explain.md | 2 +- docs/sql-ref-syntax-qry-select-like.md | 120 ++++++++++++++++++++++ 8 files changed, 154 insertions(+), 27 deletions(-) create mode 100644 docs/sql-ref-syntax-qry-select-like.md diff --git a/docs/_data/menu-sql.yaml b/docs/_data/menu-sql.yaml index 1097079e45..dfe4cfab2a 100644 --- a/docs/_data/menu-sql.yaml +++ b/docs/_data/menu-sql.yaml @@ -170,6 +170,8 @@ url: sql-ref-syntax-qry-select-inline-table.html - text: Common Table Expression url: sql-ref-syntax-qry-select-cte.html + - text: LIKE Predicate + url: sql-ref-syntax-qry-select-like.html - text: Window Function url: sql-ref-syntax-qry-window.html - text: EXPLAIN diff --git a/docs/sql-ref-syntax-aux-show-databases.md b/docs/sql-ref-syntax-aux-show-databases.md index 0ed34527bc..359900928c 100644 --- a/docs/sql-ref-syntax-aux-show-databases.md +++ b/docs/sql-ref-syntax-aux-show-databases.md @@ -29,16 +29,21 @@ and mean the same thing. ### Syntax {% highlight sql %} -SHOW { DATABASES | SCHEMAS } [ LIKE string_pattern ] +SHOW { DATABASES | SCHEMAS } [ LIKE regex_pattern ] {% endhighlight %} ### Parameters
-
LIKE string_pattern
+
regex_pattern
- Specifies a string pattern that is used to match the databases in the system. In - the specified string pattern '*' matches any number of characters. + Specifies a regular expression pattern that is used to filter the results of the + statement. +
    +
  • Only * and | are allowed as wildcard pattern.
  • +
  • Excluding * and |, the remaining pattern follows the regular expression semantics.
  • +
  • The leading and trailing blanks are trimmed in the input pattern before processing. The pattern match is case-insensitive.
  • +
diff --git a/docs/sql-ref-syntax-aux-show-functions.md b/docs/sql-ref-syntax-aux-show-functions.md index da33d999f0..ed22a3a901 100644 --- a/docs/sql-ref-syntax-aux-show-functions.md +++ b/docs/sql-ref-syntax-aux-show-functions.md @@ -58,12 +58,12 @@ SHOW [ function_kind ] FUNCTIONS ( [ LIKE ] function_name | regex_pattern )
regex_pattern
- Specifies a regular expression pattern that is used to limit the results of the + Specifies a regular expression pattern that is used to filter the results of the statement.
    -
  • Only `*` and `|` are allowed as wildcard pattern.
  • -
  • Excluding `*` and `|` the remaining pattern follows the regex semantics.
  • -
  • The leading and trailing blanks are trimmed in the input pattern before processing.
  • +
  • Only * and | are allowed as wildcard pattern.
  • +
  • Excluding * and |, the remaining pattern follows the regular expression semantics.
  • +
  • The leading and trailing blanks are trimmed in the input pattern before processing. The pattern match is case-insensitive.
diff --git a/docs/sql-ref-syntax-aux-show-table.md b/docs/sql-ref-syntax-aux-show-table.md index 1aa44d3ab3..c688a99df3 100644 --- a/docs/sql-ref-syntax-aux-show-table.md +++ b/docs/sql-ref-syntax-aux-show-table.md @@ -33,7 +33,7 @@ cannot be used with a partition specification. ### Syntax {% highlight sql %} -SHOW TABLE EXTENDED [ IN | FROM database_name ] LIKE 'identifier_with_wildcards' +SHOW TABLE EXTENDED [ IN | FROM database_name ] LIKE regex_pattern [ partition_spec ] {% endhighlight %} @@ -44,15 +44,15 @@ SHOW TABLE EXTENDED [ IN | FROM database_name ] LIKE 'identifier_with_wildcards'
Specifies database name. If not provided, will use the current database.
-
LIKE string_pattern
+
regex_pattern
Specifies the regular expression pattern that is used to filter out unwanted tables. -
    -
  • Except for `*` and `|` character, the pattern works like a regex.
  • -
  • `*` alone matches 0 or more characters and `|` is used to separate multiple different regexes, +
      +
    • Except for * and | character, the pattern works like a regular expression.
    • +
    • * alone matches 0 or more characters and | is used to separate multiple different regular expressions, any of which can match.
    • -
    • The leading and trailing blanks are trimmed in the input pattern before processing.
    • -
    +
  • The leading and trailing blanks are trimmed in the input pattern before processing. The pattern match is case-insensitive.
  • +
partition_spec
diff --git a/docs/sql-ref-syntax-aux-show-tables.md b/docs/sql-ref-syntax-aux-show-tables.md index 0b7062ec8e..f4b3dff850 100644 --- a/docs/sql-ref-syntax-aux-show-tables.md +++ b/docs/sql-ref-syntax-aux-show-tables.md @@ -29,7 +29,7 @@ current database. ### Syntax {% highlight sql %} -SHOW TABLES [ { FROM | IN } database_name ] [ LIKE 'regex_pattern' ] +SHOW TABLES [ { FROM | IN } database_name ] [ LIKE regex_pattern ] {% endhighlight %} ### Parameters @@ -39,14 +39,14 @@ SHOW TABLES [ { FROM | IN } database_name ] [ LIKE 'regex_pattern' ]
Specifies the database name from which tables are listed.
-
LIKE regex_pattern
+
regex_pattern
Specifies the regular expression pattern that is used to filter out unwanted tables.
    -
  • Except for `*` and `|` character, the pattern works like a regex.
  • -
  • `*` alone matches 0 or more characters and `|` is used to separate multiple different regexes, +
  • Except for * and | character, the pattern works like a regular expression.
  • +
  • * alone matches 0 or more characters and | is used to separate multiple different regular expressions, any of which can match.
  • -
  • The leading and trailing blanks are trimmed in the input pattern before processing.
  • +
  • The leading and trailing blanks are trimmed in the input pattern before processing. The pattern match is case-insensitive.
diff --git a/docs/sql-ref-syntax-aux-show-views.md b/docs/sql-ref-syntax-aux-show-views.md index aec3716c28..0d9210b024 100644 --- a/docs/sql-ref-syntax-aux-show-views.md +++ b/docs/sql-ref-syntax-aux-show-views.md @@ -30,7 +30,7 @@ regardless of a given database. ### Syntax {% highlight sql %} -SHOW VIEWS [ { FROM | IN } database_name ] [ LIKE 'regex_pattern' ] +SHOW VIEWS [ { FROM | IN } database_name ] [ LIKE regex_pattern ] {% endhighlight %} ### Parameters @@ -39,14 +39,14 @@ SHOW VIEWS [ { FROM | IN } database_name ] [ LIKE 'regex_pattern' ]
Specifies the database name from which views are listed.
-
LIKE regex_pattern
+
regex_pattern
- Specifies the regular expression pattern that is used to filter out unwanted views. + Specifies the regular expression pattern that is used to filter out unwanted views.
    -
  • Except for `*` and `|` character, the pattern works like a regex.
  • -
  • `*` alone matches 0 or more characters and `|` is used to separate multiple different regexes, +
  • Except for * and | character, the pattern works like a regular expression.
  • +
  • * alone matches 0 or more characters and | is used to separate multiple different regular expressions, any of which can match.
  • -
  • The leading and trailing blanks are trimmed in the input pattern before processing.
  • +
  • The leading and trailing blanks are trimmed in the input pattern before processing. The pattern match is case-insensitive.
diff --git a/docs/sql-ref-syntax-qry-explain.md b/docs/sql-ref-syntax-qry-explain.md index 6a7c2ace82..7ad297d9c7 100644 --- a/docs/sql-ref-syntax-qry-explain.md +++ b/docs/sql-ref-syntax-qry-explain.md @@ -27,7 +27,7 @@ By default, this clause provides information about a physical plan only. ### Syntax {% highlight sql %} -EXPLAIN [EXTENDED | CODEGEN | COST | FORMATTED] statement +EXPLAIN [ EXTENDED | CODEGEN | COST | FORMATTED ] statement {% endhighlight %} ### Parameters diff --git a/docs/sql-ref-syntax-qry-select-like.md b/docs/sql-ref-syntax-qry-select-like.md new file mode 100644 index 0000000000..408673c532 --- /dev/null +++ b/docs/sql-ref-syntax-qry-select-like.md @@ -0,0 +1,120 @@ +--- +layout: global +title: LIKE Predicate +displayTitle: LIKE Predicate +license: | + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--- + +### Description + +A LIKE predicate is used to search for a specific pattern. + +### Syntax + +{% highlight sql %} +[ NOT ] { LIKE search_pattern [ ESCAPE esc_char ] | RLIKE regex_pattern } +{% endhighlight %} + +### Parameters + +
+
search_pattern
+
+ Specifies a string pattern to be searched by the LIKE clause. It can contain special pattern-matching characters: +
    +
  • %
  • matches zero or more characters. +
  • _
  • matches exactly one character. +
+
+
+
+
esc_char
+
+ Specifies the escape character. The default escape character is \. +
+
+
+
regex_pattern
+
+ Specifies a regular expression search pattern to be searched by the RLIKE clause. +
+
+ +### Examples + +{% highlight sql %} +CREATE TABLE person (id INT, name STRING, age INT); +INSERT INTO person VALUES + (100, 'John', 30), + (200, 'Mary', NULL), + (300, 'Mike', 80), + (400, 'Dan', 50), + (500, 'Evan_w', 16); + +SELECT * FROM person WHERE name LIKE 'M%'; ++---+----+----+ +| id|name| age| ++---+----+----+ +|300|Mike| 80| +|200|Mary|null| ++---+----+----+ + +SELECT * FROM person WHERE name LIKE 'M_ry'; ++---+----+----+ +| id|name| age| ++---+----+----+ +|200|Mary|null| ++---+----+----+ + +SELECT * FROM person WHERE name NOT LIKE 'M_ry'; ++---+------+---+ +| id| name|age| ++---+------+---+ +|500|Evan_W| 16| +|300| Mike| 80| +|100| John| 30| +|400| Dan| 50| ++---+------+---+ + +SELECT * FROM person WHERE name RLIKE '[MD]'; ++---+----+----+ +| id|name| age| ++---+----+----+ +|300|Mike| 80| +|400| Dan| 50| +|200|Mary|null| ++---+----+----+ + +SELECT * FROM person WHERE name LIKE '%\_%'; ++---+------+---+ +| id| name|age| ++---+------+---+ +|500|Evan_W| 16| ++---+------+---+ + +SELECT * FROM person WHERE name LIKE '%$_%' ESCAPE '$'; ++---+------+---+ +| id| name|age| ++---+------+---+ +|500|Evan_W| 16| ++---+------+---+ +{% endhighlight %} + +### Related Statements + + * [SELECT](sql-ref-syntax-qry-select.html) + * [WHERE Clause](sql-ref-syntax-qry-select-where.html)