Maksim Zhuravkov created IGNITE-27396:
-----------------------------------------

             Summary: Sql. Remove workaround for broken constraint in some 
INSERT queries introduced by calcite 1.41
                 Key: IGNITE-27396
                 URL: https://issues.apache.org/jira/browse/IGNITE-27396
             Project: Ignite
          Issue Type: Improvement
          Components: sql ai3
            Reporter: Maksim Zhuravkov


Calcite 1.41 added the following lines to `SqlToRelConverter convertValues`:
{noformat}
  // 1.40 does not have this if and does not add a cast here
        if (!(def instanceof RexDynamicParam) && 
!def.getType().equals(fieldType)) {
           def = rexBuilder.makeCast(operand.getParserPosition(), fieldType, 
def);
        }
        exps.add(def, SqlValidatorUtil.alias(operand, i));
{noformat}

Example:
{noformat}
 INSERT INTO t1 VALUES(1, (SELECT NULL))
{noformat}

If fieldType is NOT NULLABLE INT and def's type is NULLABLE INT, then resulting 
expression is wrapped into CAST(NULLABLE INT AS NOT NULLABLE INT). 
Unfortunately, that cast expression always results in 0 (INT) thus breaking a 
NOT NULL  constraint.




--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to