提交 68f0dfec authored 作者: Owner's avatar Owner

Added extra test case and help.csv syntax doc

上级 9146ede1
......@@ -193,12 +193,16 @@ SHOW TABLES
"
"Commands (DML)","WITH","
WITH [ RECURSIVE ] name ( columnName [,...] )
AS ( select )
WITH [ RECURSIVE ] { name [( columnName [,...] )]
AS ( select ) [,...] }
select
","
Can be used to create a recursive query. The first select has to be a UNION.
Currently only one result set can be referred to by name.
Can be used to create a recursive query.
For recursive queries the first select has to be a UNION.
Non-recursive queries are also supported,
One or more common table entries can be use referred to by name.
Column name declarations are now optional - the column names will be gleaned from the named select queries.
Positional parameters are not currently correctly supported.
","
WITH RECURSIVE t(n) AS (
SELECT 1
......@@ -208,6 +212,14 @@ WITH RECURSIVE t(n) AS (
WHERE n < 100
)
SELECT sum(n) FROM t;
","
WITH t1 AS (
SELECT 1 AS FIRST_COLUMN
),
t2 AS (
SELECT FIRST_COLUMN+1 AS FIRST_COLUMN FROM t1
)
SELECT sum(FIRST_COLUMN) FROM t2;
"
"Commands (DDL)","ALTER INDEX RENAME","
......
......@@ -4907,9 +4907,9 @@ public class Parser {
querySQL = StringUtils.cache(withQuery.getPlanSQL());
ArrayList<Expression> withExpressions = withQuery.getExpressions();
for (int i = 0; i < withExpressions.size(); ++i) {
System.out.println("columnName="+withExpressions.get(i).getColumnName());
System.out.println("alias="+withExpressions.get(i).getAlias());
System.out.println("nonAliasExpression="+withExpressions.get(i).getNonAliasExpression());
//System.out.println("columnName="+withExpressions.get(i).getColumnName());
//System.out.println("alias="+withExpressions.get(i).getAlias());
//System.out.println("nonAliasExpression="+withExpressions.get(i).getNonAliasExpression());
String columnName = cols != null ? cols[i] : withExpressions.get(i).getColumnName();
columnTemplateList.add(new Column(columnName, withExpressions.get(i).getType()));
}
......@@ -4918,10 +4918,10 @@ public class Parser {
}
int id = database.allocateObjectId();
boolean isRecursive = RecursiveQuery.isRecursive(tempViewName,querySQL);
System.out.println("tempViewName=>"+tempViewName+"<");
System.out.println("columnTemplateList="+columnTemplateList.stream().map(Column::toStringWithType).collect(Collectors.toList()));
System.out.println("isRecursive="+isRecursive);
System.out.println("querySQL="+querySQL);
//System.out.println("tempViewName=>"+tempViewName+"<");
//System.out.println("columnTemplateList="+columnTemplateList.stream().map(Column::toStringWithType).collect(Collectors.toList()));
//System.out.println("isRecursive="+isRecursive);
//System.out.println("querySQL="+querySQL);
TableView view = new TableView(schema, id, tempViewName, querySQL,
parameters, columnTemplateList.toArray(new Column[0]), session,
isRecursive);
......
......@@ -8,7 +8,7 @@ public class RecursiveQuery {
// A query is recursive if it references it's own name in its definition
public static boolean isRecursive(String tempViewName, String querySQL) {
boolean foundAny = RecursiveQuery.foundAny(tempViewName,querySQL);
System.out.println("foundAny="+foundAny);
//System.out.println("foundAny="+foundAny);
return foundAny;
}
......
......@@ -37,6 +37,14 @@ public class TestGeneralCommonTableQueries extends TestBase {
",t2 as (select first_col+1 from t1) " +
",t3 as (select 4 as first_col) " +
"select * from t1 union all select * from t2 union all select * from t3 where first_col<>?";
private static final String PARAMETERIZED_CHAINED_QUERY = " WITH t1 AS ("
+" SELECT 1 AS FIRST_COLUMN"
+"),"
+" t2 AS ("
+" SELECT FIRST_COLUMN+1 AS FIRST_COLUMN FROM t1 "
+") "
+"SELECT sum(FIRST_COLUMN) FROM t2";
/**
* Run just this test.
*
......@@ -44,13 +52,14 @@ public class TestGeneralCommonTableQueries extends TestBase {
*/
public static void main(String... a) throws Exception {
TestBase.createCaller().init().test();
System.out.println("Testing done");
//System.out.println("Testing done");
}
@Override
public void test() throws Exception {
testSimple();
testImpliedColumnNames();
testChainedQuery();
}
private void testSimple() throws Exception {
......@@ -118,4 +127,20 @@ public class TestGeneralCommonTableQueries extends TestBase {
conn.close();
deleteDb("commonTableExpressionQueries");
}
private void testChainedQuery() throws Exception {
deleteDb("commonTableExpressionQueries");
Connection conn = getConnection("commonTableExpressionQueries");
PreparedStatement prep;
ResultSet rs;
prep = conn.prepareStatement(PARAMETERIZED_CHAINED_QUERY);
rs = prep.executeQuery();
assertTrue(rs.next());
assertEquals(2, rs.getInt(1));
assertFalse(rs.next());
conn.close();
deleteDb("commonTableExpressionQueries");
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论