Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

MapSourceAndSinks.mapWithUpdating generates java.lang.ClassCastException: class java.lang.Integer cannot be cast to class java.lang.String (java.lang.Integer and java.lang.String are in module java.base of loader 'bootstrap') at com.hazelcast.jet.impl.execution.TaskletExecutionService$BlockingWorker.run(TaskletExecutionService.java:250) #202

Open
sebvige opened this issue Jun 30, 2019 · 5 comments

Comments

@sebvige
Copy link

sebvige commented Jun 30, 2019

Running the mapWithUpdating "as is " generates the exception described above.

Changing String.valueOf(e.getValue()) to e.getValue()
and
? oldValue +"--even"
: oldValue +"--odd"
to
? oldValue
: oldValue

makes the code running ok but with no parsing and suffixing

@viliam-durina
Copy link
Contributor

Please share the entire code of the pipeline. Is the type parameter of the source (at drawFrom) correct, does it correspond to the actual type of data in the source?

@sebvige
Copy link
Author

sebvige commented Jul 1, 2019

Here is the code as it is today in the repo :

 private static Pipeline mapWithUpdating(String sourceMapName, String sinkMapName) {
        Pipeline pipeline = Pipeline.create();

        pipeline.drawFrom(Sources.<Integer, Integer>map(sourceMapName))
                .map(e -> entry(e.getKey(), String.valueOf(e.getValue())))
                .drainTo(
                        Sinks.mapWithUpdating(
                                sinkMapName,
                                (oldValue, item) ->
                                        item.getKey() % 2 == 0
                                                ? oldValue + "-even"
                                                : oldValue + "-odd"
                        )
                );

        return pipeline;
    }

@viliam-durina
Copy link
Contributor

I suspect that the sink map already contains items with Integer type. The sink map has to be of type <Integer, String> and all items in it have to match the signature. If you share the stack trace of the exception I could confirm.

@sebvige
Copy link
Author

sebvige commented Jul 2, 2019

Here is the stack trace :
------------Map with Updating ----------------

25:31,512 [192.168.1.17]:5704 [jet] [3.1.1-SNAPSHOT] class java.lang.Integer cannot be cast to class java.lang.String (java.lang.Integer and java.lang.String are in module java.base of loader 'bootstrap')
java.lang.ClassCastException: class java.lang.Integer cannot be cast to class java.lang.String (java.lang.Integer and java.lang.String are in module java.base of loader 'bootstrap')
	at com.hazelcast.jet.function.BiFunctionEx.apply(BiFunctionEx.java:43)
	at com.hazelcast.jet.impl.connector.HazelcastWriters$ApplyFnEntryProcessor.handle(HazelcastWriters.java:647)
	at com.hazelcast.jet.impl.connector.HazelcastWriters$ApplyFnEntryProcessor.process(HazelcastWriters.java:639)
	at com.hazelcast.map.impl.operation.EntryOperator.process(EntryOperator.java:318)
	at com.hazelcast.map.impl.operation.EntryOperator.operateOnKeyValueInternal(EntryOperator.java:181)
	at com.hazelcast.map.impl.operation.EntryOperator.operateOnKey(EntryOperator.java:166)
	at com.hazelcast.map.impl.operation.MultipleEntryOperation.run(MultipleEntryOperation.java:76)
	at com.hazelcast.spi.Operation.call(Operation.java:170)
	at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.call(OperationRunnerImpl.java:210)
	at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.run(OperationRunnerImpl.java:199)
	at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.process(OperationThread.java:147)
	at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.process(OperationThread.java:177)
	at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.process(OperationThread.java:131)
	at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.run(OperationThread.java:110)

@viliam-durina
Copy link
Contributor

That's it. Your sink map contained entries with Integer value.

        map.put(1, 1);

        Pipeline p = Pipeline.create();
        p.drawFrom(SourceBuilder.batch("src", procCtx -> null)
                .<Entry<Integer, String>>fillBufferFn((ctx, buf) -> {
                    buf.add(entry(1, "foo"));
                    buf.close();
                })
                .build())
         .drainTo(Sinks.mapWithUpdating("sinkMap", (oldValue, item) ->
                 item.getKey() % 2 == 0
                         ? oldValue + "-even"
                         : oldValue + "-odd"));

        inst.newJob(p).join();

failed with:

java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
	at com.hazelcast.jet.function.BiFunctionEx.apply(BiFunctionEx.java:41)
	at com.hazelcast.jet.impl.connector.HazelcastWriters$ApplyFnEntryProcessor.handle(HazelcastWriters.java:647)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants