2016-12-20 6 views
0

ヘッダーが '。'の入力ファイルを読み込んでいます。 'をDataFrameとして表示します。私は、そのファイルの値をトリミングする際に問題に直面しています。ヘッダーにドットを含むデータフレーム値をトリミングする

サンプルtestCode:私は上記のコードを実行しようとした場合

val sqc = new SQLContext(getLocalSparkContext()) 
import sqc.implicits.localSeqToDataFrameHolder 
import org.apache.spark.sql.functions._ 
val testDataFrame = Seq((" test data ", " dummy data ", " a multi word string ")).toDF("col1", "col. 2", "col3") 
testDataFrame.withColumn("col. 2", trim(testDataFrame("`col. 2`"))).show() 
testDataFrame.withColumn("col1", trim(testDataFrame("col1"))).show() 

、私は

を取得していますと、「COLを解決することはできません。 2 '与えられた入力列col1、col。 2、col3; org.apache.spark.sql.AnalysisException: 'col。'を解決できません。 2 '与えられたの入力列col1、col。 2、col3;このライン上の

testDataFrame.withColumn("col1", trim(testDataFrame("col1"))).show()

驚くべきことに、

testDataFrame.withColumn("col. 2", trim(testDataFrame("`col. 2`"))).show() 

パス。 私も同じよう列を交換してみました。まだ同じ例外を取得

testDataFrame.withColumnRenamed("col. 2", "`col. 2`").show() 

。これに関する助言?

答えて

0

この試してください。(testDataFrame( "col. 2を "))ドロップ

ヴァル・T2 = T1((COLを(" col. 2"))トリム、 "TMP")

ヴァルt1が= testDataFrame.withColumnを.withColumn( "col .2"、t1( "tmp"))。drop(t1( "tmp"))

+0

あなたのコメントはありがとうございました。あなたが提供した内容に基づいて、私は val testDataFrame = Seq(( "テストデータ"、 "ダミーデータ"、 "マルチワード文字列"))toDF( "col1"、 "col 2"、 "col3") ( "tmp"、 "col。2") 変形されたDF= testDataFrame.withColumn( "tmp"、trim(testDataFrame( "col 2")))。 .show() transformedDF.withColumn( "col1"、trim(testDataFrame( "col1")))。show() 列の順序が変更され、 "col1"のトリムも失敗します – sriram

+0

withColumn関数いずれかのヘッダーに 'があると、他の列の列には失敗します。 'したがって、他の列についても同じ "tmp"列を実行しなければなりませんでした。これが固定されることを願っています。 – sriram

関連する問題