Uploaded image for project: 'Flink'
  1. Flink
  2. FLINK-14987

JDBCTableSource can't support DataTypes.DECIMAL

    XMLWordPrintableJSON

Details

    Description

       

      sample code 1 fail with ValidationException. After investigation, i find that the root cause may be related to the conversion between DecimalType and TypeInformation<BigDecimal>, please see sample code 2.

       

      sampe code 1: 

      public static void main(String[] args) {
          JDBCOptions options = JDBCOptions.builder()
                  .setDBUrl("jdbc:mysql://127.0.0.1/test")
                  .setTableName("table1")
                  .setDriverName("com.mysql.jdbc.Driver")
                  .setUsername("root")
                  .setPassword("password")
                  .build();
          TableSchema schema = TableSchema.builder()
                  .field("a", DataTypes.INT())
                  .field("b", DataTypes.BIGINT())
                  .field("c", DataTypes.FLOAT())
                  .field("d", DataTypes.DOUBLE())
                  .field("e", DataTypes.DECIMAL(24,3))
                  .field("f", DataTypes.TIMESTAMP(3))
                  .build();
          JDBCTableSource source = JDBCTableSource.builder()
                  .setOptions(options)
                  .setSchema(schema)
                  .build();
          TableSourceValidation.validateTableSource(source);
      }
      
      

      Exception in thread "main" org.apache.flink.table.api.ValidationException: Type DECIMAL(24, 3) of table field 'LEGACY(BigDecimal)' does not match with type 'e; of the field 'LEGACY(BigDecimal)' of the TableSource return type.Exception in thread "main" org.apache.flink.table.api.ValidationException: Type DECIMAL(24, 3) of table field 'LEGACY(BigDecimal)' does not match with type 'e; of the field 'LEGACY(BigDecimal)' of the TableSource return type. at org.apache.flink.table.sources.TableSourceValidation.validateLogicalTypeEqualsPhysical(TableSourceValidation.java:184) at org.apache.flink.table.sources.TableSourceValidation.validateLogicalToPhysicalMapping(TableSourceValidation.java:156) at org.apache.flink.table.sources.TableSourceValidation.validateTableSource(TableSourceValidation.java:69) at com.moodys.demo.Demo.main(Demo.java:43)

       

      sample code 2 :

      public static void main(String[] args) {
          DataType originalDataType = DataTypes.DECIMAL(24,3);
          TypeInformation legacyType =    LegacyTypeInfoDataTypeConverter.toLegacyTypeInfo(originalDataType);
          DataType dataType = LegacyTypeInfoDataTypeConverter.toDataType(legacyType);
          System.out.println(originalDataType.equals(dataType));
      }
      
      // output: false

       

       

      Attachments

        Issue Links

          Activity

            People

              docete Zhenghua Gao
              caidezhi655 Dezhi Cai
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: