rubenada commented on PR #5294:
URL: https://github.com/apache/calcite/pull/5294#issuecomment-6056017351

   Taking a final look... I have the impression that the current rewrite 
approach only works if `SqlValidator.Config.identifierExpansion` is true (I 
think the existing tests using `CalciteAssert` / `SqlToRelFixture` have this 
flag set to true, but actually the default value is false).
   
   Having a `SELECT * ...` test with `identifierExpansion=false` would be 
required. IIANM, adding these tests to `SqlValidatorTest` unveils the issue:
   
   ```
     @Test void testCyclePathWithStarInRecursiveTerm() {
       SqlValidatorTestCase.FIXTURE
           .withValidatorIdentifierExpansion(false)
           .withSql("WITH RECURSIVE t(n) AS (VALUES (1) UNION ALL SELECT * FROM 
t)\n"
               + "CYCLE n SET c TO 'Y' DEFAULT 'N' USING p\n"
               + "SELECT * FROM t")
           .type("RecordType(INTEGER NOT NULL N, CHAR(1) NOT NULL C, "
               + "RecordType(INTEGER NOT NULL EXPR$0) NOT NULL ARRAY NOT NULL 
P) NOT NULL");
     }
   
     @Test void testCyclePathWithStarInRecursiveTermIdExpansion() {
       SqlValidatorTestCase.FIXTURE
           .withValidatorIdentifierExpansion(true)
           .withSql("WITH RECURSIVE t(n) AS (VALUES (1) UNION ALL SELECT * FROM 
t)\n"
               + "CYCLE n SET c TO 'Y' DEFAULT 'N' USING p\n"
               + "SELECT * FROM t")
           .type("RecordType(INTEGER NOT NULL N, CHAR(1) NOT NULL C, "
               + "RecordType(INTEGER NOT NULL EXPR$0) NOT NULL ARRAY NOT NULL 
P) NOT NULL");
     }
   ```
   
   The first one fails, but the second one passes.
   
   A potential solution might be forcing the expansion (independently of the 
flag) in `CycleRewriter#prepareQuery` (unverified):
   
   ```
   private SqlNode prepareQuery(Reference reference) {
       final SqlSelect step = ((SqlCall) queryBody(item.query)).operand(1);
       final SqlNodeList stepSelectList = step.getSelectList();
       final SqlShuttle shuttle = new DeepCopier() {
         @Override public SqlNode visit(SqlNodeList nodeList) {
           return requireNonNull(
               super.visit(nodeList == stepSelectList ? 
validator.expandStar(stepSelectList, step, false) : nodeList));
         }
         ...
   ```
   
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to