本文整理汇总了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)
}
}
}
}
开发者ID:yamrcraft,项目名称:etl-light,代码行数:49,代码来源:HdfsUtils.scala
示例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")))
}
}
开发者ID:jborkowski,项目名称:plugin-for-jacek,代码行数:35,代码来源:DefaultSource.scala
注:本文中的org.apache.hadoop.fs.FileStatus类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论