'SQL Wildcard Characters - What Am I Missing?
Trying to group the browser platforms by generic type instead of each individual version.
An error occurred while calling o73.sql.
: org.apache.spark.sql.catalyst.parser.ParseException:
mismatched input 'BrowserPlatform' expecting <EOF>(line 2, pos 10)
This is the error I usually get when syntax is off slightly so I know I'm missing something here. Can you point it out?
spark.sql(""" SELECT
CASE WHEN BrowserPlatform IN 'iOS%' THEN 'iOS'
WHEN BrowserPlatform IN '%Android%' THEN 'Android'
WHEN BrowserPlatform IN '%iPad%' THEN 'iPad'
WHEN BrowserPlatform IN '%iPhone%' THEN 'iPhone'
ELSE BrowserPlatform
END AS GenericBrowserPlatform
FROM DATA
""").createOrReplaceTempView('Test')
| BrowserPlatform | GenericBrowserPlatform |
|---|---|
| iPhone, iOS 14 | iPhone |
| iOS 14 | iOS |
| Android 10 | Android |
| Android 11 | Android |
| iPhone, iOS 13 | iPhone |
Solution 1:[1]
Answering my own question here in case it helps someone else.
LIKE instead of IN solves the problem
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | HelpMe7733 |
