[chore](Nereids) more reasonable parse select list only query (#31346)

This commit is contained in:
morrySnow
2024-02-27 14:32:12 +08:00
committed by yiguolei
parent f039ec8cfb
commit 378ced72db
3 changed files with 27 additions and 27 deletions

View File

@ -1220,7 +1220,8 @@ public class LogicalPlanBuilder extends DorisParserBaseVisitor<Object> {
if (columnCtx.EXCEPT() != null) {
throw new ParseException("select-except cannot be used in one row relation", selectCtx);
}
relation = withOneRowRelation(columnCtx);
relation = new UnboundOneRowRelation(StatementScopeIdGenerator.newRelationId(),
ImmutableList.of(new UnboundAlias(Literal.of(0))));
} else {
relation = visitFromClause(ctx.fromClause());
}

View File

@ -46,7 +46,7 @@ import java.util.Map;
// this ut will add more test case later
public class FunctionRegistryTest implements MemoPatternMatchSupported {
private ConnectContext connectContext = MemoTestUtils.createConnectContext();
private final ConnectContext connectContext = MemoTestUtils.createConnectContext();
@Test
public void testDefaultFunctionNameIsClassName() {
@ -55,8 +55,8 @@ public class FunctionRegistryTest implements MemoPatternMatchSupported {
PlanChecker.from(connectContext)
.analyze("select year('2021-01-01')")
.matches(
logicalOneRowRelation().when(r -> {
Year year = (Year) r.getProjects().get(0).child(0);
logicalProject().when(project -> {
Year year = (Year) project.getProjects().get(0).child(0);
Assertions.assertEquals("2021-01-01",
((Literal) year.getArguments().get(0).child(0)).getValue());
return true;
@ -72,14 +72,14 @@ public class FunctionRegistryTest implements MemoPatternMatchSupported {
PlanChecker.from(connectContext)
.analyze("select substring('abc', 1, 2), substr(substring('abcdefg', 4, 3), 1, 2)")
.matches(
logicalOneRowRelation().when(r -> {
Substring firstSubstring = (Substring) r.getProjects().get(0).child(0);
logicalProject().when(project -> {
Substring firstSubstring = (Substring) project.getProjects().get(0).child(0);
Assertions.assertEquals("abc", ((Literal) firstSubstring.getSource()).getValue());
Assertions.assertEquals(1, ((Literal) firstSubstring.getPosition()).getValue());
Assertions.assertEquals(2, ((Literal) firstSubstring.getLength().get()).getValue());
Substring secondSubstring = (Substring) r.getProjects().get(1).child(0);
Assertions.assertTrue(secondSubstring.getSource() instanceof Substring);
Substring secondSubstring = (Substring) project.getProjects().get(1).child(0);
Assertions.assertInstanceOf(Substring.class, secondSubstring.getSource());
Assertions.assertEquals(1, ((Literal) secondSubstring.getPosition()).getValue());
Assertions.assertEquals(2, ((Literal) secondSubstring.getLength().get()).getValue());
return true;
@ -95,13 +95,13 @@ public class FunctionRegistryTest implements MemoPatternMatchSupported {
PlanChecker.from(connectContext)
.analyze("select substr('abc', 1), substring('def', 2, 3)")
.matches(
logicalOneRowRelation().when(r -> {
Substring firstSubstring = (Substring) r.getProjects().get(0).child(0);
logicalProject().when(project -> {
Substring firstSubstring = (Substring) project.getProjects().get(0).child(0);
Assertions.assertEquals("abc", ((Literal) firstSubstring.getSource()).getValue());
Assertions.assertEquals(1, ((Literal) firstSubstring.getPosition()).getValue());
Assertions.assertTrue(firstSubstring.getLength().isPresent());
Substring secondSubstring = (Substring) r.getProjects().get(1).child(0);
Substring secondSubstring = (Substring) project.getProjects().get(1).child(0);
Assertions.assertEquals("def", ((Literal) secondSubstring.getSource()).getValue());
Assertions.assertEquals(2, ((Literal) secondSubstring.getPosition()).getValue());
Assertions.assertEquals(3, ((Literal) secondSubstring.getLength().get()).getValue());
@ -111,7 +111,7 @@ public class FunctionRegistryTest implements MemoPatternMatchSupported {
}
@Test
public void testAddFunction() throws Exception {
public void testAddFunction() {
FunctionRegistry functionRegistry = new FunctionRegistry() {
@Override
protected void afterRegisterBuiltinFunctions(Map<String, List<FunctionBuilder>> name2builders) {
@ -136,9 +136,8 @@ public class FunctionRegistryTest implements MemoPatternMatchSupported {
};
// currently we can not support the override same arity function with difference types
Assertions.assertThrowsExactly(AnalysisException.class, () -> {
functionRegistry.findFunctionBuilder("abc", ImmutableList.of(Literal.of(1)));
});
Assertions.assertThrowsExactly(AnalysisException.class,
() -> functionRegistry.findFunctionBuilder("abc", ImmutableList.of(Literal.of(1))));
}
public static class ExtendFunction extends BoundFunction implements UnaryExpression, PropagateNullable,

View File

@ -71,8 +71,8 @@ public class UdfTest extends TestWithFeService implements PlanPatternMatchSuppor
PlanChecker.from(connectContext)
.analyze(sql)
.matches(
logicalOneRowRelation()
.when(relation -> relation.getProjects().get(0).child(0).equals(expected))
logicalProject()
.when(project -> project.getProjects().get(0).child(0).equals(expected))
);
connectContext.setDatabase("test_1");
@ -80,8 +80,8 @@ public class UdfTest extends TestWithFeService implements PlanPatternMatchSuppor
PlanChecker.from(connectContext)
.analyze(sql)
.matches(
logicalOneRowRelation()
.when(relation -> relation.getProjects().get(0).child(0).equals(expected1))
logicalProject()
.when(project -> project.getProjects().get(0).child(0).equals(expected1))
);
sql = "select test.f(3)";
@ -89,8 +89,8 @@ public class UdfTest extends TestWithFeService implements PlanPatternMatchSuppor
PlanChecker.from(connectContext)
.analyze(sql)
.matches(
logicalOneRowRelation()
.when(relation -> relation.getProjects().get(0).child(0).equals(expected2))
logicalProject()
.when(project -> project.getProjects().get(0).child(0).equals(expected2))
);
}
@ -129,9 +129,9 @@ public class UdfTest extends TestWithFeService implements PlanPatternMatchSuppor
PlanChecker.from(connectContext)
.analyze(sql)
.matches(
logicalOneRowRelation()
.when(relation -> relation.getProjects().size() == 1
&& relation.getProjects().get(0).child(0).equals(expected))
logicalProject()
.when(project -> project.getProjects().size() == 1
&& project.getProjects().get(0).child(0).equals(expected))
);
}
@ -172,9 +172,9 @@ public class UdfTest extends TestWithFeService implements PlanPatternMatchSuppor
PlanChecker.from(connectContext)
.analyze(sql)
.matches(
logicalOneRowRelation()
.when(relation -> relation.getProjects().size() == 1
&& relation.getProjects().get(0).child(0).equals(expected))
logicalProject()
.when(project -> project.getProjects().size() == 1
&& project.getProjects().get(0).child(0).equals(expected))
);
}