Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClassCastException in DistinctValueAggregation.DistinctValueMapper.map() when gettings values from PredicateSupplier #7398

Closed
spongyT opened this issue Jan 25, 2016 · 2 comments

Comments

Projects
None yet
3 participants
@spongyT
Copy link

commented Jan 25, 2016

Assume having the following Entities and I want to get a set of unique values for an attribute "type":

E1: {"assetId":"a", "type":"car"}
E2: {"assetId":"b", "type":"paper"}
E3: {"assetId":"c", "type":"blub"}
E3: {"assetId":"d", "type":"car"}

I just want to take a look into entities E1, E2 and E4 and the result should be a set containing "car" and "paper". Due to that I wrote the following code sinppet:

com.hazelcast.query.Predicate<String, SampleEntity> assetIdsRestriction = Predicates.in("assetId", "a", "b", "d");
Supplier<String, SampleEntity, String> typeExtractorSupplier = Supplier.all(entity -> entity.getType());
Supplier<String, FleetEntity, String> supplier = Supplier.fromPredicate(assetIdsRestriction, typeExtractorSupplier );
Aggregation<String, String, Set<String>> aggregation = Aggregations.distinctValues();
        return map.aggregate(supplier, aggregation);

And what I get is a ClassCastException in DistinctValueAggregation.DistinctValueMapper.map():

Caused by: java.lang.ClassCastException: com.hazelcast.mapreduce.aggregation.impl.DistinctValuesAggregation$SimpleEntry cannot be cast to com.hazelcast.query.impl.Extractable
    at com.hazelcast.query.impl.predicates.AbstractPredicate.readAttributeValue(AbstractPredicate.java:129)
    at com.hazelcast.query.impl.predicates.AbstractPredicate.apply(AbstractPredicate.java:55)
    at com.hazelcast.mapreduce.aggregation.impl.PredicateSupplier.apply(PredicateSupplier.java:58)
    at com.hazelcast.mapreduce.aggregation.impl.DistinctValuesAggregation$DistinctValueMapper.map(DistinctValuesAggregation.java:202)
    at com.hazelcast.mapreduce.impl.task.KeyValueSourceMappingPhase.executeMappingPhase(KeyValueSourceMappingPhase.java:49)
    at com.hazelcast.mapreduce.impl.task.MapCombineTask.processMapping(MapCombineTask.java:135)
    at com.hazelcast.mapreduce.impl.task.MapCombineTask.processPartitionMapping(MapCombineTask.java:304)
    at com.hazelcast.mapreduce.impl.task.MapCombineTask.access$700(MapCombineTask.java:68)
    at com.hazelcast.mapreduce.impl.task.MapCombineTask$PartitionBasedProcessor.processPartitions(MapCombineTask.java:356)
    at com.hazelcast.mapreduce.impl.task.MapCombineTask$PartitionBasedProcessor.run(MapCombineTask.java:333)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at com.hazelcast.util.executor.CompletableFutureTask.run(CompletableFutureTask.java:67)
    at com.hazelcast.util.executor.CachedExecutorServiceDelegate$Worker.run(CachedExecutorServiceDelegate.java:212)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
    at com.hazelcast.util.executor.HazelcastManagedThread.executeRun(HazelcastManagedThread.java:76)
    at com.hazelcast.util.executor.HazelcastManagedThread.run(HazelcastManagedThread.java:92)

This is because DistinctValueAggregation.DistinctValueMapper.SimpleEntry only implements Map.Entry<K, V>

private static final class SimpleEntry<K, V> implements Map.Entry<K, V> { }

and doesn´t extend from QueryableEntry as done in SupplierConsumingMapper.SimpleEntry:

static final class SimpleEntry<K, V> extends QueryableEntry<K, V> 

---This only happens on Hazelcast 3.6-RC1.----

@jerrinot jerrinot added the Team: Core label Jan 27, 2016

@jerrinot jerrinot added this to the 3.6.1 milestone Jan 27, 2016

@jerrinot jerrinot self-assigned this Jan 27, 2016

@jerrinot

This comment has been minimized.

Copy link
Contributor

commented Jan 27, 2016

Hi @spongyT,

thank you for a nice bugreport. Let me see what I can do about it. The fix should be straightforward.

jerrinot added a commit to jerrinot/hazelcast that referenced this issue Jan 27, 2016

SimpleEntry from SupplierConsumingMapper extracted into a top-level c…
…lass

 Fixes hazelcast#7398
 The SimpleEntry is now re-used in DistinctValuesAggregation.

 It removes code duplication and fixes ClassCastException as the old inner class
 used in DistinctValuesAggregation didn't implement the interface QueryEngine
 expects.

jerrinot added a commit to jerrinot/hazelcast that referenced this issue Jan 27, 2016

SimpleEntry from SupplierConsumingMapper extracted into a top-level c…
…lass

 Fixes hazelcast#7398
 The SimpleEntry is now re-used in DistinctValuesAggregation.

 It removes code duplication and fixes ClassCastException as the old inner class
 used in DistinctValuesAggregation didn't implement the interface QueryEngine
 expects.
@adasari

This comment has been minimized.

Copy link

commented Jul 11, 2016

Hi ,
we are facing same issue in 3.5.2 as well .Was the fix part of 3.5.2 also ? or 3.6.1 onwards ? Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.