Reputation: 660
I am new to Hazelcast jet and I am not getting how to Sink simple java.util.Map to BatchSource?
I have tried below but not seems to be working.
Map<String, Object> data =new HashMap<String, Object>();
data.put("xyz", "abc");
Way 1:
Map<String, Object> am = jetInstance.getMap("abc");
am.putAll(data);
BatchSource batchSource = Sources.map("abc");
I gives error: java.util.HashMap cannot be cast to java.util.Map$Entry
Way 2: BatchSource batchSource = TestSources.items(data);
and same error please help what wrong am I doing I am trying to creating pipeline but not going forward.
Upvotes: 0
Views: 209
Reputation: 886
I think the problem must be somewhere other than in the code you've shared; the BatchSource definition isn't incorrect. I just did a quick test and the following runs fine (Tested on 5.0 version):
public static void main(String[] args) {
Config config = new Config();
config.getJetConfig().setEnabled(true);
HazelcastInstance hz = Hazelcast.newHazelcastInstance(config);
Map<String,Object> map = hz.getMap("map");
map.put("A", "AnObject");
map.put("B", "AnotherObject");
BatchSource source = Sources.map("map");
Pipeline p = Pipeline.create();
p.readFrom(source)
.writeTo(Sinks.logger());
hz.getJet().newJob(p).join();
}
With output:
INFO: [192.168.86.25]:5701 [dev] [5.0] Start execution of job '0702-23dd-8800-0001', execution 0702-23dd-8801-0001 from coordinator [192.168.86.25]:5701
Oct 25, 2021 9:11:44 AM com.hazelcast.jet.impl.connector.WriteLoggerP
INFO: [192.168.86.25]:5701 [dev] [5.0] [0702-23dd-8800-0001/loggerSink#0] B=AnotherObject
Oct 25, 2021 9:11:44 AM com.hazelcast.jet.impl.connector.WriteLoggerP
INFO: [192.168.86.25]:5701 [dev] [5.0] [0702-23dd-8800-0001/loggerSink#0] A=AnObject
Oct 25, 2021 9:11:44 AM com.hazelcast.jet.impl.MasterJobContext
INFO: [192.168.86.25]:5701 [dev] [5.0] Execution of job '0702-23dd-8800-0001', execution 0702-23dd-8801-0001 completed successfully
(Since a map is unordered in this case the entries are seen in a different order than the way they were added to the map)
Upvotes: 2