2017-03-26 3 views
1

우선, 제 질문을 읽어 주셔서 감사합니다.데이터 프레임 스파크 자바에 가입

제 질문은 다음과 같습니다. Spark with Java에서는 두 개의 데이터 프레임에 두 개의 CSV 파일 데이터를로드합니다.

이 데이터 프레임에는 다음과 같은 정보가 있습니다.

Dataframe 공항

Id | Name | City 
----------------------- 
1 | Barajas | Madrid 

Dataframe의 airport_city_state 내가이 같이 보이도록이 두 dataframes에 가입 할

City | state 
---------------- 
Madrid | España 

:

dataframe 결과

Id | Name | City | state 
-------------------------- 
1 | Barajas | Madrid | España 

여기서 dfairport.city = dfaiport_city_state.city

하지만 올바르게 결합 할 수 있도록 구문을 명확히 할 수 없습니다. 어떻게 생성 한 변수의 작은 코드 : 당신은 열 이름으로 join 방법을 사용할 수 있습니다

// Load the csv, you have to specify that you have header and what delimiter you have 
Dataset <Row> dfairport = Load.Csv (sqlContext, data_airport); 
Dataset <Row> dfairport_city_state = Load.Csv (sqlContext, data_airport_city_state); 


// Change the name of the columns in the csv dataframe to match the columns in the database 
// Once they match the name we can insert them 
Dfairport 
.withColumnRenamed ("leg_key", "id") 
.withColumnRenamed ("leg_name", "name") 
.withColumnRenamed ("leg_city", "city") 

dfairport_city_state 
.withColumnRenamed("city", "ciudad") 
.withColumnRenamed("state", "estado"); 

답변

0

먼저 답장을 보내 주셔서 감사합니다.

내 솔루션을 모두 시도했지만 그들 중 누구도 작동하지, 나는 다음과 같은 오류가 발생합니다 : 방법의 dfairport_city_state (문자열)

내가 dataframe의 특정 컬럼에 액세스 할 수 없습니다 ETL_Airport 유형에 대해 정의되지 않은 가입하십시오. 편집

: 은 이미 가입 할 수있어 난 여기 경우 다른 사람이 할 수있는 솔루션을 넣어)

모든 주셔서 감사 및 안부

//Join de tablas en las que comparten ciudad 
Dataset <Row> joined = dfairport.join(dfairport_city_state, dfairport.col("leg_city").equalTo(dfairport_city_state.col("city"))); 
6

두 dataframes, 예를 가입 :

에 당신을 허용하는 오버로드 된 버전도 있습니다
Dataset <Row> dfairport = Load.Csv (sqlContext, data_airport); 
Dataset <Row> dfairport_city_state = Load.Csv (sqlContext, data_airport_city_state); 

Dataset <Row> joined = dfairport.join(dfairport_city_state, dfairport_city_state("City")); 

예를 들어, 세 번째 인수로 join 유형을 지정 :

Dataset <Row> joined = dfairport.join(dfairport_city_state, dfairport_city_state("City"), "left_outer");

Here의 이상에 조인.

관련 문제