Replace \" with "" in Spark SQL - apache-spark-sql

The data I am querying on contains \", and I need to be able to convert it to "" instead in the SELECT statement.
I tried using the following:
SELECT REPLACE(COLUMN_NAME,'\"','""') but that gives the following error: unexpected EOF while looking for matching `''
What is the appropriate query to replace \" with ""?

Try using this expression SELECT REPLACE(COLUMN_NAME,'\\\\\"','\"\"')

Related

How to concat two string with addon word to the column value in HIVE

I am trying to concat two columns with concat and concat_ws function. Along with concatinating two columns I also want to append a word to this concatination. So I tried to achieve that using below method
SELECT CONCAT(CONCAT("SRID=4326;POINT(", CONCAT_WS(" ",cast(A.longitude as string),cast(A.latitude as string))), ")") as the_geom
FROM test
With above syntax I am getting the following error.
**org.apache.hive.service.cli.HiveSQLException: Error while compiling statement: FAILED: ParseException line 1:13 cannot recognize input near 'CONCAT' '(' 'CONCAT' in expression specification**
I was not knowing what wrong I am doing in the above syntax. Is there any alternative way to achieve this.
Expected RESULT : SRID=4326;POINT(127.155104 35.8091378)
I tried all ways using concat and concat_ws, but getting syntax issues.
The problem is semicolon, it breaks the query. Try replacing semicolon with \073, also double backslash may work \\;
Also it seems single concat is enough.
Demo using \073 :
with test as (
select 12134.12345 as longitude, 12134.12345 as latitude
)
SELECT CONCAT("SRID=4326\073POINT(",
CONCAT_WS(" ",cast(A.longitude as string),cast(A.latitude as string))
, ")"
) as the_geom
FROM test A
Result:
SRID=4326;POINT(12134.12345 12134.12345)

Strange symbol error in sql query with quotation marks

I have a sql query in my R code:
query <- glue("SELECT
oper.value
oper.status
oper.class
FROM "uploads".ratings AS rates"
But i get this error:
Error: unexpected symbol in:
"oper.class
FROM "uploads"
How could i handle it? How should i write schema part in query?
It seems that r interprets the double quotes character as the end of the string. You would need to use an escape character to your query.
I think this should do it :
query <- glue("SELECT
oper.value
oper.status
oper.class
FROM \"uploads\".ratings AS rates")

Regex to get the string inside parentheses using hive sql

I am trying to get the string between parentheses but i am getting always getting empty value.
String_Input: select sum(OUTPUT_VALUE) from table_name
Output : OUTPUT_VALUE
What I tried here:
select regexp_extract(String_Input,"/\\(([^)]+)\\)/") from table_name;
any suggestion to get the value ?
If you need to get the value without the parentheses, you should indicate that you need to extract Captturing group 1 value in the third argument to regexp_extract function. Besides, you should remove / delimiters, they are parsed as literal symbols.
select regexp_extract(String_Input,"\\(([^)]+)\\)", 1) from table_name;
^ ^ ^
From the Hive documentation:
The 'index' parameter is the Java regex Matcher group() method index. See docs/api/java/util/regex/Matcher.html for more information on the 'index' or Java regex group() method.
Try this:
\((.*?)\)
In Hive:
select regexp_extract(String_input,'\\((.*?)\\)')
from table_name

Adding Double Quotes and Comma around Query Results Using Derived Column in SSIS

I am trying to add double quotes and comma for every field value in my query result using ssis derived column. I can't figure out how to use the expresion in derived column to achieve this. can someone please help? here is what i am expecting to see in my output text file after the conversion:
Name Location
"ABC", "CLT",
"NYZ", "ATL",
"MYX", "LA",
and so forth..
thanks
Use the following expression
"\"" + Name + "\","
The \ works as an escape character.

Regular expression to match a string in sql

How to write a regular expression to match a string if at least 3 characters from the start are matching?
Here is how my SQL query looks right now -
SELECT * FROM tableName WHERE columnName REGEXP "^[a-zA-Z]{3}someString";
You cannot use CONCAT or alike with REGEX, it will fail. Easiest way to do it, is:
$query = 'SELECT * FROM Test WHERE colb REGEXP "^'.substr($mystring,0,3).'"');
Another is:
SELECT * FROM Test WHERE LEFT(colb, 3) LIKE "{$mystring}%"
Please use jQuery and jqSQL plugin. Note that symbol $ must be escaped in SQL query with this plugin.