Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# SHOW FULL COLUMNS
## description
该语句用于指定表的列信息
语法:
SHOW FULL COLUMNS FROM tbl;

## example
1. 查看指定表的列信息

SHOW FULL COLUMNS FROM tbl;

## keyword

SHOW,TABLE,STATUS
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# SHOW TABLE STATUS
## description
该语句用于查看 Table 的一些信息。
语法:
SHOW TABLE STATUS
[FROM db] [LIKE "pattern"]

说明:
1. 该语句主要用于兼容 MySQL 语法,目前仅显示 Comment 等少量信息

## example
1. 查看当前数据库下所有表的信息

SHOW TABLE STATUS;

2. 查看指定数据库下,名称包含 example 的表的信息

SHOW TABLE STATUS FROM db LIKE "%example%";

## keyword

SHOW,TABLE,STATUS
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
(column_definition1[, column_definition2, ...])
[ENGINE = [olap|mysql|broker]]
[key_desc]
[COMMENT "table comment"];
[partition_desc]
[distribution_desc]
[PROPERTIES ("key"="value", ...)];
[BROKER PROPERTIES ("key"="value", ...)];
[PROPERTIES ("key"="value", ...)]
[BROKER PROPERTIES ("key"="value", ...)]

1. column_definition
语法:
Expand Down Expand Up @@ -191,6 +192,7 @@
)
ENGINE=olap
AGGREGATE KEY(k1, k2)
COMMENT "my first doris table"
DISTRIBUTED BY HASH(k1) BUCKETS 32
PROPERTIES ("storage_type"="column");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
该语句用于创建一个逻辑视图
语法:
CREATE VIEW [IF NOT EXISTS]
[db_name.]view_name (column1[, column2, ...])
[db_name.]view_name
(column1[ COMMENT "col comment"][, column2, ...])
AS query_stmt

说明:
Expand All @@ -12,10 +13,25 @@

## example
1. 在 example_db 上创建视图 example_view

CREATE VIEW example_db.example_view (k1, k2, k3, v1)
AS
SELECT c1 as k1, k2, k3, SUM(v1) FROM example_table
WHERE k1 = 20160112 GROUP BY k1,k2,k3;

2. 创建一个包含 comment 的 view

CREATE VIEW example_db.example_view
(
k1 COMMENT "first key",
k2 COMMENT "second key",
k3 COMMENT "third key",
v1 COMMENT "first value"
)
COMMENT "my first view"
AS
SELECT c1 as k1, k2, k3, SUM(v1) FROM example_table
WHERE k1 = 20160112 GROUP BY k1,k2,k3;

## keyword
CREATE,VIEW
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# SHOW FULL COLUMNS
## description
This statement is used to view some information about columns of a table.

Syntax:
SHOW FULL COLUMNS FROM tbl;

## example

1. View the column information of specified table

SHOW FULL COLUMNS FROM tbl;

## keyword

SHOW,FULL,COLUMNS
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# SHOW TABLE STATUS

## description

This statement is used to view some information about Table.

Syntax:

SHOW TABLE STATUS
[FROM db] [LIKE "pattern"]

Explain:

1. This statement is mainly used to be compatible with MySQL grammar. At present, only a small amount of information such as Comment is displayed.

## Example

1. View the information of all tables under the current database

SHOW TABLE STATUS;


2. View the information of the table whose name contains example in the specified database

SHOW TABLE STATUS FROM DB LIKE "% example%";

## Keyword

SHOW,TABLE,STATUS
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@

### Syntax

CREATE [EXTERNAL] TABLE [IF NOT EXISTS] [database.]table_name
(column_definition1[, column_definition2, ...])
[ENGINE = [olap|mysql|broker]]
[key_desc]
[partition_desc]
[distribution_desc]
[PROPERTIES ("key"="value", ...)];
[BROKER PROPERTIES ("key"="value", ...)];
CREATE [EXTERNAL] TABLE [IF NOT EXISTS] [database.]table_name
(column_definition1[, column_definition2, ...])
[ENGINE = [olap|mysql|broker]]
[key_desc]
[COMMENT "table comment"]
[partition_desc]
[distribution_desc]
[PROPERTIES ("key"="value", ...)]
[BROKER PROPERTIES ("key"="value", ...)];

1. column_definition

