add error check

This commit is contained in:
liuneng1994 2022-01-18 05:55:41 +00:00 committed by neng.liu
parent b4e30ad78e
commit c6e205b2ad
2 changed files with 7 additions and 0 deletions

View File

@ -72,6 +72,9 @@ namespace
HDFSFileInfo ls;
ls.file_info = hdfsListDirectory(fs.get(), prefix_without_globs.data(), &ls.length);
if (ls.file_info == nullptr) {
throw Exception(ErrorCodes::ACCESS_DENIED, "Cannot list directory {}: {}", prefix_without_globs, String(hdfsGetLastError()));
}
Strings result;
for (int i = 0; i < ls.length; ++i)
{

View File

@ -361,6 +361,10 @@ def test_hdfsCluster(started_cluster):
assert actual == expected
fs.delete(dir, recursive=True)
def testHdfsDirectoryNotExist(started_cluster):
ddl ="create table HDFSStorageWithNotExistDir (id UInt32, name String, weight Float64) ENGINE = HDFS('hdfs://hdfs1:9000/dir1/empty', 'TSV')";
node1.query(ddl)
assert "Cannot list directory" in node1.query_and_get_error("select * from HDFSStorageWithNotExistDir")
if __name__ == '__main__':
cluster.start()