Hazelcast Jet with Named Jdbc Query or ResultSet?

191 Views Asked by At

I am new to Hazelcast Jet and I am using Spring JdbcTemplate to execute my query, which uses named parameters in the query, but I am not sure how to use it with Hazelcast Jet.

E.g. Hazelcast works in following way:

Pipeline p = Pipeline.create();
p.readFrom(Sources.jdbc(
    () -> DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql"),
    (con, parallelism, index) -> {
        PreparedStatement stmt = con.prepareStatement(
              "SELECT * FROM person WHERE MOD(id, ?) = ?)");
        stmt.setInt(1, parallelism);
        stmt.setInt(2, index);
        return stmt.executeQuery();
    },
    resultSet -> new Person(resultSet.getInt(1), resultSet.getString(2))
)).writeTo(Sinks.logger());

But instead of ? I want to use named query like SELECT * FROM person WHERE MOD(id, :id) = :id). Does Hazelcast support named query or Spring JdbcTemplate?

Also in Sources, can we pass ResultSet directly as a source? There are many sources but I didn't find any for "ResultSet".

E.g.

p.readFrom(Sources.resultSet(<Resultset Object>) //something like this

Please help me out on this, if possible.

2

There are 2 best solutions below

0
On

I assume that by "Named JDBC Query" you meant "Named parameters".

It's is not a standard feature of JDBC API, it's a convenience provided by the Spring Framework. Hazelcast Jet does not support it. We are currently looking at how to provide better integration between Hazelcast Jet and Spring and this is one of the things on our radar.

0
On

I'll answer the other part of the question: it's not technically possible to create a ResultSet source. The query must be executed on the cluster, you cannot execute a query on the client and send it to the cluster to fetch the rows. That's why the JDBC source asks you for a SQL statement and for a lambda to create the connection, but the connection will be created in the cluster and used to execute the query.