Skip to content
Closed
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
26 changes: 25 additions & 1 deletion fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -1130,7 +1130,31 @@ private void handleShowColumn() throws AnalysisException {
continue;
}
final String columnName = col.getName();
final String columnType = col.getOriginType().toString().toLowerCase(Locale.ROOT);
String columnType;
if (col.getOriginType().isDatetimeV2()) {
StringBuilder typeStr = new StringBuilder("DATETIME");
if (((ScalarType) col.getOriginType()).getScalarScale() > 0) {
typeStr.append("(").append(((ScalarType) col.getOriginType()).getScalarScale())
.append(")");
}
columnType = typeStr.toString().toLowerCase(Locale.ROOT);
} else if (col.getOriginType().isDateV2()) {
columnType = "date";
} else if (col.getOriginType().isDecimalV3()) {
StringBuilder typeStr = new StringBuilder("DECIMAL");
ScalarType sType = (ScalarType) col.getOriginType();
int scale = sType.getScalarScale();
int precision = sType.getScalarPrecision();
// not default
if (scale > 0 && precision != 9) {
typeStr.append("(").append(precision).append(", ").append(scale)
.append(")");
}
columnType = typeStr.toString().toLowerCase(Locale.ROOT);
} else {
columnType = col.getOriginType().toString().toLowerCase(Locale.ROOT);
}

final String isAllowNull = col.isAllowNull() ? "YES" : "NO";
final String isKey = col.isKey() ? "YES" : "NO";
final String defaultValue = col.getDefaultValue();
Expand Down
19 changes: 17 additions & 2 deletions fe/fe-core/src/test/java/org/apache/doris/qe/ShowExecutorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,14 @@ public void setUp() throws Exception {

Column column1 = new Column("col1", PrimitiveType.BIGINT);
Column column2 = new Column("col2", PrimitiveType.DOUBLE);
Column column3 = new Column("col3", PrimitiveType.DATEV2);
Column column4 = new Column("col4", PrimitiveType.DATETIMEV2);
Column column5 = new Column("col5", PrimitiveType.DECIMALV2);
column1.setIsKey(true);
column2.setIsKey(true);
column3.setIsKey(false);
column4.setIsKey(false);
column5.setIsKey(false);
// mock index 1
MaterializedIndex index1 = new MaterializedIndex();

Expand Down Expand Up @@ -119,7 +125,7 @@ public void setUp() throws Exception {

table.getBaseSchema();
minTimes = 0;
result = Lists.newArrayList(column1, column2);
result = Lists.newArrayList(column1, column2, column3, column4, column5);

table.getKeysType();
minTimes = 0;
Expand Down Expand Up @@ -502,6 +508,15 @@ public void testShowColumn() throws AnalysisException {
Assert.assertEquals("NO", resultSet.getString(2));
Assert.assertTrue(resultSet.next());
Assert.assertEquals("col2", resultSet.getString(0));
Assert.assertTrue(resultSet.next());
Assert.assertEquals("col3", resultSet.getString(0));
Assert.assertEquals("date", resultSet.getString(1));
Assert.assertTrue(resultSet.next());
Assert.assertEquals("col4", resultSet.getString(0));
Assert.assertEquals("datetime", resultSet.getString(1));
Assert.assertTrue(resultSet.next());
Assert.assertEquals("col5", resultSet.getString(0));
Assert.assertEquals("decimal(9, 0)", resultSet.getString(1));
Assert.assertFalse(resultSet.next());

// verbose
Expand All @@ -516,7 +531,7 @@ public void testShowColumn() throws AnalysisException {
Assert.assertTrue(resultSet.next());
Assert.assertEquals("col2", resultSet.getString(0));
Assert.assertEquals("NO", resultSet.getString(3));
Assert.assertFalse(resultSet.next());
Assert.assertTrue(resultSet.next());

// pattern
stmt = new ShowColumnStmt(new TableName(internalCtl, "testDb", "testTable"), null, "%1", true);
Expand Down