Skip to content
80 changes: 79 additions & 1 deletion docs/sql-ref-syntax-aux-show-tables.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,83 @@ license: |
See the License for the specific language governing permissions and
limitations under the License.
---
### Description

**This page is under construction**
List all the `tables` from the database with `database-name` and `is temporary table`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shivusondur Sorry.. re-reading this one last time :-)
SHOW TABLES statement returns all the tables for an optionally specified database. Additionally, the output
of this statement may be filtered via an optional matching pattern. If no database is specified then the tables
are returned from the current database.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DOne


### Syntax
{% highlight sql %}
SHOW TABLES [{FROM|IN} database_name] [LIKE 'regex_pattern']
{% endhighlight %}

### Parameters
<dl>
<dt><code><em>{FROM|IN} database_name</em></code></dt>
<dd>
Specifies the `database` name from which tables are listed.
</dd>
<dt><code><em>LIKE 'regex_pattern'</em></code></dt>
<dd>
Specifies the regex pattern that is used to filter out unwanted tables.
<br> - Only `*` and `|` are allowed as wildcard pattern.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shivusondur Can you please include the example with output using the 'I' as wildcard ? From the code its not clear to me if this is supported.

@shivusondur shivusondur Sep 22, 2019

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

| isn't a wildcard pattern, so I wouldn't imply it is.
Is it really treated as a full regex otherwise? if not, I wouldn't call it a regex unless it is generally called this in other similar references.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@srowen Thats a very good point Sean. How about we name the pattern 'identifier_with_wildcards' (and describe as such) as mentioned in ShowTablesCommand's comment ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it a SQL-like pattern that supports wildcards like %? then I'd just call it a pattern

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@srowen I quickly tried in my env. It does not support SQL-like pattern like %. I only saw the following work :

  • * : Matches 0 or more characters.
  • . : Matches a char
  • | : works like or expression.

@shivusondur Can you please confirm ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dilipbiswal @srowen
I also tesed, it is same behaviour you mentioned above.
It will use the below method to handle, here they are handling "|" and "*" seperatly, remaining treating as regex

def filterPattern(names: Seq[String], pattern: String): Seq[String] = {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, your comment is consistent with the docs then. Hm, but isn't it more accurate to say that * and | don't work like in regexes? * matches 0 or more characters, and | delimits whole regexes, which is different, but the rest is the same. Maybe a comment more like that. "The pattern is a regex except that * matches 0 or more characters by itself, and | may only be used at the top level to delimit alternative regexes to match." ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@srowen @dilipbiswal
Thank you both for your time in reviewing.

I updated according to your suggestion and screenshot also I updated.
Now it will look like below.
image

<br> - Excluding `*` and `|` the remaining pattern follows the regex semantics.
<br> - The leading and trailing blanks are trimmed in the input pattern before processing.
</dd>
</dl>

### Example
{% highlight sql %}
-- List all tables in default database
SHOW TABLES;
+-----------+------------+--------------+--+

@dilipbiswal dilipbiswal Sep 21, 2019

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please lets fix the formatting. Did we construct this output by hand ? Can we paste the
actual output here please so we preserve the formatting.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dilipbiswal
I just Copy and paste the actual output from the Beeline console
Here is the beeline console snap
image

In the UI it looks like below, i think it is normal
image

Only in the git file editor, it shows inconsistent.

| database | tableName | isTemporary |
+-----------+------------+--------------+--+
| default | sam | false |
| default | sam1 | false |
| default | suj | false |
+-----------+------------+--------------+--+

-- List all tables from userdb database
SHOW TABLES FROM userdb;
+-----------+------------+--------------+--+
| database | tableName | isTemporary |
+-----------+------------+--------------+--+
| userdb | user1 | false |
| userdb | user2 | false |
+-----------+------------+--------------+--+

-- List all tables in userdb database
SHOW TABLES IN userdb;
+-----------+------------+--------------+--+
| database | tableName | isTemporary |
+-----------+------------+--------------+--+
| userdb | user1 | false |
| userdb | user2 | false |
+-----------+------------+--------------+--+

-- List all tables from default database matching the pattern `sam*`
SHOW TABLES FROM default LIKE 'sam*';
+-----------+------------+--------------+--+
| database | tableName | isTemporary |
+-----------+------------+--------------+--+
| default | sam | false |
| default | sam1 | false |
+-----------+------------+--------------+--+

-- List all tables matching the pattern `sam*|suj`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: can we have a line between previous test and this one.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dilipbiswal
Done, updated the snap's also.

SHOW TABLES LIKE 'sam*|suj';
+-----------+------------+--------------+--+
| database | tableName | isTemporary |
+-----------+------------+--------------+--+
| default | sam | false |
| default | sam1 | false |
| default | suj | false |
+-----------+------------+--------------+--+

{% endhighlight %}
Comment thread
shivusondur marked this conversation as resolved.
Outdated

### Related statements
- [CREATE TABLE](sql-ref-syntax-ddl-create-table.html)
- [DROP TABLE](sql-ref-syntax-ddl-drop-table.html)
- [CREATE DATABASE](sql-ref-syntax-ddl-create-database.html)
- [DROP DATABASE](sql-ref-syntax-ddl-drop-database.html)