本文整理汇总了Scala中org.apache.hadoop.fs.FileStatus类的典型用法代码示例。如果您正苦于以下问题:Scala FileStatus类的具体用法?Scala FileStatus怎么用?Scala FileStatus使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FileStatus类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: HdfsUtils
//设置package包名称以及导入依赖的类
package yamrcraft.etlite.utils
import org.apache.hadoop.fs.{FileStatus, FileSystem, Path}
import scala.collection.mutable
object HdfsUtils {
def renameFiles(fromBase: Path, toBase: Path, fs: FileSystem) = {
if (fs.exists(fromBase)) {
val filesToMove = listFiles(fromBase, fs)
println("files to move:")
filesToMove foreach (p => println("+++" + p.toString))
filesToMove foreach { file =>
val relPath = relativize(fromBase, file)
val toPath = new Path(toBase, relPath)
fs.mkdirs(toPath.getParent)
fs.rename(file, toPath)
println(" file renamed to: " + toPath.toString)
}
}
}
def relativize(base: Path, files: List[Path]) = {
files map (file => new Path(base.toUri.relativize(file.toUri).getPath))
}
def relativize(base: Path, file: Path): Path = {
new Path(base.toUri.relativize(file.toUri).getPath)
}
def listFiles(path: Path, fs: FileSystem): List[Path] = {
val statusList = mutable.MutableList[FileStatus]()
traverse(path, statusList, fs)
statusList.map(status => new Path(status.getPath.toUri.getPath)).toList
}
private def traverse(path: Path, list: mutable.MutableList[FileStatus], fs: FileSystem): Unit = {
fs.listStatus(path) foreach { status =>
if (!status.isDirectory) {
list += status
} else {
traverse(status.getPath, list, fs)
}
}
}
}
示例2: DefaultSource
//设置package包名称以及导入依赖的类
package pl.jborkowskijmartin.spark.mf
import org.apache.hadoop.conf.Configuration
import org.apache.hadoop.fs.FileStatus
import org.apache.hadoop.mapreduce.Job
import org.apache.spark.sql.SparkSession
import org.apache.spark.sql.catalyst.InternalRow
import org.apache.spark.sql.execution.datasources.{FileFormat, OutputWriterFactory, PartitionedFile}
import org.apache.spark.sql.sources.Filter
import org.apache.spark.sql.types.{StringType, StructField, StructType}
import org.apache.spark.unsafe.types.UTF8String
class DefaultSource extends FileFormat {
override def inferSchema(sparkSession: SparkSession, options: Map[String, String], files: Seq[FileStatus]):
Option[StructType] = {
println(">>>InferSchema")
Some(StructType(
StructField("line", StringType, nullable = true) :: Nil
))
}
override def prepareWrite(sparkSession: SparkSession, job: Job, options: Map[String, String], dataSchema: StructType):
OutputWriterFactory = {
println(">>> prepareWrite")
null
}
override def buildReader(sparkSession: SparkSession, dataSchema: StructType, partitionSchema: StructType,
requiredSchema: StructType, filters: Seq[Filter], options: Map[String, String],
hadoopConf: Configuration): (PartitionedFile) => Iterator[InternalRow] = {
pf => Iterator(InternalRow(UTF8String.fromString("hello")))
}
}