Uploaded image for project: 'Debezium'
  1. Debezium
  2. DBZ-5236

Cannot convert field type tinyint(1) unsigned to boolean

    • False
    • None
    • False

      In order to make your issue reports as actionable as possible, please provide the following information, depending on the issue type.

      Bug report

      For bug reports, provide this information, please:

      CREATE TABLE `retail_order_detail` (

        `id` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id',

        `cdc_code` varchar(100) NOT NULL COMMENT 'code',

        `product` varchar(50) NOT NULL COMMENT '商品',

        `price` int NOT NULL COMMENT '价格',

        `city` varchar(50) NOT NULL COMMENT '城市',

        `user_deleted` tinyint unsigned NOT NULL DEFAULT '0' COMMENT 'user deleted journey,YES=1,NO=0',

        `is_completed` tinyint(1) NOT NULL DEFAULT '1',

        `b` boolean NOT NULL DEFAULT true,

        PRIMARY KEY (`id`)

      ) ENGINE=InnoDB AUTO_INCREMENT=58 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='零售表';

       

      field `is_completed` tinyint(1) can convert to boolean,

      but field `user_deleted` tinyint unsigned cannot convert to boolean

       

      insert into retail_order_detail(cdc_code,product,price,city,user_deleted,is_completed,b) values(400,"apple400",400,"合肥400",1,0,true)

       

      when insert data to table,convert result as follows:

      {'type': 'boolean', 'optional': False, 'default': True, 'field': 'is_completed'}

       
       

      {'type': 'int16', 'optional': False, 'default': 0, 'field': 'user_deleted'}

      What Debezium connector do you use and what version?

      debezium-connector-mysql-1.9.2.Final.jar

      What is the connector configuration?

       

      What is the captured database version and mode of depoyment?

      (E.g. on-premises, with a specific cloud provider, etc.)

      mysql 5.7

      What behaviour do you expect?

       field type tinyint unsigned can convert to boolean

      What behaviour do you see?

      insert into retail_order_detail(cdc_code,product,price,city,user_deleted,is_completed,b) values(400,"apple400",400,"合肥400",1,0,true)

       

      when insert data to table,convert result as follows:

      {'type': 'boolean', 'optional': False, 'default': True, 'field': 'is_completed'}

       
       

      {'type': 'int16', 'optional': False, 'default': 0, 'field': 'user_deleted'}

       

            [DBZ-5236] Cannot convert field type tinyint(1) unsigned to boolean

            Released

            Debezium Builder added a comment - Released

            Applied to 1.9 and 2.0

            Jiri Pechanec added a comment - Applied to 1.9 and 2.0

            Harvey Yue (Inactive) added a comment - - edited

            fy18759, Yes, I have fixed the `tinyint(1) unsigned` not converted to boolean issue.
            Please wait this pr been merged to main or apply this changes with your branch and rebuild it.
            https://github.com/debezium/debezium/pull/3602

            Harvey Yue (Inactive) added a comment - - edited fy18759 , Yes, I have fixed the `tinyint(1) unsigned` not converted to boolean issue. Please wait this pr been merged to main or apply this changes with your branch and rebuild it. https://github.com/debezium/debezium/pull/3602

            @Harvey Yue yes,i want to convert  `user_deleted` tinyint(1) unsigned to boolean when using custom converter TinyIntOneToBooleanConverter. It is currently converted to int16.

             

              `user_deleted` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT 'user deleted journey,YES=1,NO=0',

              `is_completed` tinyint(1) NOT NULL DEFAULT '1',

             

            insert into retail_order_detail(cdc_code,product,price,city,user_deleted,is_completed,b) values(400,"apple400",400,"合肥400",1,0,true)

             

            i want to convert  `user_deleted` tinyint(1) unsigned to boolean,but convert result as follows:

            *

            {'type': 'int16', 'optional': False, 'default': 0, 'field': 'user_deleted'}

            , {'type': 'boolean', 'optional': False, 'default': True, 'field': 'is_completed'}*

            fei yang (Inactive) added a comment - @Harvey Yue yes,i want to convert  `user_deleted`  tinyint (1)  unsigned to boolean when using custom converter TinyIntOneToBooleanConverter. It is currently converted to int16.     `user_deleted`  tinyint (1)  unsigned   NOT   NULL   DEFAULT  '0' COMMENT 'user deleted journey,YES=1,NO=0',   `is_completed`  tinyint (1)  NOT   NULL   DEFAULT  '1',   insert   into  retail_order_detail(cdc_code,product,price,city,user_deleted,is_completed,b)  values (400,"apple400",400,"合肥400",1,0, true )   i want to convert  `user_deleted`  tinyint (1)  unsigned to boolean,but convert result as follows: * {'type': 'int16', 'optional': False, 'default': 0, 'field': 'user_deleted'} , {'type': 'boolean', 'optional': False, 'default': True, 'field': 'is_completed'}*

            fei yang (Inactive) added a comment - - edited

            sorry,I made a mistake. 

               CREATE TABLE retail_order_detail (

              `id` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id',

              `cdc_code` varchar(100) NOT NULL COMMENT 'code',

              `product` varchar(50) NOT NULL COMMENT '商品',

              `price` int NOT NULL COMMENT '价格',

              `city` varchar(50) NOT NULL COMMENT '城市',

              `user_deleted` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT 'user deleted journey,YES=1,NO=0',

              `is_completed` tinyint(1) NOT NULL DEFAULT '1',

              `b` boolean NOT NULL DEFAULT true,

              PRIMARY KEY (`id`)

            )ENGINE=InnoDB AUTO_INCREMENT=58 DEFAULT CHARSET=utf8mb4 COMMENT='零售表';

             

            connector configuration as follows:

            {
            }

             

            insert into retail_order_detail(cdc_code,product,price,city,user_deleted,is_completed,b) values(400,"apple400",400,"合肥400",1,0,true)

            i want to convert  `user_deleted` tinyint(1) unsigned to boolean,but convert result as follows:

            *

            {'type': 'int16', 'optional': False, 'default': 0, 'field': 'user_deleted'}

            , {'type': 'boolean', 'optional': False, 'default': True, 'field': 'is_completed'}*

            thank you very much

            fei yang (Inactive) added a comment - - edited sorry,I made a mistake.     CREATE TABLE retail_order_detail (   `id` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id',   `cdc_code` varchar (100) NOT NULL COMMENT 'code',   `product` varchar (50) NOT NULL COMMENT '商品',   `price` int NOT NULL COMMENT '价格',   `city` varchar (50) NOT NULL COMMENT '城市',   `user_deleted` tinyint (1) unsigned NOT NULL DEFAULT '0' COMMENT 'user deleted journey,YES=1,NO=0',   `is_completed` tinyint (1) NOT NULL DEFAULT '1',   `b` boolean NOT NULL DEFAULT true ,   PRIMARY KEY (`id`) )ENGINE=InnoDB AUTO_INCREMENT =58 DEFAULT CHARSET=utf8mb4 COMMENT='零售表';   connector configuration as follows: { }   insert into retail_order_detail(cdc_code,product,price,city,user_deleted,is_completed,b) values (400,"apple400",400,"合肥400",1,0, true ) i want to convert  `user_deleted` tinyint (1) unsigned to boolean,but convert result as follows: * {'type': 'int16', 'optional': False, 'default': 0, 'field': 'user_deleted'} , {'type': 'boolean', 'optional': False, 'default': True, 'field': 'is_completed'}* thank you very much

            I do want to point out however that the DDL presented doesn't use TINYINT(1) UNSIGNED but rather TINYINT UNSIGNED. When you define TINYINT without an explicit width, I do believe that defaults to TINYINT(4) in MySQL which means the converter would still not convert the column's value to a boolean, even with Harvey's changes. That's expected behavior because the expectation is that the field's width is explicitly set to 1. So fy18759 you would need to adjust the table's DDL to be TINYINT(1) UNSIGNED as Harvey mentioned above for his fix to take place.

            Chris Cranford added a comment - I do want to point out however that the DDL presented doesn't use TINYINT(1) UNSIGNED but rather TINYINT UNSIGNED . When you define TINYINT without an explicit width, I do believe that defaults to TINYINT(4) in MySQL which means the converter would still not convert the column's value to a boolean, even with Harvey's changes. That's expected behavior because the expectation is that the field's width is explicitly set to 1. So fy18759 you would need to adjust the table's DDL to be TINYINT(1) UNSIGNED as Harvey mentioned above for his fix to take place.

            fy18759 The `tinyint(1)` or `tinyint(1) unsigned` should expect the captured value is true/false when using custom converter TinyIntOneToBooleanConverter. Currently, we don't handle `tinyint(1) unsigned` case, fixed now.

            Harvey Yue (Inactive) added a comment - fy18759 The `tinyint(1)` or `tinyint(1) unsigned` should expect the captured value is true/false when using custom converter TinyIntOneToBooleanConverter. Currently, we don't handle `tinyint(1) unsigned` case, fixed now.

              Unassigned Unassigned
              fy18759 fei yang (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

                Created:
                Updated:
                Resolved: