Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is wrong with spark sql substring function?

This should require no explanation. But could someone describe the logic behind the pos parameter of substring because I cannot make sense of this (Using Spark 2.1):

scala> val df = Seq("abcdef").toDS()
df: org.apache.spark.sql.Dataset[String] = [value: string]

scala> df.show
+------+
| value|
+------+
|abcdef|
+------+

scala> df.selectExpr("substring(value, 0, 2)", "substring(value, 1, 2)", "substring(value, 2,2)", "substring(value, 3,2)").show
+----------------------+----------------------+----------------------+----------------------+
|substring(value, 0, 2)|substring(value, 1, 2)|substring(value, 2, 2)|substring(value, 3, 2)|
+----------------------+----------------------+----------------------+----------------------+
|                    ab|                    ab|                    bc|                    cd|
+----------------------+----------------------+----------------------+----------------------+
like image 934
Jeff Saremi Avatar asked Sep 29 '17 23:09

Jeff Saremi


People also ask

How do you get a substring from a string in Pyspark?

We can get the substring of the column using substring() and substr() function. Parameter: str – It can be string or name of the column from which we are getting the substring. start and pos – Through this parameter we can give the starting position from where substring is start.

Why is Spark SQL slow?

Sometimes, Spark runs slowly because there are too many concurrent tasks running. The capacity for high concurrency is a beneficial feature, as it provides Spark-native fine-grained sharing. This leads to maximum resource utilization while cutting down query latencies.

Is there a substring function in SQL?

SQL Server SUBSTRING() Function The SUBSTRING() function extracts some characters from a string.


1 Answers

first value is from what index it should start (starts from 1 not from 0) second value is how many characters it should take from the index

like image 99
Vasile Surdu Avatar answered Jan 01 '23 22:01

Vasile Surdu