Gives solution for any Error occurs in any Programming Language, .Net Core 3.1, 3.0, C#,Asp.Net,Sqlserver,MVC,Java,Php,Html,Css,Jquery,errors and solutions,Latest News,Technology

Friday, 2 December 2016

Filter Spark Dataframe column using Scala

No comments :
If you are using a Spark dataframe, you can filter Spark DataFrame using Scala with Spark.Sql in an easy way like below:

Filter a DataFrame which contains ""
DataFrame.registerTempTable("tempDfTable")
SqlContext.Sql("""Select * from tempDfTable where tempDfTable.col!="" """)

Filter a DataFrame column which contains null
DataFrame.registerTempTable("tempDfTable")
SqlContext.Sql("""Select * from tempDfTable where tempDfTable.col is null """)

You can write this statement with Single Quotes also
SqlContext.Sql("Select * from tempDfTable where tempDfTable.col is null")

Filter a DataFrame column which will not contain null values
DataFrame.registerTempTable("tempDfTable")
SqlContext.Sql("""Select * from tempDfTable where tempDfTable.col is not null """)

No comments :

Post a Comment