[ 
https://issues.apache.org/jira/browse/PHOENIX-5600?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Chen Feng updated PHOENIX-5600:
-------------------------------
    Description: 
Execute select of case when for casting INTEGER to UNSIGNED_LONG throws 
exception.

A example is shown as follows

CREATE TABLE IF NOT EXISTS TBL_TEST_CASE_WHEN (A UNSIGNED_LONG NOT NULL, Y 
FLOAT, Z UNSIGNED_LONG CONSTRAINT pk PRIMARY KEY (A));
 UPSERT INTO TBL_TEST_CASE_WHEN VALUES (1, 1, 1);
 UPSERT INTO TBL_TEST_CASE_WHEN VALUES (2, 2, 2);

#this works correctly
 SELECT CASE WHEN A = 1 THEN A+9 ELSE A END, CASE WHEN Y > 1 THEN 5.5 ELSE Y 
END FROM TBL_TEST_CASE_WHEN;

#this throws exception

SELECT CASE WHEN A = 1 THEN 10 ELSE A END, CASE WHEN Y > 1 THEN 5.5 ELSE Y END 
FROM TBL_TEST_CASE_WHEN;

 

By checking code of PUnsignedLong.java and PInteger.java, I see such comment in 
PLong.isCoercibleTo(isCoercibleTo), it says

// In general, don't allow conversion of LONG to INTEGER. There are times when
 // we check isComparableTo for a more relaxed check and then throw a runtime
 // exception if we overflow

However, in this example, enable casting a const INTEGER to UNSIGNED_LONG is 
more comprehensible.

  was:
Execute select of case when for casting INTEGER to UNSIGNED_LONG throws 
exception.

A example is shown as follows

CREATE TABLE IF NOT EXISTS TBL_TEST_CASE_WHEN (A UNSIGNED_LONG NOT NULL, Y 
FLOAT, Z UNSIGNED_LONG CONSTRAINT pk PRIMARY KEY (A));
UPSERT INTO TBL_TEST_CASE_WHEN VALUES (1, 1, 1);
UPSERT INTO TBL_TEST_CASE_WHEN VALUES (2, 2, 2);

# this works correctly
SELECT CASE WHEN A = 1 THEN A+9 ELSE A END, CASE WHEN Y > 1 THEN 5.5 ELSE Y END 
FROM TBL_TEST_CASE_WHEN;

# exception as follows
# Error: ERROR 203 (22005): Type mismatch. Case expressions must have common 
type: INTEGER cannot be coerced to UNSIGNED_LONG (state=22005,code=203)
# org.apache.phoenix.schema.TypeMismatchException: ERROR 203 (22005): Type 
mismatch. Case expressions must have common type: INTEGER cannot be coerced to 
UNSIGNED_LONG

SELECT CASE WHEN A = 1 THEN 10 ELSE A END, CASE WHEN Y > 1 THEN 5.5 ELSE Y END 
FROM TBL_TEST_CASE_WHEN;

 

By checking code of PUnsignedLong.java and PInteger.java, I see such comment in 
PLong.isCoercibleTo(isCoercibleTo), it says

// In general, don't allow conversion of LONG to INTEGER. There are times when
// we check isComparableTo for a more relaxed check and then throw a runtime
// exception if we overflow

However, in this example, enable casting a const INTEGER to UNSIGNED_LONG is 
more comprehensible.


> case when for INTEGER to UNSIGNED_LONG throws exception
> -------------------------------------------------------
>
>                 Key: PHOENIX-5600
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-5600
>             Project: Phoenix
>          Issue Type: Improvement
>            Reporter: Chen Feng
>            Priority: Minor
>
> Execute select of case when for casting INTEGER to UNSIGNED_LONG throws 
> exception.
> A example is shown as follows
> CREATE TABLE IF NOT EXISTS TBL_TEST_CASE_WHEN (A UNSIGNED_LONG NOT NULL, Y 
> FLOAT, Z UNSIGNED_LONG CONSTRAINT pk PRIMARY KEY (A));
>  UPSERT INTO TBL_TEST_CASE_WHEN VALUES (1, 1, 1);
>  UPSERT INTO TBL_TEST_CASE_WHEN VALUES (2, 2, 2);
> #this works correctly
>  SELECT CASE WHEN A = 1 THEN A+9 ELSE A END, CASE WHEN Y > 1 THEN 5.5 ELSE Y 
> END FROM TBL_TEST_CASE_WHEN;
> #this throws exception
> SELECT CASE WHEN A = 1 THEN 10 ELSE A END, CASE WHEN Y > 1 THEN 5.5 ELSE Y 
> END FROM TBL_TEST_CASE_WHEN;
>  
> By checking code of PUnsignedLong.java and PInteger.java, I see such comment 
> in PLong.isCoercibleTo(isCoercibleTo), it says
> // In general, don't allow conversion of LONG to INTEGER. There are times when
>  // we check isComparableTo for a more relaxed check and then throw a runtime
>  // exception if we overflow
> However, in this example, enable casting a const INTEGER to UNSIGNED_LONG is 
> more comprehensible.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to