GitHub user kaspersorensen opened a pull request:
https://github.com/apache/metamodel/pull/70
METAMODEL-195 - a MAP_VALUE function
This PR attempts to fix METAMODEL-195, the addition of a MAP_VALUE function
which takes a string parameter to tell which value from within a map you wish
to get. It's syntax is like this: ```MAP_VALUE('path.to.value', column)```
There is also support for a query parser shorthand syntax where you select
like this: ```column.path.to.value```
It only works on MAP type columns.
Point to especially consider: Since this is the first function which
involves parameters, I ended up also doing some redesign of the ScalarFunction
interface. I initially built it so that parameters was part of the
MapValueFunction instance and thus you would need to instantiate the function
for each parameter set you have. This worked kinda well just until I came to
the point of parsing and printing the function as SQL. The trouble here was
that if the interface did not reveal the parameters in any way then automating
the printing etc. wasn't possible either. I am a bit unhappy about changing the
interface already since it was launched in MetaModel 4.4.0, but figure we kind
of need it if we want to support functions like this. I actually think that the
interface I ended up with here could be further improved, but this was the
first stab to get your feedback.
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/kaspersorensen/metamodel
METAMODEL-195/map-value-function
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/metamodel/pull/70.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #70
----
commit 6bfbfa1d82b573d007193593219d6eb6ec38f466
Author: Kasper Sørensen <[email protected]>
Date: 2015-10-22T19:33:26Z
METAMODEL-195: Added MAP_VALUE function
commit cb82939b6892a480f4e537277c081bb052aee6dc
Author: Kasper Sørensen <[email protected]>
Date: 2015-10-23T15:39:23Z
METAMODEL-195: MAP_VALUE function special short-hand syntax
commit 8f603edfcea419fdf5a6965b3a7f14f4bee61cfa
Author: Kasper Sørensen <[email protected]>
Date: 2015-11-02T21:47:34Z
METAMODEL-195: Implemented parsing and keeping of params in select item
commit 04c00e67192ffd4238cf5250e358b18934bca6f7
Author: Kasper Sørensen <[email protected]>
Date: 2015-11-02T21:52:36Z
Merge branch 'master' into METAMODEL-195/map-value-function
Conflicts:
core/src/main/java/org/apache/metamodel/query/SelectItem.java
core/src/main/java/org/apache/metamodel/query/parser/SelectItemParser.java
core/src/test/java/org/apache/metamodel/query/parser/QueryParserTest.java
----
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---