-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Enhancement] (nereids)implement showTableCreationCommand in nereids #…
- Loading branch information
Showing
6 changed files
with
198 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
...src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowTableCreationCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// 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.nereids.trees.plans.commands; | ||
|
||
import org.apache.doris.catalog.Column; | ||
import org.apache.doris.catalog.ScalarType; | ||
import org.apache.doris.common.ErrorCode; | ||
import org.apache.doris.common.ErrorReport; | ||
import org.apache.doris.common.util.ListComparator; | ||
import org.apache.doris.common.util.OrderByPair; | ||
import org.apache.doris.nereids.trees.plans.PlanType; | ||
import org.apache.doris.nereids.trees.plans.visitor.PlanVisitor; | ||
import org.apache.doris.qe.ConnectContext; | ||
import org.apache.doris.qe.ShowResultSet; | ||
import org.apache.doris.qe.ShowResultSetMetaData; | ||
import org.apache.doris.qe.StmtExecutor; | ||
|
||
import com.google.common.base.Strings; | ||
import com.google.common.collect.Lists; | ||
|
||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
/** | ||
* show table id command | ||
*/ | ||
public class ShowTableCreationCommand extends ShowCommand { | ||
private static final ShowResultSetMetaData META_DATA = | ||
ShowResultSetMetaData.builder() | ||
.addColumn(new Column("Database", ScalarType.createVarchar(20))) | ||
.addColumn(new Column("Table", ScalarType.createVarchar(20))) | ||
.addColumn(new Column("Status", ScalarType.createVarchar(10))) | ||
.addColumn(new Column("Create Time", ScalarType.createVarchar(20))) | ||
.addColumn(new Column("Error Msg", ScalarType.createVarchar(100))) | ||
.build(); | ||
|
||
private String dbName; | ||
private String wild; | ||
|
||
/** | ||
* constructor | ||
*/ | ||
public ShowTableCreationCommand(String dbName, String wild) { | ||
super(PlanType.SHOW_TABLE_CREATION_COMMAND); | ||
this.dbName = dbName; | ||
this.wild = wild; | ||
} | ||
|
||
@Override | ||
public ShowResultSet doRun(ConnectContext ctx, StmtExecutor executor) throws Exception { | ||
if (Strings.isNullOrEmpty(dbName)) { | ||
dbName = ConnectContext.get().getDatabase(); | ||
if (Strings.isNullOrEmpty(dbName)) { | ||
ErrorReport.reportAnalysisException(ErrorCode.ERR_NO_DB_ERROR); | ||
} | ||
} | ||
|
||
/* Need to implement fetching records from iceberg table */ | ||
List<List<Comparable>> rowSet = Lists.newArrayList(); | ||
// sort function rows by fourth column (Create Time) asc | ||
ListComparator<List<Comparable>> comparator = null; | ||
OrderByPair orderByPair = new OrderByPair(3, false); | ||
comparator = new ListComparator<>(orderByPair); | ||
Collections.sort(rowSet, comparator); | ||
List<List<String>> resultRowSet = Lists.newArrayList(); | ||
|
||
Set<String> keyNameSet = new HashSet<>(); | ||
for (List<Comparable> row : rowSet) { | ||
List<String> resultRow = Lists.newArrayList(); | ||
for (Comparable column : row) { | ||
resultRow.add(column.toString()); | ||
} | ||
resultRowSet.add(resultRow); | ||
keyNameSet.add(resultRow.get(0)); | ||
} | ||
|
||
return new ShowResultSet(META_DATA, resultRowSet); | ||
} | ||
|
||
@Override | ||
public <R, C> R accept(PlanVisitor<R, C> visitor, C context) { | ||
return visitor.visitShowTableCreationCommand(this, context); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
regression-test/suites/nereids_p0/show/test_nereids_show_table_creation.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package show | ||
// 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. | ||
|
||
|
||
suite("test_nereids_show_table_creation") { | ||
def table = "test_nereids_show_table_creation" | ||
// create table and insert data | ||
String dbName = 'test_nereids_show_table_creation' | ||
try_sql """drop database if exists ${dbName}""" | ||
sql """create database ${dbName}""" | ||
sql """ drop table if exists ${dbName}.${table} force""" | ||
|
||
sql """ | ||
create table ${dbName}.${table} ( | ||
`id` int(11), | ||
`name` varchar(128), | ||
`da` date | ||
) | ||
engine=olap | ||
duplicate key(id) | ||
partition by range(da)( | ||
PARTITION p3 VALUES LESS THAN ('2023-01-01'), | ||
PARTITION p4 VALUES LESS THAN ('2024-01-01'), | ||
PARTITION p5 VALUES LESS THAN ('2025-01-01') | ||
) | ||
distributed by hash(id) buckets 2 | ||
properties( | ||
"replication_num"="1", | ||
"light_schema_change"="true" | ||
); | ||
""" | ||
|
||
checkNereidsExecute("SHOW TABLE CREATION FROM ${dbName}") | ||
checkNereidsExecute("SHOW TABLE CREATION IN ${dbName}") | ||
checkNereidsExecute("SHOW TABLE CREATION FROM ${dbName} like '%${table}%'") | ||
checkNereidsExecute("SHOW TABLE CREATION like '%${table}%'") | ||
checkNereidsExecute("SHOW TABLE CREATION") | ||
|
||
def res = sql """SHOW TABLE CREATION FROM ${dbName}""" | ||
assertTrue(res.size() == 0) | ||
|
||
res = sql """SHOW TABLE CREATION IN ${dbName}""" | ||
assertTrue(res.size() == 0) | ||
|
||
res = sql """SHOW TABLE CREATION FROM ${dbName} like '%${table}%'""" | ||
assertTrue(res.size() == 0) | ||
|
||
res = sql """SHOW TABLE CREATION like '%${table}%'""" | ||
assertTrue(res.size() == 0) | ||
|
||
res = sql """SHOW TABLE CREATION""" | ||
assertTrue(res.size() == 0) | ||
|
||
} | ||
|