我有一个制表符分隔的文件(tsv),我不知道它的模式,我想使用"Scalding“从每一行中删除第一列。
我知道如果模式是已知的,那么我可以使用
val dataControlSchema = List('a,'b,'c,'d,'e,'f)
Tsv("abc.tsv").read
.discard('a)
.write(Tsv("output1.tsv"))但问题是我不知道模式,可能会有6列或7列,甚至更多。但这是固定的,我必须删除第一列..任何帮助都将不胜感激
发布于 2015-02-18 17:15:32
Scalding提供了两种API
基于
在这种情况下,您必须使用类型安全API,
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" ) ) 发布于 2015-02-18 23:24:08
@sarveshKsingh写的很棒的回复。只是在.write的末尾缺少一个括号
val字符串: TypedPipe fromFile= 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" )) // a bracket was missing. https://stackoverflow.com/questions/28576851
复制相似问题