Expand Down Expand Up @@ -222,6 +223,7 @@ CREATE [EXTERNAL] TABLE [IF NOT EXISTS] [database.]table_name
)
ENGINE=olap
AGGREGATE KEY(k1, k2)
COMMENT "my first doris table"
DISTRIBUTED BY HASH(k1) BUCKETS 32
PROPERTIES ("storage_type"="column");
```
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,42 @@
# CREATE VIEW
## Description
This statement is used to create a logical view
Grammar:
CREATE VIEW [IF NOT EXISTS]
[db_name.]view_name (column1[, column2, ...])
AS query
This statement is used to create a logical view
Grammar:

CREATE VIEW [IF NOT EXISTS]
[db_name.]view_name
(column1[ COMMENT "col comment"][, column2, ...])
AS query_stmt

Explain:
1. Views are logical views without physical storage. All queries on views are equivalent to sub-queries corresponding to views.
2. Query_stmt is arbitrarily supported SQL
Explain:

1. Views are logical views without physical storage. All queries on views are equivalent to sub-queries corresponding to views.
2. query_stmt is arbitrarily supported SQL.

## example
1. Create view example_view on example_db
CREATE VIEW example_db.example_view (k1, k2, k3, v1)
AS
SELECT c1 as k1, k2, k3, SUM(v1) FROM example_table
WHERE k1 = 20160112 GROUP BY k1,k2,k3;

1. Create view example_view on example_db

CREATE VIEW example_db.example_view (k1, k2, k3, v1)
AS
SELECT c1 as k1, k2, k3, SUM(v1) FROM example_table
WHERE k1 = 20160112 GROUP BY k1,k2,k3;

2. Create view with comment

CREATE VIEW example_db.example_view
(
k1 COMMENT "first key",
k2 COMMENT "second key",
k3 COMMENT "third key",
v1 COMMENT "first value"
)
COMMENT "my first view"
AS
SELECT c1 as k1, k2, k3, SUM(v1) FROM example_table
WHERE k1 = 20160112 GROUP BY k1,k2,k3;

## keyword
CREATE,VIEW

CREATE,VIEW

40 changes: 37 additions & 3 deletions fe/src/main/cup/sql_parser.cup
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,8 @@ nonterminal String opt_system;
nonterminal String opt_cluster;
nonterminal BrokerDesc opt_broker;
nonterminal List<String> opt_col_list, col_list, opt_dup_keys, opt_columns_from_path;
nonterminal List<ColWithComment> opt_col_with_comment_list, col_with_comment_list;
nonterminal ColWithComment col_with_comment;
nonterminal List<String> opt_partitions, partitions;
nonterminal List<Expr> opt_col_mapping_list;
nonterminal ColumnSeparator opt_field_term, column_separator;
Expand Down Expand Up @@ -877,22 +879,23 @@ create_stmt ::=
| KW_CREATE opt_external:isExternal KW_TABLE opt_if_not_exists:ifNotExists table_name:name
LPAREN column_definition_list:columns RPAREN opt_engine:engineName
opt_keys:keys
opt_comment:tableComment
opt_partition:partition
opt_distribution:distribution
opt_properties:tblProperties
opt_ext_properties:extProperties
{:
RESULT = new CreateTableStmt(ifNotExists, isExternal, name, columns, engineName, keys, partition, distribution, tblProperties, extProperties);
RESULT = new CreateTableStmt(ifNotExists, isExternal, name, columns, engineName, keys, partition, distribution, tblProperties, extProperties, tableComment);
:}
/* User */
| KW_CREATE KW_USER opt_if_not_exists:ifNotExists grant_user:user opt_user_role:userRole
{:
RESULT = new CreateUserStmt(ifNotExists, user, userRole);
:}
| KW_CREATE KW_VIEW opt_if_not_exists:ifNotExists table_name:viewName
opt_col_list:columns KW_AS query_stmt:view_def
opt_col_with_comment_list:columns opt_comment:comment KW_AS query_stmt:view_def
{:
RESULT = new CreateViewStmt(ifNotExists, viewName, columns, view_def);
RESULT = new CreateViewStmt(ifNotExists, viewName, columns, comment, view_def);
:}
/* cluster */
| KW_CREATE KW_CLUSTER ident:name opt_properties:properties KW_IDENTIFIED KW_BY STRING_LITERAL:password
Expand Down Expand Up @@ -1133,6 +1136,37 @@ opt_col_list ::=
:}
;

opt_col_with_comment_list ::=
{:
RESULT = null;
:}
| LPAREN col_with_comment_list:colList RPAREN
{:
RESULT = colList;
:}
;

col_with_comment_list ::=
col_with_comment:col
{:
ArrayList<ColWithComment> list = new ArrayList<ColWithComment>();
list.add(col);
RESULT = list;
:}
| col_with_comment_list:list COMMA col_with_comment:col
{:
list.add(col);
RESULT = list;
:}
;

col_with_comment ::=
ident:col opt_comment:comment
{:
RESULT = new ColWithComment(col, comment);
:}
;

col_list ::=
KW_COLUMNS LPAREN ident_list:colList RPAREN
{:
Expand Down
55 changes: 55 additions & 0 deletions fe/src/main/java/org/apache/doris/analysis/ColWithComment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// 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.

package org.apache.doris.analysis;

import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.FeNameFormat;

import com.google.common.base.Strings;

public class ColWithComment {

private String colName;
private String comment;

public ColWithComment(String colName, String comment) {
this.colName = colName;
this.comment = Strings.nullToEmpty(comment);
}

public void analyze() throws AnalysisException {
FeNameFormat.checkColumnName(colName);
}

public String getColName() {
return colName;
}

public String getComment() {
return comment;
}

@Override
public String toString() {
String str = "`" + colName + "`";
if (!comment.isEmpty()) {
str += " COMMENT \"" + comment + "\"";
}
return str;
}
}
Loading