Skip to content

Commit

Permalink
Fix bug show full column does not display default value
Browse files Browse the repository at this point in the history
Signed-off-by: Astralidea <astralidea@163.com>
  • Loading branch information
Astralidea authored and wanpengfei-git committed Jul 24, 2023
1 parent b78bd1d commit 151f038
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
3 changes: 3 additions & 0 deletions fe/fe-core/src/main/java/com/starrocks/catalog/Column.java
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,9 @@ public String getMetaDefaultValue(List<String> extras) {
if ("now()".equalsIgnoreCase(defaultExpr.getExpr())) {
extras.add("DEFAULT_GENERATED");
return "CURRENT_TIMESTAMP";
} else {
extras.add("DEFAULT_GENERATED");
return defaultExpr.getExpr();
}
}
return FeConstants.null_string;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.starrocks.analysis;

import com.starrocks.common.Config;
import com.starrocks.common.FeConstants;
import com.starrocks.qe.ConnectContext;
import com.starrocks.qe.ShowExecutor;
import com.starrocks.qe.ShowResultSet;
import com.starrocks.server.GlobalStateMgr;
import com.starrocks.sql.ast.DropTableStmt;
import com.starrocks.sql.ast.ShowColumnStmt;
import com.starrocks.utframe.StarRocksAssert;
import com.starrocks.utframe.UtFrameUtils;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

public class ShowColumnStmtTest {

private static ConnectContext connectContext;
private static StarRocksAssert starRocksAssert;

@BeforeClass
public static void beforeClass() throws Exception {
FeConstants.runningUnitTest = true;
Config.dynamic_partition_enable = true;
Config.dynamic_partition_check_interval_seconds = 1;
Config.enable_strict_storage_medium_check = false;
UtFrameUtils.createMinStarRocksCluster();
UtFrameUtils.addMockBackend(10002);
UtFrameUtils.addMockBackend(10003);
// create connect context
connectContext = UtFrameUtils.createDefaultCtx();
starRocksAssert = new StarRocksAssert(connectContext);

starRocksAssert.withDatabase("test").useDatabase("test")
.withTable("create table test_default\n" +
"(id varchar(255) default (uuid()))\n" +
"distributed by hash(id)\n" +
"PROPERTIES ( \"replication_num\" = \"1\" )");
}

@AfterClass
public static void tearDown() throws Exception {
ConnectContext ctx = starRocksAssert.getCtx();
String dropSQL = "drop table test_default";
try {
DropTableStmt dropTableStmt = (DropTableStmt) UtFrameUtils.parseStmtWithNewParser(dropSQL, ctx);
GlobalStateMgr.getCurrentState().dropTable(dropTableStmt);
} catch (Exception ex) {

}
}

@Test
public void testShowDefaultValue() throws Exception {
ConnectContext ctx = starRocksAssert.getCtx();
String sql = "show full columns from test_default;";
ShowColumnStmt showColumnStmt = (ShowColumnStmt) UtFrameUtils.parseStmtWithNewParser(sql, ctx);
ShowExecutor executor = new ShowExecutor(ctx, showColumnStmt);
ShowResultSet resultSet = executor.execute();
Assert.assertEquals("uuid()", resultSet.getResultRows().get(0).get(5));
}

}

0 comments on commit 151f038

Please sign in to comment.