Skip to content

Commit

Permalink
[chore](sql) Forbid show hidden columns and create table with hidden …
Browse files Browse the repository at this point in the history
…column (apache#38796)

Forbid show hidden columns and create table with hidden column

(cherry picked from commit 9eae4ba)
  • Loading branch information
924060929 committed Aug 6, 2024
1 parent ff6fa33 commit fb38c41
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,11 @@ public void analyze(Analyzer analyzer) throws UserException {
if (Objects.equals(columnDef.getType(), Type.ALL)) {
throw new AnalysisException("Disable to create table with `ALL` type columns.");
}
String columnNameUpperCase = columnDef.getName().toUpperCase();
if (columnNameUpperCase.startsWith("__DORIS_")) {
throw new AnalysisException(
"Disable to create table column with name start with __DORIS_: " + columnNameUpperCase);
}
if (Objects.equals(columnDef.getType(), Type.DATE) && Config.disable_datev1) {
throw new AnalysisException("Disable to create table with `DATE` type columns, please use `DATEV2`.");
}
Expand Down
3 changes: 3 additions & 0 deletions fe/fe-core/src/main/java/org/apache/doris/catalog/Column.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,16 @@
*/
public class Column implements Writable, GsonPostProcessable {
private static final Logger LOG = LogManager.getLogger(Column.class);
// NOTE: you should name hidden column start with '__DORIS_' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
public static final String DELETE_SIGN = "__DORIS_DELETE_SIGN__";
public static final String WHERE_SIGN = "__DORIS_WHERE_SIGN__";
public static final String SEQUENCE_COL = "__DORIS_SEQUENCE_COL__";
public static final String ROWID_COL = "__DORIS_ROWID_COL__";
public static final String ROW_STORE_COL = "__DORIS_ROW_STORE_COL__";
public static final String DYNAMIC_COLUMN_NAME = "__DORIS_DYNAMIC_COL__";
public static final String VERSION_COL = "__DORIS_VERSION_COL__";
// NOTE: you should name hidden column start with '__DORIS_' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

private static final String COLUMN_ARRAY_CHILDREN = "item";
private static final String COLUMN_STRUCT_CHILDREN = "field";
private static final String COLUMN_AGG_ARGUMENT_CHILDREN = "argument";
Expand Down
8 changes: 1 addition & 7 deletions fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java
Original file line number Diff line number Diff line change
Expand Up @@ -3520,13 +3520,7 @@ public static void getDdlStmt(DdlStmt ddlStmt, String dbName, TableIf table, Lis

sb.append(" (\n");
int idx = 0;
List<Column> columns;
// when 'create table B like A', always return schema of A without hidden columns
if (getDdlForLike) {
columns = table.getBaseSchema(false);
} else {
columns = table.getBaseSchema();
}
List<Column> columns = table.getBaseSchema(false);
for (Column column : columns) {
if (idx++ != 0) {
sb.append(",\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,11 @@ public void validate(ConnectContext ctx) {

//check datev1 and decimalv2
for (ColumnDefinition columnDef : columns) {
String columnNameUpperCase = columnDef.getName().toUpperCase();
if (columnNameUpperCase.startsWith("__DORIS_")) {
throw new AnalysisException(
"Disable to create table column with name start with __DORIS_: " + columnNameUpperCase);
}
if (columnDef.getType().isDateType() && Config.disable_datev1) {
throw new AnalysisException(
"Disable to create table with `DATE` type columns, please use `DATEV2`.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ class TestAction implements SuiteAction {
this.exception = exceptionMsgSupplier.call()
}

void check(@ClosureParams(value = FromString, options = ["String,Throwable,Long,Long"]) Closure check) {
void check(@ClosureParams(value = FromString, options = ["List<List<Object>>,Throwable,Long,Long"]) Closure check) {
this.check = check
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,30 @@
// specific language governing permissions and limitations
// under the License.

import org.apache.doris.regression.util.JdbcUtils

suite("test_show_create_table_and_views", "show") {
sql "SET enable_nereids_planner=false;"

def shouldNotShowHiddenColumnsAndCreateWithHiddenColumns = {
connect {
multi_sql """
SET enable_nereids_planner=false;
drop table if exists test_show_create_table_no_hidden_column;
create table test_show_create_table_no_hidden_column(id int, name varchar(50)) unique key(id) distributed by hash(id) properties('replication_num'='1');
set show_hidden_columns=true;
"""

def result = JdbcUtils.executeToMapArray(context.getConnection(), "show create table test_show_create_table_no_hidden_column")
assertTrue(!result[0].get("Create Table").toString().contains("__DORIS_DELETE_SIGN__"))

test {
sql "create table table_with_hidden_sign(id int, __DORIS_DELETE_SIGN__ int) distributed by hash(id) properties('replication_num'='1')"
exception "Disable to create table column with name start with __DORIS_: "
}
}
}()

def ret = sql "SHOW FRONTEND CONFIG like '%enable_feature_binlog%';"
logger.info("${ret}")
if (ret.size() != 0 && ret[0].size() > 1 && ret[0][1] == 'false') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,27 @@
// specific language governing permissions and limitations
// under the License.

import org.apache.doris.regression.util.JdbcUtils

suite("test_show_create_table_and_views_nereids", "show") {
def shouldNotShowHiddenColumnsAndCreateWithHiddenColumns = {
connect {
multi_sql """
drop table if exists test_show_create_table_no_hidden_column;
create table test_show_create_table_no_hidden_column(id int, name varchar(50)) unique key(id) distributed by hash(id) properties('replication_num'='1');
set show_hidden_columns=true;
"""

def result = JdbcUtils.executeToMapArray(context.getConnection(), "show create table test_show_create_table_no_hidden_column")
assertTrue(!result[0].get("Create Table").toString().contains("__DORIS_DELETE_SIGN__"))

test {
sql "create table table_with_hidden_sign(id int, __DORIS_DELETE_SIGN__ int) distributed by hash(id) properties('replication_num'='1')"
exception "Disable to create table column with name start with __DORIS_: "
}
}
}()

def ret = sql "SHOW FRONTEND CONFIG like '%enable_feature_binlog%';"
logger.info("${ret}")
if (ret.size() != 0 && ret[0].size() > 1 && ret[0][1] == 'false') {
Expand Down

0 comments on commit fb38c41

Please sign in to comment.