本文整理汇总了Scala中org.apache.hadoop.fs.permission.FsPermission类的典型用法代码示例。如果您正苦于以下问题:Scala FsPermission类的具体用法?Scala FsPermission怎么用?Scala FsPermission使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FsPermission类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: AvroSink
//设置package包名称以及导入依赖的类
package io.eels.component.avro
import java.io.File
import io.eels.schema.StructType
import io.eels.{Row, Sink, SinkWriter}
import org.apache.hadoop.conf.Configuration
import org.apache.hadoop.fs.permission.FsPermission
import org.apache.hadoop.fs.{FileSystem, Path}
case class AvroSink(path: Path,
overwrite: Boolean = false,
permission: Option[FsPermission] = None,
inheritPermissions: Option[Boolean] = None)
(implicit conf: Configuration, fs: FileSystem) extends Sink {
def withOverwrite(overwrite: Boolean): AvroSink = copy(overwrite = overwrite)
def withPermission(permission: FsPermission): AvroSink = copy(permission = Option(permission))
def withInheritPermission(inheritPermissions: Boolean): AvroSink = copy(inheritPermissions = Option(inheritPermissions))
override def open(schema: StructType): SinkWriter = new SinkWriter {
private val writer = new AvroWriter(schema, fs.create(path, overwrite))
override def write(row: Row): Unit = writer.write(row)
override def close(): Unit = {
writer.close()
permission match {
case Some(perm) => fs.setPermission(path, perm)
case None =>
if (inheritPermissions.getOrElse(false)) {
val permission = fs.getFileStatus(path.getParent).getPermission
fs.setPermission(path, permission)
}
}
}
}
}
object AvroSink {
def apply(file: File)(implicit conf: Configuration, fs: FileSystem): AvroSink = AvroSink(new Path(file.getAbsoluteFile.toString))
def apply(path: java.nio.file.Path)(implicit conf: Configuration, fs: FileSystem): AvroSink = apply(path.toFile)
}
示例2: serde
//设置package包名称以及导入依赖的类
package io.eels.component.hive
import com.sksamuel.exts.Logging
import io.eels.component.hive.dialect.{OrcHiveDialect, ParquetHiveDialect}
import io.eels.datastream.Publisher
import io.eels.schema.StructType
import io.eels.{Predicate, Row}
import org.apache.hadoop.conf.Configuration
import org.apache.hadoop.fs.permission.FsPermission
import org.apache.hadoop.fs.{FileSystem, Path}
import org.apache.hadoop.hive.metastore.api.Table
import scala.math.BigDecimal.RoundingMode.RoundingMode
trait HiveDialect extends Logging {
def serde: String
def inputFormat: String
def outputFormat: String
def output(schema: StructType, // schema without partition information
path: Path,
permission: Option[FsPermission],
roundingMode: RoundingMode,
metadata: Map[String, String])
(implicit fs: FileSystem, conf: Configuration): HiveOutputStream
def stats(getPath: Path)(implicit fs: FileSystem): Long = throw new UnsupportedOperationException
}
object HiveDialect extends Logging {
def apply(format: String): HiveDialect = format match {
case input if input.contains("ParquetInputFormat") => ParquetHiveDialect()
case input if input.contains("OrcInputFormat") => OrcHiveDialect()
//case input if input.contains("AvroHiveDialect") || input.contains("AvroContainerInputFormat") => AvroHiveDialect
// "org.apache.hadoop.mapred.TextInputFormat" -> TextHiveDialect
case _ => throw new UnsupportedOperationException(s"Unknown hive input format $format")
}
def apply(table: Table): HiveDialect = {
val format = table.getSd.getInputFormat
logger.debug(s"Table format is $format")
val dialect = HiveDialect(format)
logger.debug(s"HiveDialect is $dialect")
dialect
}
}
示例3: OrcHiveDialect
//设置package包名称以及导入依赖的类
package io.eels.component.hive.dialect
import com.sksamuel.exts.Logging
import io.eels.component.hive.{HiveDialect, HiveOutputStream}
import io.eels.component.orc.{OrcPublisher, OrcWriteOptions, OrcWriter}
import io.eels.datastream.{Publisher, Subscriber}
import io.eels.schema.StructType
import io.eels.{Predicate, Row}
import org.apache.hadoop.conf.Configuration
import org.apache.hadoop.fs.permission.FsPermission
import org.apache.hadoop.fs.{FileSystem, Path}
import org.apache.hadoop.hive.ql.io.orc.{OrcInputFormat, OrcOutputFormat, OrcSerde}
import scala.math.BigDecimal.RoundingMode.RoundingMode
case class OrcHiveDialect(options: OrcWriteOptions = OrcWriteOptions()) extends HiveDialect with Logging {
override val serde: String = classOf[OrcSerde].getCanonicalName
override val inputFormat: String = classOf[OrcInputFormat].getCanonicalName
override val outputFormat: String = classOf[OrcOutputFormat].getCanonicalName
override def input(path: Path,
metastoreSchema: StructType,
projectionSchema: StructType,
predicate: Option[Predicate])
(implicit fs: FileSystem, conf: Configuration): Publisher[Seq[Row]] = new Publisher[Seq[Row]] {
override def subscribe(subscriber: Subscriber[Seq[Row]]): Unit = {
new OrcPublisher(path, projectionSchema.fieldNames(), predicate).subscribe(subscriber)
}
}
override def output(schema: StructType,
path: Path,
permission: Option[FsPermission],
roundingMode: RoundingMode,
metadata: Map[String, String])(implicit fs: FileSystem, conf: Configuration): HiveOutputStream = {
val path_x = path
val writer = new OrcWriter(path, schema, options)
new HiveOutputStream {
override def write(row: Row): Unit = {
require(row.values.nonEmpty, "Attempting to write an empty row")
writer.write(row)
}
override def close(): Unit = {
writer.close()
permission.foreach(fs.setPermission(path, _))
}
override def records: Int = writer.records
override def path: Path = path_x
}
}
}
示例4: HiveSpeedTest
//设置package包名称以及导入依赖的类
package io.eels.component.hive
import com.sksamuel.exts.metrics.Timed
import io.eels.datastream.DataStream
import io.eels.schema.StructType
import org.apache.hadoop.fs.permission.FsPermission
import scala.util.Random
object HiveSpeedTest extends App with Timed {
import HiveConfig._
val Database = "sam"
val Table = "speedtest"
val data = Array(
Vector("elton", "yellow brick road ", "1972"),
Vector("elton", "tumbleweed connection", "1974"),
Vector("elton", "empty sky", "1969"),
Vector("beatles", "white album", "1969"),
Vector("beatles", "tumbleweed connection", "1966"),
Vector("pinkfloyd", "the wall", "1979"),
Vector("pinkfloyd", "dark side of the moon", "1974"),
Vector("pinkfloyd", "emily", "1966")
)
val rows = List.fill(3000000)(data(Random.nextInt(data.length)))
val ds = DataStream.fromValues(StructType("artist", "album", "year"), rows)
.addField("bibble", "myvalue")
.addField("timestamp", System.currentTimeMillis.toString)
println(ds.schema.show())
while (true) {
new HiveOps(client).createTable(
Database,
Table,
ds.schema,
List("artist"),
overwrite = true
)
timed("writing data") {
val sink = HiveSink(Database, Table).withPermission(new FsPermission("700"))
ds.to(sink)
logger.info("Write complete")
}
timed("reading data") {
val source = HiveSource(Database, Table)
source.toDataStream().size
logger.info("Read complete")
}
Thread.sleep(5000)
}
}