Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix
es.output.json
for Cascading. (#898)
Added tests to verify functionality. fixes #885
- Loading branch information
Showing
7 changed files
with
263 additions
and
24 deletions.
There are no files selected for viewing
97 changes: 97 additions & 0 deletions
97
...a/org/elasticsearch/hadoop/integration/cascading/AbstractCascadingHadoopJsonReadTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.hadoop.integration.cascading; | ||
|
||
import cascading.flow.hadoop.HadoopFlowConnector; | ||
import cascading.operation.AssertionLevel; | ||
import cascading.operation.aggregator.Count; | ||
import cascading.operation.assertion.AssertSizeLessThan; | ||
import cascading.operation.filter.FilterNotNull; | ||
import cascading.pipe.Each; | ||
import cascading.pipe.Every; | ||
import cascading.pipe.GroupBy; | ||
import cascading.pipe.Pipe; | ||
import cascading.scheme.local.TextLine; | ||
import cascading.tap.Tap; | ||
import cascading.tuple.Fields; | ||
import com.google.common.collect.Lists; | ||
import org.elasticsearch.hadoop.HdpBootstrap; | ||
import org.elasticsearch.hadoop.QueryTestParams; | ||
import org.elasticsearch.hadoop.Stream; | ||
import org.elasticsearch.hadoop.cascading.EsTap; | ||
import org.elasticsearch.hadoop.cfg.ConfigurationOptions; | ||
import org.elasticsearch.hadoop.mr.RestUtils; | ||
import org.elasticsearch.hadoop.util.StringUtils; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
import org.junit.runners.Parameterized.Parameters; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.OutputStream; | ||
import java.io.PrintStream; | ||
import java.util.Collection; | ||
import java.util.Properties; | ||
|
||
@RunWith(Parameterized.class) | ||
public class AbstractCascadingHadoopJsonReadTest { | ||
|
||
@Parameters | ||
public static Collection<Object[]> queries() { | ||
return QueryTestParams.params(); | ||
} | ||
|
||
private final String indexPrefix = "json-"; | ||
private final String query; | ||
private final boolean readMetadata; | ||
|
||
public AbstractCascadingHadoopJsonReadTest(String query, boolean readMetadata) { | ||
this.query = query; | ||
this.readMetadata = readMetadata; | ||
} | ||
|
||
@Before | ||
public void before() throws Exception { | ||
RestUtils.refresh(indexPrefix + "cascading-hadoop"); | ||
} | ||
|
||
@Test | ||
public void testReadFromES() throws Exception { | ||
Tap in = new EsTap(indexPrefix + "cascading-hadoop/artists"); | ||
Pipe pipe = new Pipe("copy"); | ||
|
||
Tap out = new HadoopPrintStreamTap(Stream.NULL); | ||
build(cfg(), in, out, pipe); | ||
} | ||
|
||
private void build(Properties cfg, Tap in, Tap out, Pipe pipe) { | ||
StatsUtils.proxy(new HadoopFlowConnector(cfg).connect(in, out, pipe)).complete(); | ||
} | ||
|
||
private Properties cfg() { | ||
Properties props = HdpBootstrap.asProperties(QueryTestParams.provisionQueries(CascadingHadoopSuite.configuration)); | ||
props.put(ConfigurationOptions.ES_QUERY, query); | ||
props.put(ConfigurationOptions.ES_READ_METADATA, readMetadata); | ||
props.put(ConfigurationOptions.ES_OUTPUT_JSON, "true"); | ||
return props; | ||
} | ||
} |
104 changes: 104 additions & 0 deletions
104
...va/org/elasticsearch/hadoop/integration/cascading/AbstractCascadingLocalJsonReadTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.hadoop.integration.cascading; | ||
|
||
import cascading.flow.local.LocalFlowConnector; | ||
import cascading.pipe.Pipe; | ||
import cascading.scheme.local.TextLine; | ||
import cascading.tap.Tap; | ||
import org.elasticsearch.hadoop.QueryTestParams; | ||
import org.elasticsearch.hadoop.cascading.EsTap; | ||
import org.elasticsearch.hadoop.cfg.ConfigurationOptions; | ||
import org.elasticsearch.hadoop.mr.RestUtils; | ||
import org.elasticsearch.hadoop.util.TestSettings; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
import org.junit.runners.Parameterized.Parameters; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.ByteArrayInputStream; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.InputStreamReader; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Properties; | ||
|
||
import static org.hamcrest.Matchers.hasItems; | ||
import static org.junit.Assert.assertThat; | ||
|
||
@RunWith(Parameterized.class) | ||
public class AbstractCascadingLocalJsonReadTest { | ||
|
||
@Parameters | ||
public static Collection<Object[]> queries() { | ||
return QueryTestParams.localParams(); | ||
} | ||
|
||
private final String indexPrefix = "json-"; | ||
private final String query; | ||
private final boolean readMetadata; | ||
|
||
public AbstractCascadingLocalJsonReadTest(String query, boolean readMetadata) { | ||
this.query = query; | ||
this.readMetadata = readMetadata; | ||
} | ||
|
||
@Before | ||
public void before() throws Exception { | ||
RestUtils.refresh(indexPrefix + "cascading-local"); | ||
} | ||
|
||
@Test | ||
public void testReadFromES() throws Exception { | ||
Tap in = new EsTap(indexPrefix + "cascading-local/artists"); | ||
Pipe pipe = new Pipe("copy"); | ||
ByteArrayOutputStream os = new ByteArrayOutputStream(); | ||
Tap out = new OutputStreamTap(new TextLine(), os); | ||
build(cfg(), in, out, pipe); | ||
|
||
BufferedReader r = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(os.toByteArray()))); | ||
|
||
List<String> records = new ArrayList<>(); | ||
for (String line = r.readLine(); line != null; line = r.readLine()) { | ||
records.add(line); | ||
} | ||
|
||
String doc1 = "{\"number\":\"917\",\"name\":\"Iron Maiden\",\"url\":\"http://www.last.fm/music/Iron+Maiden\",\"picture\":\"http://userserve-ak.last.fm/serve/252/22493569.jpg\",\"@timestamp\":\"2870-10-06T19:20:25.000Z\",\"list\":[\"quick\", \"brown\", \"fox\"]}"; | ||
String doc2 = "{\"number\":\"979\",\"name\":\"Smash Mouth\",\"url\":\"http://www.last.fm/music/Smash+Mouth\",\"picture\":\"http://userserve-ak.last.fm/serve/252/82063.jpg\",\"@timestamp\":\"2931-10-06T19:20:25.000Z\",\"list\":[\"quick\", \"brown\", \"fox\"]}"; | ||
String doc3 = "{\"number\":\"190\",\"name\":\"Muse\",\"url\":\"http://www.last.fm/music/Muse\",\"picture\":\"http://userserve-ak.last.fm/serve/252/416514.jpg\",\"@timestamp\":\"2176-10-06T19:20:25.000Z\",\"list\":[\"quick\", \"brown\", \"fox\"]}"; | ||
|
||
assertThat(records, hasItems(doc1, doc2, doc3)); | ||
} | ||
|
||
private void build(Properties cfg, Tap in, Tap out, Pipe pipe) { | ||
StatsUtils.proxy(new LocalFlowConnector(cfg).connect(in, out, pipe)).complete(); | ||
} | ||
|
||
private Properties cfg() { | ||
Properties props = new TestSettings().getProperties(); | ||
props.put(ConfigurationOptions.ES_QUERY, query); | ||
props.put(ConfigurationOptions.ES_READ_METADATA, readMetadata); | ||
props.put(ConfigurationOptions.ES_OUTPUT_JSON, "true"); | ||
return props; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.