flink-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Soheil Pourbafrani <soheil.i...@gmail.com>
Subject Create Dynamic data type
Date Fri, 19 Apr 2019 15:18:42 GMT
Hi,

Using JDBCInputFormat I want to read data from database but the problem is
the table columns are dynamic according to the number of rows. In the
schema the first column is of type int and in the rest of the column the
first half is String and the second half is double. So I need a way to
create the data type dynamically.

I tried the following:

Tuple t = Tuple.getTupleClass(num_col + 1).newInstance();
t.setField("Integer", 0);
for(int i = 0; i < num_col; i++) {
    if (i < i / 2) t.setField("String", i);
    if (i > i / 2) t.setField("Double", i);
}


JDBCInputFormat jdbcInputFormat = JDBCInputFormat.buildJDBCInputFormat()
        .setDrivername("com.mysql.jdbc.Driver")
        .setDBUrl("url")
        .setUsername("root")
        .setPassword("pass")
        .setQuery("SELECT * FROM table;")
        .setFetchSize(100)
        .setRowTypeInfo(new RowTypeInfo(TypeExtractor.getForObject(t)))
        .finish();

but I got the following error:

Automatic type extraction is not possible on candidates with null values.
Please specify the types directly.

Creating the data type using TypeInformation[] fieldTypes I successfully
can get the data but it needs the static schema and doesn't fit in my case!

Any help will be appreciated!

Mime
View raw message