0

I am using Flink's Table API. I would like to use CASE WHEN in a Table API query. My query uses three fields: routeid, startlocation, distance and I want to use a CASE WHEN clause to identify factors based on the distance value which are conditions required to satisfy based on routeid.

Example:

SELECT 
  routeid, 
  startlocation, 
  CASE WHEN (routeid=1) AND (distance > 0 AND distance <= 250) THEN 'oneday-distance'

Is this possible with Flink's Table API? If yes, how can is be done?

Fabian Hueske
  • 18,707
  • 2
  • 44
  • 49
Akki
  • 493
  • 1
  • 11
  • 23
  • why you don't put all these conditions in WHERE clause? – mitkosoft May 16 '16 at 06:42
  • My dataset is large & importantly I have multiple conditions for satisfying classes...If I use CASE WHEN, it will be an optimized query...I also want to use UPDATE statement.. – Akki May 16 '16 at 07:03

1 Answers1

0

The Table API of the latest Flink version 1.0.3 does not support CASE WHEN clauses.

For the next release (Flink 1.1.0), the Table API is reworked, extended, and will support CASE WHEN clauses. We can try the 1.1-SNAPSHOT version to try the feature. Feedback is appreciated.

Fabian Hueske
  • 18,707
  • 2
  • 44
  • 49
  • @FabianHueske Could you pls give the correct case when in: `select("o_orderdate.substring(0,4) as o_year, volume, (when(n_name.like('%BRAZIL%'),volume)) as case_volume")` – Soheil Pourbafrani Jan 29 '19 at 23:35
  • Hey @Fabian, was this removed from more recent versions of Flink SQL? Looking through the 1.10 docs and can't find anything on it. – austin_ce Aug 17 '20 at 18:06
  • Ah, found it -- are there any good examples of this in the Flink docs? – austin_ce Aug 17 '20 at 18:53
  • I'm only aware of this one: https://ci.apache.org/projects/flink/flink-docs-release-1.10/dev/table/functions/systemFunctions.html#conditional-functions But I think this is pretty much standard SQL so there should be plenty of examples in the web like this one: https://www.w3schools.com/sql/sql_case.asp – Fabian Hueske Aug 17 '20 at 19:42