本文整理汇总了Scala中org.apache.parquet.schema.Type类的典型用法代码示例。如果您正苦于以下问题:Scala Type类的具体用法?Scala Type怎么用?Scala Type使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Type类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: SchemaConverter
//设置package包名称以及导入依赖的类
package com.trueaccord.scalapb.parquet
import com.google.protobuf.Descriptors.{ Descriptor, FieldDescriptor }
import org.apache.parquet.schema.Types.{ Builder, GroupBuilder, MessageTypeBuilder, PrimitiveBuilder }
import org.apache.parquet.schema.{ MessageType, Type, Types }
import scala.collection.JavaConverters._
object SchemaConverter {
def convert(descriptor: Descriptor): MessageType = {
val builder: MessageTypeBuilder = Types.buildMessage()
addAllFields(descriptor, builder).named(descriptor.getFullName)
}
private def addAllFields[T](descriptor: Descriptor, builder: GroupBuilder[T]): GroupBuilder[T] = {
descriptor.getFields.asScala.foreach {
fd =>
addSingleField(fd, builder).id(fd.getNumber).named(fd.getName)
}
builder
}
private def addSingleField[T](fd: FieldDescriptor, builder: GroupBuilder[T]) = {
import FieldDescriptor.JavaType
import org.apache.parquet.schema.OriginalType
import org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName
val repetition = if (fd.isRequired) Type.Repetition.REQUIRED
else if (fd.isRepeated) Type.Repetition.REPEATED
else Type.Repetition.OPTIONAL
fd.getJavaType match {
case JavaType.BOOLEAN => builder.primitive(PrimitiveTypeName.BOOLEAN, repetition)
case JavaType.INT => builder.primitive(PrimitiveTypeName.INT32, repetition)
case JavaType.LONG => builder.primitive(PrimitiveTypeName.INT64, repetition)
case JavaType.FLOAT => builder.primitive(PrimitiveTypeName.FLOAT, repetition)
case JavaType.DOUBLE => builder.primitive(PrimitiveTypeName.DOUBLE, repetition)
case JavaType.BYTE_STRING => builder.primitive(PrimitiveTypeName.BINARY, repetition)
case JavaType.STRING => builder.primitive(PrimitiveTypeName.BINARY, repetition).as(OriginalType.UTF8)
case JavaType.MESSAGE =>
val subgroup = builder.group(repetition)
addAllFields(fd.getMessageType, subgroup)
case JavaType.ENUM => builder.primitive(PrimitiveTypeName.BINARY, repetition).as(OriginalType.UTF8)
case javaType =>
throw new UnsupportedOperationException("Cannot convert Protocol Buffer: unknown type " + javaType)
}
}
}
示例2: apply
//设置package包名称以及导入依赖的类
package io.eels.component.parquet
import com.sksamuel.exts.Logging
import io.eels.{Predicate, Row}
import org.apache.hadoop.conf.Configuration
import org.apache.hadoop.fs.Path
import org.apache.parquet.filter2.compat.FilterCompat
import org.apache.parquet.hadoop.api.ReadSupport
import org.apache.parquet.hadoop.{ParquetInputFormat, ParquetReader}
import org.apache.parquet.schema.Type
def apply(path: Path,
predicate: Option[Predicate],
readSchema: Option[Type],
dictionaryFiltering: Boolean)(implicit conf: Configuration): ParquetReader[Row] = {
logger.debug(s"Opening parquet reader for $path")
// The parquet reader can use a projection by setting a projected schema onto the supplied conf object
def configuration(): Configuration = {
val newconf = new Configuration(conf)
readSchema.foreach { it =>
newconf.set(ReadSupport.PARQUET_READ_SCHEMA, it.toString)
}
newconf.set(ParquetInputFormat.DICTIONARY_FILTERING_ENABLED, dictionaryFiltering.toString)
newconf.set(org.apache.parquet.hadoop.ParquetFileReader.PARQUET_READ_PARALLELISM, config.parallelism.toString)
newconf
}
// a filter is set when we have a predicate for the read
def filter(): FilterCompat.Filter = predicate.map(ParquetPredicateBuilder.build)
.map(FilterCompat.get)
.getOrElse(FilterCompat.NOOP)
ParquetReader.builder(new RowReadSupport, path)
.withConf(configuration())
.withFilter(filter())
.build()
}
}