[SQL][Function] Validate the param of rand function in compile step (#4439)
The param of rand() function should be literal, but current compiler ignore to validate the literal param of rand function, it is validated in execution step. This PR make it validated in compile step, and make it more earlier to find the usage error of rand() function.
This commit is contained in:
9
fe/fe-core/src/main/java/org/apache/doris/analysis/Expr.java
Normal file → Executable file
9
fe/fe-core/src/main/java/org/apache/doris/analysis/Expr.java
Normal file → Executable file
@ -1405,7 +1405,14 @@ abstract public class Expr extends TreeNode<Expr> implements ParseNode, Cloneabl
|
||||
throws AnalysisException {
|
||||
FunctionName fnName = new FunctionName(name);
|
||||
Function searchDesc = new Function(fnName, argTypes, Type.INVALID, false);
|
||||
return Catalog.getCurrentCatalog().getFunction(searchDesc, mode);
|
||||
Function f = Catalog.getCurrentCatalog().getFunction(searchDesc, mode);
|
||||
if (f != null && fnName.getFunction().equalsIgnoreCase("rand")) {
|
||||
if (this.children.size() == 1
|
||||
&& !(this.children.get(0) instanceof LiteralExpr)) {
|
||||
throw new AnalysisException("The param of rand function must be literal");
|
||||
}
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
15
fe/fe-core/src/test/java/org/apache/doris/analysis/SelectStmtTest.java
Normal file → Executable file
15
fe/fe-core/src/test/java/org/apache/doris/analysis/SelectStmtTest.java
Normal file → Executable file
@ -379,6 +379,21 @@ public class SelectStmtTest {
|
||||
dorisAssert.query(sql).explainQuery();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRandFunction() throws Exception {
|
||||
String sql = "select rand(db1.tbl1.k1) from db1.tbl1;";
|
||||
try {
|
||||
dorisAssert.query(sql).explainQuery();
|
||||
Assert.fail("The param of rand function must be literal");
|
||||
} catch (AnalysisException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
sql = "select rand(1234) from db1.tbl1;";
|
||||
dorisAssert.query(sql).explainQuery();
|
||||
sql = "select rand() from db1.tbl1;";
|
||||
dorisAssert.query(sql).explainQuery();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVarcharToLongSupport() throws Exception {
|
||||
String sql = "select count(*)\n" +
|
||||
|
||||
Reference in New Issue
Block a user