difference between sort by and order by
difference between sort by and order by
Published: None
difference between sort by and order by
difference between sort by and order by
Order By and Sort By both are not same in sql. Order by will do sorting an entire data. sort by will do partition wise sorting
orderBy and sort both are same in pyspark. sortWintinPartitions as same as sort By in sql.
df=spark.read.format("csv")\
.option("header","True")\
.load("/FileStore/tables/Sample DataSource/emp.csv")
df.createOrReplaceTempView("df")
df.rdd.getNumPartitions()
df=df.repartition(4,"JOB")
df=df.withColumn("PARTITION_ID",spark_partition_id())
df.createOrReplaceTempView("df")
display(df)
df.rdd.getNumPartitions()
df=df.repartition(4,"JOB")
#Ascending
#df.orderBy(col("SAL")).show()
#descending order
df.orderBy(col("SAL").desc()).show()
#df.sort("SAL").show()
df.sort(col("SAL").desc()).show()
df.sortWithinPartitions(desc(col("SAL"))).show()
Comments
Post a Comment