首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在不使用模式的情况下在scalding中访问TSV

在不使用模式的情况下在scalding中访问TSV
EN

Stack Overflow用户
提问于 2015-02-18 13:49:37
回答 2查看 877关注 0票数 0

我有一个制表符分隔的文件(tsv),我不知道它的模式,我想使用"Scalding“从每一行中删除第一列。

我知道如果模式是已知的,那么我可以使用

代码语言:javascript
复制
val dataControlSchema = List('a,'b,'c,'d,'e,'f)
  Tsv("abc.tsv").read
  .discard('a)
  .write(Tsv("output1.tsv"))

但问题是我不知道模式,可能会有6列或7列,甚至更多。但这是固定的,我必须删除第一列..任何帮助都将不胜感激

EN

回答 2

Stack Overflow用户

发布于 2015-02-18 17:15:32

Scalding提供了两种API

基于

  1. 字段的接口
  2. 类型安全接口

在这种情况下,您必须使用类型安全API,

代码语言:javascript
复制
val fromFile: TypedPipe[ String ] = TypedPipe.from( TextLine("abc.tsv" ) )
fromFile
.map( _.split( "\t" ) )  // now should be TypedPipe[ Array[ String ] ]
.map( _.toList ) //  now should be TypedPipe[ List[ String ] ]
.map( _.drop( 1 ) ) // this should drop first string from the List
.map( _.mkString( "\t" ) ) // Now TypedList[ String ]
.write( TypedTsv( "output.tsv" ) ) 
票数 0
EN

Stack Overflow用户

发布于 2015-02-18 23:24:08

@sarveshKsingh写的很棒的回复。只是在.write的末尾缺少一个括号

val字符串: TypedPipe fromFile= TypedPipe.from( TextLine("abc.tsv“))

代码语言:javascript
复制
fromFile

.map( _.split( "\t" ) )  // now should be TypedPipe[ Array[ String ] ]

.map( _.toList ) //  now should be TypedPipe[ List[ String ] ]

.map( _.drop( 1 ) ) // this should drop first string from the List

.map( _.mkString( "\t" ) ) // Now TypedList[ String ]

.write( TypedTsv( "output.tsv" )) // a bracket was missing. 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28576851

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档