[Enchancement](compatible) show dateV2/datetimeV2 to date/datetime (#18358)
show dateV2/datetimeV2 to date/datetime modify show create table modify desc table use desc table all to get real type from column ColumnType
This commit is contained in:
@ -67,6 +67,7 @@ public class DescribeStmt extends ShowStmt {
|
||||
.addColumn(new Column("IndexKeysType", ScalarType.createVarchar(20)))
|
||||
.addColumn(new Column("Field", ScalarType.createVarchar(20)))
|
||||
.addColumn(new Column("Type", ScalarType.createVarchar(20)))
|
||||
.addColumn(new Column("InternalType", ScalarType.createVarchar(20)))
|
||||
.addColumn(new Column("Null", ScalarType.createVarchar(10)))
|
||||
.addColumn(new Column("Key", ScalarType.createVarchar(10)))
|
||||
.addColumn(new Column("Default", ScalarType.createVarchar(30)))
|
||||
@ -130,6 +131,11 @@ public class DescribeStmt extends ShowStmt {
|
||||
? FeConstants.null_string : column.getDefaultValue(),
|
||||
"NONE"
|
||||
);
|
||||
if (column.getOriginType().isDatetimeV2()) {
|
||||
row.set(1, "DATETIME");
|
||||
} else if (column.getOriginType().isDateV2()) {
|
||||
row.set(1, "DATE");
|
||||
}
|
||||
totalRows.add(row);
|
||||
}
|
||||
return;
|
||||
@ -205,6 +211,7 @@ public class DescribeStmt extends ShowStmt {
|
||||
"",
|
||||
column.getName(),
|
||||
column.getOriginType().toString(),
|
||||
column.getOriginType().toString(),
|
||||
column.isAllowNull() ? "Yes" : "No",
|
||||
((Boolean) column.isKey()).toString(),
|
||||
column.getDefaultValue() == null
|
||||
@ -215,6 +222,12 @@ public class DescribeStmt extends ShowStmt {
|
||||
column.getDefineExpr() == null ? "" : column.getDefineExpr().toSql(),
|
||||
"");
|
||||
|
||||
if (column.getOriginType().isDatetimeV2()) {
|
||||
row.set(3, "DATETIME");
|
||||
} else if (column.getOriginType().isDateV2()) {
|
||||
row.set(3, "DATE");
|
||||
}
|
||||
|
||||
if (j == 0) {
|
||||
row.set(0, indexName);
|
||||
row.set(1, indexMeta.getKeysType().name());
|
||||
|
||||
@ -633,14 +633,30 @@ public class Column implements Writable, GsonPostProcessable {
|
||||
}
|
||||
|
||||
public String toSql() {
|
||||
return toSql(false);
|
||||
return toSql(false, false);
|
||||
}
|
||||
|
||||
public String toSql(boolean isUniqueTable) {
|
||||
return toSql(isUniqueTable, false);
|
||||
}
|
||||
|
||||
public String toSql(boolean isUniqueTable, boolean isCompatible) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("`").append(name).append("` ");
|
||||
String typeStr = type.toSql();
|
||||
sb.append(typeStr);
|
||||
|
||||
// show change datetimeV2/dateV2 to datetime/date
|
||||
if (isCompatible) {
|
||||
if (type.isDatetimeV2()) {
|
||||
sb.append("datetime");
|
||||
} else if (type.isDateV2()) {
|
||||
sb.append("date");
|
||||
} else {
|
||||
sb.append(typeStr);
|
||||
}
|
||||
} else {
|
||||
sb.append(typeStr);
|
||||
}
|
||||
if (aggregationType != null && aggregationType != AggregateType.NONE && !isUniqueTable
|
||||
&& !isAggregationTypeImplicit) {
|
||||
sb.append(" ").append(aggregationType.name());
|
||||
|
||||
@ -2789,7 +2789,8 @@ public class Env {
|
||||
// There MUST BE 2 space in front of each column description line
|
||||
// sqlalchemy requires this to parse SHOW CREATE TABLE stmt.
|
||||
if (table.getType() == TableType.OLAP) {
|
||||
sb.append(" ").append(column.toSql(((OlapTable) table).getKeysType() == KeysType.UNIQUE_KEYS));
|
||||
sb.append(" ").append(
|
||||
column.toSql(((OlapTable) table).getKeysType() == KeysType.UNIQUE_KEYS, true));
|
||||
} else {
|
||||
sb.append(" ").append(column.toSql());
|
||||
}
|
||||
|
||||
@ -73,6 +73,13 @@ public class IndexSchemaProcNode implements ProcNodeInterface {
|
||||
column.getDefaultValue() == null
|
||||
? FeConstants.null_string : column.getDefaultValue(),
|
||||
extraStr);
|
||||
|
||||
if (column.getOriginType().isDateV2()) {
|
||||
rowList.set(1, "DATE");
|
||||
}
|
||||
if (column.getOriginType().isDatetimeV2()) {
|
||||
rowList.set(1, "DATETIME");
|
||||
}
|
||||
result.addRow(rowList);
|
||||
}
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user