Apache Flink:JDBCInputFormat返回什么类型的记录?

时间:2018-08-11 23:28:50

标签: apache-flink

我收到与if (yn) { console.log('Ok...'); } 相关的setRowTypeInfo错误。错误如下。显然,JDBCInputFormat的{​​{1}}类型不像Tuple2的{​​{1}},但是我找不到任何地方可以阐明如何定义格式。

  

[错误]无法执行目标   org.apache.maven.plugins:maven-compiler-plugin:3.1:compile   (默认编译)在项目flink上:编译失败[ERROR]   /Users/rocadmin/Desktop/flink/flink/src/main/java/svalarms/BatchJob.java:[125,48]   不兼容的类型:推断的类型不符合相等性   约束[ERROR]推断为:   org.apache.flink.api.java.tuple.Tuple2   [错误]平等约束:   org.apache.flink.api.java.tuple.Tuple2,org.apache.flink.types.Row   [错误] [错误]-> [帮助1]

DataSet

2 个答案:

答案 0 :(得分:1)

JDBCInputFormat返回类型为Row的记录。因此,结果DataSet的类型应为Row,即

DataSet<Row> dbData =
  env.createInput(
    JDBCInputFormat.buildJDBCInputFormat()
      .setDrivername("oracle.jdbc.driver.OracleDriver")
      .setDBUrl("jdbc:oracle:thin:@//[ip]:1521/sdmprd")
      .setQuery(
        "SELECT T2.work_order_nbr, T2.work_order_nbr " +
        "FROM sdm.work_order_master T2  " +
        "WHERE " +
          "TO_DATE(T2.date_entered + 19000000,'yyymmdd') >= CURRENT_DATE - 14 " +
          "AND T2.W_O_TYPE = 'TC' " +
          "AND T2.OFFICE_ONLY_FLG = 'N' "
        )
      .setRowTypeInfo(Types.ROW(Types.INT, Types.INT))
      .finish()
    );

答案 1 :(得分:0)

一切顺利

TypeInformation[] fieldTypes = new TypeInformation[] {
        BasicTypeInfo.BIG_DEC_TYPE_INFO,
        BasicTypeInfo.BIG_DEC_TYPE_INFO
};

RowTypeInfo rowTypeInfo = new RowTypeInfo(fieldTypes);
JDBCInputFormatBuilder inputBuilder =
        JDBCInputFormat.buildJDBCInputFormat().setDrivername("oracle.jdbc.driver.OracleDriver").setDBUrl("jdbc:oracle:thin:@//ipaddress:1521/sdmprd").setQuery("" +
                "SELECT T2.work_order_nbr  , T2.work_order_nbr  " +
                "FROM sdm.work_order_master T2  " +
                "WHERE " +
                "TO_DATE(T2.date_entered + 19000000,'yyyymmdd') >= CURRENT_DATE - 14 " +
                "AND T2.W_O_TYPE = 'TC' " +
                "AND T2.OFFICE_ONLY_FLG = 'N' " +
                "").setRowTypeInfo(rowTypeInfo).setUsername(“user”).setPassword(“pass”);
DataSet<Row> source = env.createInput(inputBuilder.finish());