ヘッダーが '。'の入力ファイルを読み込んでいます。 'を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()
。これに関する助言?
あなたのコメントはありがとうございました。あなたが提供した内容に基づいて、私は 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
withColumn関数いずれかのヘッダーに 'があると、他の列の列には失敗します。 'したがって、他の列についても同じ "tmp"列を実行しなければなりませんでした。これが固定されることを願っています。 – sriram