Skip to content

Commit

Permalink
Refactored isHdfs to isExternalDataSource
Browse files Browse the repository at this point in the history
  • Loading branch information
blee1234 committed Aug 2, 2022
1 parent 2eb7460 commit 8fc6a25
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@ private[offline] class LocalPathChecker(hadoopConf: Configuration, dataLoaderHan
}

/**
* check whether the input path is an Hdfs path. Neesd to have separate function, as there are class conflicts with Breaks.getClass
* check whether the input path is an external data source. Needs to have separate function, as there are class conflicts with Breaks.getClass
* @param path input path.
* @return true if the path is an Hdfs path.
* @return true if the path is an external data source.
*/
def isHdfs(path: String): Boolean = {
def isExternalDataSource(path: String): Boolean = {
import scala.util.control.Breaks._

var isHdfsFlag: Boolean = true
var isExternalDataSourceFlag: Boolean = false
breakable {
for(dataLoaderHandler <- dataLoaderHandlers) {
if (dataLoaderHandler.validatePath(path)) {
isHdfsFlag = false
isExternalDataSourceFlag = true
break
}
}
}
isHdfsFlag
isExternalDataSourceFlag
}

/**
Expand All @@ -47,7 +47,7 @@ private[offline] class LocalPathChecker(hadoopConf: Configuration, dataLoaderHan
* @return true if the path exists.
*/
override def exists(path: String): Boolean = {
if (isHdfs(path) && HdfsUtils.exists(path)) return true
if (!isExternalDataSource(path) && HdfsUtils.exists(path)) return true
if (LocalFeatureJoinUtils.getMockPathIfExist(path, hadoopConf, None).isDefined) return true
if (getClass.getClassLoader.getResource(path) != null) return true
if (getClass.getClassLoader.getResource(path + TEST_AVRO_JSON_FILE) != null) return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class TestPathChecker extends TestFeathr with MockitoSugar {
assertEquals(localPathChecker.exists("non-existing_path"), false)
}

@Test(description = "test isHdfs method for LocalPathChecker")
def testLocalPathCheckerIsHdfs() : Unit = {
@Test(description = "test isExternalDataSource method for LocalPathChecker")
def testLocalPathCheckerIsExternalDataSource() : Unit = {
val mockCreateDataFrame = (path: String, daliParameters: Map[String, String], jobConf: JobConf) => mock[DataFrame]

val mockUnionDataFrame = (
Expand All @@ -68,7 +68,7 @@ class TestPathChecker extends TestFeathr with MockitoSugar {
)
val mockDataLoaderHandlers = List(mockDataLoaderHandler)
val localPathChecker = new LocalPathChecker(new Configuration(), mockDataLoaderHandlers)
assertTrue(!localPathChecker.isHdfs("xyz://"))
assertTrue(localPathChecker.isHdfs("file://"))
assertTrue(localPathChecker.isExternalDataSource("xyz://"))
assertTrue(!localPathChecker.isExternalDataSource("file://"))
}
}

0 comments on commit 8fc6a25

Please sign in to comment.