Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

METRON-449 JSONMapParser should unfold maps to arbitrary depths #271

Closed
wants to merge 2 commits into from

Conversation

ottobackwards
Copy link
Contributor

The JSON Parser currently only unfolds maps at the root level. The parser would support a wider range of sources is it supported unfolding maps at any depth of the document.

METRON-449 adds a recursive function to unfold Maps as they are encountered when parsing. A new function was added because the enum lambdas cannot reference themselves.

@@ -56,7 +56,7 @@ public void testHappyPath() {

/**
{
"collection" : { "blah" : 7, "blah2" : "foo" }
"collection" : { "blah" : 7, "blah2" : "foo", "bigblah" : { "innerBlah" : "baz", "reallyInnerBlah" : { "color" : "grey" }}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it! Would you make one more test case that involves just a single map?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

like

{ 
  "collection" : {
    "key" : "value"
  },
"key" : "value"
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I'll do that

@ottobackwards
Copy link
Contributor Author

ottobackwards commented Sep 26, 2016

@cestella , from looking at the ES templates etc, it seems that ':' is used as the name separator and not '.', although the documented JSON Object uses '.'. Is there some conversion happening? Should the the unfolding use ':'?

@cestella
Copy link
Member

No, ES uses ':' and modifies the keys upon write converting '.' to ':'.
Before that, '.' is the preferred source. I'm hoping we can go back to '.'
eventually. Also, non-ES indices are perfectly fine with '.'.

On Mon, Sep 26, 2016 at 11:59 AM, ottobackwards notifications@github.com
wrote:

@cestella https://github.com/cestella , from looking at the ES
templates etc, it seems that ':' is used as the name separator and not '.'.
Should the the unfolding not use the same?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#271 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAg-x-luOvx1Ebrf2a3eH3JTi9nEd5rrks5qt-v4gaJpZM4KFphg
.

@ottobackwards
Copy link
Contributor Author

Never mind - just found the field name converter

@cestella
Copy link
Member

cestella commented Sep 27, 2016

+1, tested in single node vagrant.

Did the following:

  • Created a config called custom at $METRON_HOME/config/zookeeper/parsers/custom.json:
{
  "parserClassName":"org.apache.metron.parsers.json.JSONMapParser",
  "sensorTopic":"custom",
  "parserConfig" : {
    "mapStrategy" : "UNFOLD"
  }
}
  • Created kafka topic for custom via /usr/hdp/current/kafka-broker/bin/kafka-topics.sh --zookeeper node1:2181 --create --topic custom --partitions 1 --replication-factor 1
  • Loaded the configs into zookeeper via $METRON_HOME/bin/zk_load_configs.sh --mode PUSH -i /usr/metron/0.2.0BETA/config/zookeeper -z node1:2181
  • Started the topology via $METRON_HOME/bin/start_parser_topology.sh -k node1:6667 -z node1:2181 -s custom
  • Created some sample data in ~/test_data.dat:
{ "foo" : "bar" }
{ "map" : { "blah" : 1 } }
{ "foo" : "grok", "map" : { "blah" : { "tim" : "sort" } } }
  • Loaded the sample data into the kafka queue via cat ~/test_data.dat | /usr/hdp/current/kafka-broker/bin/kafka-console-producer.sh --broker-list node1:6667 --topic custom
  • Checked in ES Head that I had a message with a field called map:blah:tim

Thanks a lot for your contribution, Otto!

@asfgit asfgit closed this in d0d6c2c Sep 27, 2016
@ottobackwards ottobackwards deleted the METRON-449 branch September 27, 2016 14:02
@ottobackwards ottobackwards restored the METRON-449 branch September 27, 2016 14:02
@ottobackwards ottobackwards deleted the METRON-449 branch September 27, 2016 14:05
danieljue added a commit to Cognami/incubator-metron that referenced this pull request Sep 27, 2016
# By cstella (4) and others
# Via cstella
* 'master' of https://github.com/apache/incubator-metron:
  METRON-457 Correct GrokParser logging spelling error (mmiklavc via cestella) closes apache#274
  METRON-449 JSONMapParser should unfold maps to arbitrary depths closes apache#271
  METRON-453: Add a stellar shell function to open an external editor and return the editor's contents closes apache#272
  METRON-452: Add rudimentary configuration management functions to Stellar closes apache#269
  METRON-374: Add appropriate bundled 3rd party licenses to NOTICE and LICENSE where appropriate closes apache#229
  flush
  METRON-427 Create Ambari Management Pack for Metron Installation closes apache#266
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants