This is an automated email from the ASF dual-hosted git repository. shaofengshi pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/kylin.git
The following commit(s) were added to refs/heads/master by this push: new 4817ae0 KYLIN-3651 JDBCResourceStore doesn't list all resources 4817ae0 is described below commit 4817ae0c23b40004f41030398c0e6e1178c825f0 Author: shaofengshi <shaofeng...@apache.org> AuthorDate: Mon Oct 29 08:36:29 2018 +0800 KYLIN-3651 JDBCResourceStore doesn't list all resources --- .../kylin/common/persistence/JDBCResourceDAO.java | 49 +++++++++++++++++----- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/core-common/src/main/java/org/apache/kylin/common/persistence/JDBCResourceDAO.java b/core-common/src/main/java/org/apache/kylin/common/persistence/JDBCResourceDAO.java index 70a049b..c301d10 100644 --- a/core-common/src/main/java/org/apache/kylin/common/persistence/JDBCResourceDAO.java +++ b/core-common/src/main/java/org/apache/kylin/common/persistence/JDBCResourceDAO.java @@ -151,10 +151,21 @@ public class JDBCResourceDAO { //fetch primary key only public NavigableSet<String> listAllResource(final String folderPath, final boolean recursive) throws SQLException { final NavigableSet<String> allResourceName = new TreeSet<>(); + if (isRootPath(folderPath)) { + for (int i = 0; i < tableNames.length; i++) { + final String tableName = tableNames[i]; + listResource(tableName, folderPath, allResourceName, recursive); + } + } else { + listResource(getMetaTableName(folderPath), folderPath, allResourceName, recursive); + } + return allResourceName; + } + + private void listResource(final String tableName, final String folderPath, final NavigableSet<String> allResourceName, final boolean recursive) throws SQLException { executeSql(new SqlOperation() { @Override public void execute(Connection connection) throws SQLException { - String tableName = getMetaTableName(folderPath); pstat = connection.prepareStatement(getListResourceSqlString(tableName)); pstat.setString(1, folderPath + "%"); rs = pstat.executeQuery(); @@ -171,7 +182,6 @@ public class JDBCResourceDAO { } } }); - return allResourceName; } public List<JDBCResource> getAllResource(final String folderPath, final long timeStart, final long timeEndExclusive, @@ -226,26 +236,35 @@ public class JDBCResourceDAO { } public void deleteResource(final String resourcePath) throws SQLException { + if (isRootPath(resourcePath)) { + for (int i = 0; i < tableNames.length; i++) { + final String tableName = tableNames[i]; + deleteResourceFromTable(tableName, resourcePath); + } + } else { + String tableName = getMetaTableName(resourcePath); + deleteResourceFromTable(tableName, resourcePath); + } boolean skipHdfs = isJsonMetadata(resourcePath); + if (!skipHdfs) { + try { + deleteHDFSResourceIfExist(resourcePath); + } catch (Throwable e) { + throw new SQLException(e); + } + } + } + private void deleteResourceFromTable(final String tableName, final String resourcePath) throws SQLException { executeSql(new SqlOperation() { @Override public void execute(Connection connection) throws SQLException { - String tableName = getMetaTableName(resourcePath); pstat = connection.prepareStatement(getDeletePstatSql(tableName)); pstat.setString(1, resourcePath); pstat.executeUpdate(); } }); - - if (!skipHdfs) { - try { - deleteHDFSResourceIfExist(resourcePath); - } catch (Exception e) { - throw new SQLException(e); - } - } } private void deleteHDFSResourceIfExist(String resourcePath) throws IOException { @@ -705,6 +724,10 @@ public class JDBCResourceDAO { * @return the table name */ public String getMetaTableName(String resPath) { + if (isRootPath(resPath)) { + throw new IllegalArgumentException("Not supported"); + } + if (resPath.startsWith(ResourceStore.BAD_QUERY_RESOURCE_ROOT) || resPath.startsWith(ResourceStore.EXECUTE_OUTPUT_RESOURCE_ROOT) || resPath.startsWith(ResourceStore.TEMP_STATMENT_RESOURCE_ROOT)) { @@ -714,4 +737,8 @@ public class JDBCResourceDAO { } } + public boolean isRootPath(String path) { + return "/".equals(path); + } + } \ No newline at end of file