• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala Type类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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)
    }
  }
} 
开发者ID:scalapb,项目名称:sparksql-scalapb,代码行数:48,代码来源:SchemaConverter.scala


示例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()
  }
} 
开发者ID:51zero,项目名称:eel-sdk,代码行数:41,代码来源:RowParquetReaderFn.scala



注:本文中的org.apache.parquet.schema.Type类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala ByteBuf类代码示例发布时间:2022-05-23
下一篇:
Scala times类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap