You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@kylin.apache.org by GitBox <gi...@apache.org> on 2020/11/30 08:38:07 UTC

[GitHub] [kylin] hit-lacus edited a comment on pull request #1490: KYLIN-4828 Add more sql test cases into NBuildAndQueryTest

hit-lacus edited a comment on pull request #1490:
URL: https://github.com/apache/kylin/pull/1490#issuecomment-735626681


   From my side, there is some difference from old implementation for `sql_plan`, OLD impl will comare generated SQL with original one`Assert.assertEquals(expectedSQL, optimizedSQL);`. Please consider implement it later.  
   
   
   
   ```
       protected void execAndCompPlan(String queryFolder, String[] exclusiveQuerys, boolean needSort,
               ICompareQueryTranslator translator) throws Exception {
           logger.info("---------- test folder: " + new File(queryFolder).getAbsolutePath());
           Set<String> exclusiveSet = buildExclusiveSet(exclusiveQuerys);
   
           List<File> sqlFiles = getFilesFromFolder(new File(queryFolder), ".sql");
           for (File sqlFile : sqlFiles) {
               String queryName = StringUtils.split(sqlFile.getName(), '.')[0];
               if (exclusiveSet.contains(queryName)) {
                   continue;
               }
               String sql1 = getTextFromFile(sqlFile);
               String sql2 = translator.transform(sqlFile);
   
               // execute Kylin
               logger.info("Query Result from Kylin - " + queryName + "  (" + queryFolder + ")");
               IDatabaseConnection kylinConn = new DatabaseConnection(cubeConnection);
               ITable kylinTable = executeQuery(kylinConn, queryName, sql1, needSort);
               RelNode calcitePlan = (RelNode) QueryContextFacade.current().getCalcitePlan();
               if (calcitePlan == null)
                   throw new NullPointerException();
   
               // execute H2
               logger.info("Query Result from H2 - " + queryName);
               long currentTime = System.currentTimeMillis();
               ITable h2Table = executeQuery(newH2Connection(), queryName, sql2, needSort);
               logger.info("H2 spent " + (System.currentTimeMillis() - currentTime) + " mili-seconds.");
   
               try {
                   // compare the result
                   assertTableEquals(h2Table, kylinTable);
               } catch (Throwable t) {
                   logger.info("execAndCompQuery failed on: " + sqlFile.getAbsolutePath());
                   throw t;
               }
   
               RelToSqlConverter converter = new RelToSqlConverter(CALCITE);
               SqlNode sqlNode = converter.visitChild(0, calcitePlan.getInput(0)).asStatement();
               String optimizedSQL = sqlNode.toSqlString(CALCITE).getSql();
               String expectedSQL = Strings.join(Files.readLines(
                       new File(sqlFile.getParent(), sqlFile.getName() + ".expected"), Charset.forName("utf-8")), "\n");
               Assert.assertEquals(expectedSQL, optimizedSQL);
               compQueryCount++;
               if (kylinTable.getRowCount() == 0) {
                   zeroResultQueries.add(sql1);
               }
           }
       }
   ```


----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org