Common superclass for all extractors that enable the user to define custom attributes and extract their values.
The extraction logic may just extract the underlying value or group, reduce or transform it.
How to use a ValueExtractor?
First, extend this class and implement the @see com.hazelcast.query.extractor.ValueExtractor#extract method.
Then, define a new custom attribute referencing the implemented extractor in the configuration of the map.
How to define a new custom attribute?
MapAttributeConfig attributeConfig = new MapAttributeConfig();
extractorConfig.setName("currency");
extractorConfig.setExtractor("com.bank.CurrencyExtractor");
How to register the newly-defined attribute in a configuration of a Map?
MapConfig mapConfig = (...);
mapConfig.addMapAttributeConfig(attributeConfig);
Extractors may be also defined in the XML configuration.
< map name="trades">
< attributes>
< attribute extractor="com.bank.CurrencyExtractor">currency< /attribute>
< /attributes>
< /map>
Please, bear in mind that an extractor may not be added after a map has been instantiated.
All extractors have to be defined upfront in the map's initial configuration.
A ValueExtractor may use a custom argument if it is specified in the query.
The custom argument may be passed within the square brackets located after the name of the attribute
that uses a ValueExtractor, like: customAttribute[argumentString]
Let's have a look at the following query: 'currency[incoming] == EUR'
Let's assume that currency is an custom attribute that uses com.test.CurrencyExtractor for extraction.
The string "incoming" is an argument that will be passed to the
ArgumentParser during the extraction.
The parser will parse the string according to the parser's custom logic and it will return a parsed object.
The parsed object may be a single object, array, collection, etc. It's up to the ValueExtractor implementor's
to understand the semantics of the parsed argument object.
Reflection-based extraction is the default mechanism - ValueExtractors are an alternative way of extracting
attribute values from an object.
It is also possible to use a ValueExtractor with a Portable data format. In this case the target object passed to the
extractor implements a
ValueReader interface.