Bug: examples provided in https://spark.apache.org/docs/latest/api/sql/index.html   link not working
Status: Open | Priority: Minor | Resolution: 
Created: 20/Jan/21 10:05
Affects Version/s: 2.4.5

*Issue 1 :*

*array_sort examples provided in [https://spark.apache.org/docs/latest/api/sql/index.html#array_sort] link not working.*

 

SELECT array_sort(array(5, 6, 1), (left, right) -> case when left < right then -1 when left > right then 1 else 0 end); –> *this example when executed in spark-sql fails with below error*

SELECT array_sort(array(5, 6, 1), (left, right) -> case when left < right then -1 when left > right then 1 else 0 end);
 Error in query:
 extraneous input '->' expecting \{')', ','}(line 1, pos 48)

== SQL ==
 SELECT array_sort(array(5, 6, 1), (left, right) -> case when left < right then -1 when left > right then 1 else 0 end)
 ------------------------------------------------^^^

spark-sql>

 

SELECT array_sort(array('bc', 'ab', 'dc'), (left, right) -> case when left is null and right is null then 0 when left is null then -1 when right is null then 1 when left < right then 1 when left > right then -1 else 0 end);  --> *This example when executed fails with below error*

 

spark-sql>
 >
 >
 >
 >
 >
 >
 >
 >
 >
 >
 >
 >
 >
 >
 >
 >
 > SELECT array_sort(array('bc', 'ab', 'dc'), (left, right) -> case when left is null and right is null then 0 when left is null then -1 when right is null then 1 when left < right then 1 when left > right then -1 else 0 end);
 Error in query:
 extraneous input '->' expecting \{')', ','}(line 1, pos 57)

== SQL ==
 SELECT array_sort(array('bc', 'ab', 'dc'), (left, right) -> case when left is null and right is null then 0 when left is null then -1 when right is null then 1 when left < right then 1 when left > right then -1 else 0 end)
 ---------------------------------------------------------^^^

spark-sql>

 

*Issue 2 :-*

*Examples for overlay functions are not working in link - https://spark.apache.org/docs/latest/api/sql/index.html*

 

spark-sql> SELECT overlay('Spark SQL' PLACING '_' FROM 6);
Error in query:
mismatched input 'PLACING' expecting \{')', ','}(line 1, pos 27)

== SQL ==
SELECT overlay('Spark SQL' PLACING '_' FROM 6)
---------------------------^^^

spark-sql> SELECT overlay('Spark SQL' PLACING 'CORE' FROM 7);
Error in query:
mismatched input 'PLACING' expecting \{')', ','}(line 1, pos 27)

== SQL ==
SELECT overlay('Spark SQL' PLACING 'CORE' FROM 7)
---------------------------^^^

spark-sql> SELECT overlay('Spark SQL' PLACING 'ANSI ' FROM 7 FOR 0);
Error in query:
mismatched input 'PLACING' expecting \{')', ','}(line 1, pos 27)

== SQL ==
SELECT overlay('Spark SQL' PLACING 'ANSI ' FROM 7 FOR 0)
---------------------------^^^

spark-sql> SELECT overlay('Spark SQL' PLACING 'tructured' FROM 2 FOR 4);
Error in query:
mismatched input 'PLACING' expecting \{')', ','}(line 1, pos 27)

== SQL ==
SELECT overlay('Spark SQL' PLACING 'tructured' FROM 2 FOR 4)
---------------------------^^^

spark-sql> SELECT overlay(encode('Spark SQL', 'utf-8') PLACING encode('_', 'utf-8') FROM 6);
Error in query:
mismatched input 'PLACING' expecting \{')', ','}(line 1, pos 44)

== SQL ==
SELECT overlay(encode('Spark SQL', 'utf-8') PLACING encode('_', 'utf-8') FROM 6)
--------------------------------------------^^^

spark-sql> SELECT overlay(encode('Spark SQL', 'utf-8') PLACING encode('CORE', 'utf-8') FROM 7);
Error in query:
mismatched input 'PLACING' expecting \{')', ','}(line 1, pos 44)

== SQL ==
SELECT overlay(encode('Spark SQL', 'utf-8') PLACING encode('CORE', 'utf-8') FROM 7)
--------------------------------------------^^^

spark-sql> SELECT overlay(encode('Spark SQL', 'utf-8') PLACING encode('ANSI ', 'utf-8') FROM 7 FOR 0);
Error in query:
mismatched input 'PLACING' expecting \{')', ','}(line 1, pos 44)

== SQL ==
SELECT overlay(encode('Spark SQL', 'utf-8') PLACING encode('ANSI ', 'utf-8') FROM 7 FOR 0)
--------------------------------------------^^^

spark-sql> SELECT overlay(encode('Spark SQL', 'utf-8') PLACING encode('tructured', 'utf-8') FROM 2 FOR 4);
Error in query:
mismatched input 'PLACING' expecting \{')', ','}(line 1, pos 44)

== SQL ==
SELECT overlay(encode('Spark SQL', 'utf-8') PLACING encode('tructured', 'utf-8') FROM 2 FOR 4)
--------------------------------------------^^^