Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 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
2 changes: 2 additions & 0 deletions docs/_data/menu-sql.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@
subitems:
- text: Data Types
url: sql-ref-datatypes.html
- text: Identifiers
url: sql-ref-identifier.html
- text: Literals
url: sql-ref-literals.html
- text: Null Semantics
Expand Down
76 changes: 76 additions & 0 deletions docs/sql-ref-identifier.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
---
layout: global
title: Identifiers
displayTitle: Identifiers
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

An identifier is a string used to identify a database object such as a table, view, schema, column, etc. Spark SQL has regular identifiers and delimited identifiers, which are enclosed within backticks. When `spark.sql.caseSensitive` is set to false (default behavior since Spark 2.4), both regular identifiers and delimited identifiers are case-insensitive.

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.

spark.sql.caseSensitive is an internal config. Shall we ignore it and just say Spark is case insensitive in the doc?

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.

Sure. Will update.


### Syntax

#### Regular Identifier

{% highlight sql %}
{ letter | digit | '_' } [ , ... ]
{% endhighlight %}
Note: If `spark.sql.ansi.enabled` is set to true, ANSI SQL reserved keywords cannot be used as identifiers. For more details, please refer to [ANSI Compliance](sql-ref-ansi-compliance.html) for a complete list of the keywords.

#### Delimited Identifier

{% highlight sql %}
`c [ ... ]`
{% endhighlight %}

### Parameters

<dl>
<dt><code><em>letter</em></code></dt>
<dd>
Any letter from A-Z or a-z.
</dd>
</dl>
<dl>
<dt><code><em>digit</em></code></dt>
<dd>
Any numeral from 0 to 9.
</dd>
</dl>
<dl>
<dt><code><em>c</em></code></dt>
<dd>
Any character from the character set. Use <code>`</code> to escape special characters (e.g., <code>`</code>).
</dd>
</dl>

### Examples

{% highlight sql %}
-- This CREATE TABLE fails because of the illegal identifier name a.b
CREATE TABLE test (a.b int);

-- This CREATE TABLE works
CREATE TABLE test (`a.b` int);

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.

We don't need to describe a multi-part name like a.b.c for DSv2? @cloud-fan

@cloud-fan cloud-fan Apr 24, 2020

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.

It's still evolving, we don't mention anything about it in the sql reference for now.


-- This CREATE TABLE fails
CREATE TABLE test1 (`a`b` int);

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.

this should fail the parser?

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.

Yes. This throws ParseException. Do you want me to change L71 to
-- This CREATE TABLE fails with ParseException?

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.

Can we include the error message in the example?

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.

Updated. Thanks!


-- This CREATE TABLE works
CREATE TABLE test (`a``b` int);
{% endhighlight %}