I want 'Experience
' column data in single column like the below one (hire_date
is not printed here.it is the column which is not being displayed below but I want to show it in my data):
emp_id | emp_name | salary | Experience
--------+----------+---------+-------------------------
68319 | KAYLING | 6000.00 | 26 years 2 mons 12 days
67858 | SCARLET | 3100.00 | 20 years 9 mons 11 days
Below is my query with result:
sqlContext.sql("SELECT emp_id,emp_name,hire_date,salary,datediff(current_date(),hire_date) as (Experience) FROM employees WHERE (salary/30)>100").show()
Result:
+------+--------+----------+------+----------+
|emp_id|emp_name| hire_date|salary|Experience|
+------+--------+----------+------+----------+
| 68319| KAYLING|1991-11-18|6000.0| 9763|
| 67858| SCARLET|1997-04-19|3100.0| 7784|
Schema:
|-- emp_id: long (nullable = true)
|-- emp_name: string (nullable = true)
|-- job_name: string (nullable = true)
|-- manager_id: long (nullable = true)
|-- hire_date: date (nullable = true)
|-- salary: double (nullable = true)
|-- commision: double (nullable = true)
|-- dep_id: long (nullable = true)
I tried creating sample UDF for getting difference in year
in Scala but it keeps on giving me the error. Below is my code with error:
def getYearValue(value:java.util.Date):String= {
val year1:String=year(current_date()-year(hire_date);
year1;
}
Error:
<console>:26: error: type mismatch;
found : org.apache.spark.sql.Column
required: String
val year1:String=year(current_date());
So how do I modify my UDF code to get the expected format?