[chore](sql) Forbid show hidden columns and create table with hidden column (#38796) (#38924)

Forbid show hidden columns and create table with hidden column
This commit is contained in:
924060929
2024-08-06 14:24:41 +08:00
committed by GitHub
parent 75fe929dc4
commit fcb4483ed1
7 changed files with 57 additions and 8 deletions

View File

@ -311,6 +311,11 @@ public class CreateTableStmt extends DdlStmt {
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`.");
}

View File

@ -55,6 +55,7 @@ import java.util.Set;
*/
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__";
@ -62,6 +63,8 @@ public class Column implements Writable, GsonPostProcessable {
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";

View File

@ -3520,13 +3520,7 @@ public class Env {
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");

View File

@ -262,6 +262,11 @@ public class CreateTableInfo {
//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`.");