Author: lewismc Date: Sun Aug 11 01:34:58 2013 New Revision: 1512845 URL: http://svn.apache.org/r1512845 Log: CMS commit to gora by lewismc
Modified: gora/site/trunk/content/current/tutorial.md Modified: gora/site/trunk/content/current/tutorial.md URL: http://svn.apache.org/viewvc/gora/site/trunk/content/current/tutorial.md?rev=1512845&r1=1512844&r2=1512845&view=diff ============================================================================== --- gora/site/trunk/content/current/tutorial.md (original) +++ gora/site/trunk/content/current/tutorial.md Sun Aug 11 01:34:58 2013 @@ -603,12 +603,12 @@ the LogManager class. /** Queries and prints pageview object that have keys between startKey and endKey*/ private void query(long startKey, long endKey) throws IOException { - Query<Long, Pageview> query = dataStore.newQuery(); + Query<Long, Pageview> query = dataStore.newQuery(); //set the properties of query query.setStartKey(startKey); query.setEndKey(endKey); - Result<Long, Pageview> result = query.execute(); + Result<Long, Pageview> result = query.execute(); printResult(result); } @@ -621,7 +621,7 @@ Result interface allows us to iterate th next() method. The getKey() method returns the current key and get() returns current persistent object. - private void printResult(Result<Long, Pageview> result) throws IOException { + private void printResult(Result<Long, Pageview> result) throws IOException { while(result.next()) { //advances the Result object and breaks if at end long resultKey = result.getKey(); //obtain current key @@ -685,7 +685,7 @@ Continueing from the LogManager class, t /** This method illustrates delete by query call */ private void deleteByQuery(long startKey, long endKey) throws IOException { //Constructs a query from the dataStore. The matching rows to this query will be deleted - Query≶Long, Pageview> query = dataStore.newQuery(); + Query<Long, Pageview> query = dataStore.newQuery(); //set the properties of query query.setStartKey(startKey); query.setEndKey(endKey); @@ -728,7 +728,7 @@ First we need to download HSQL dependenc dependency is available in the Maven pom.xml. Ofcourse MySQL users should uncomment the mysql dependency instead. - <!--<dependency org="org.hsqldb" name="hsqldb" rev="2.0.0" conf="*->default"/>--> + <!--<dependency org="org.hsqldb" name="hsqldb" rev="2.0.0" conf="*->default"/>--> Then we need to run Maven so that the new dependencies can be downloaded. @@ -789,15 +789,15 @@ Similar to what we have seen with HBase, gora-sql-mappings.xml file. Specifically, we will use the gora-tutorial/conf/gora-sql-mappings.xml file. - <gora-orm> + <gora-orm> ... - <class name="org.apache.gora.tutorial.log.generated.MetricDatum" keyClass="java.lang.String" table="Metrics"> - <primarykey column="id" length="512"/> - <field name="metricDimension" column="metricDimension" length="512"/> - <field name="timestamp" column="ts"/> - <field name="metric" column="metric/> - </class> - </gora-orm> + <class name="org.apache.gora.tutorial.log.generated.MetricDatum" keyClass="java.lang.String" table="Metrics"> + <primarykey column="id" length="512"/> + <field name="metricDimension" column="metricDimension" length="512"/> + <field name="timestamp" column="ts"/> + <field name="metric" column="metric/> + </class> + </gora-orm> SQL mapping files contain one or more class elements as the children of gora-orm. The key value pair is declared in the class element. The name attribute is the @@ -834,8 +834,8 @@ the data store to store the job's output initMapperJob and initReducerJob functions have also overriden methods that take the data store class rather than data store instances. - public Job createJob(DataStore<Long, Pageview> inStore - , DataStore<String, MetricDatum> outStore, int numReducer) throws IOException { + public Job createJob(DataStore<Long, Pageview> inStore + , DataStore<String, MetricDatum> outStore, int numReducer) throws IOException { Job job = new Job(getConf()); job.setJobName("Log Analytics"); @@ -897,7 +897,7 @@ Then the metric dimension object is cons will be stored at the output data store. protected void reduce(TextLong tuple - , Iterable<LongWritable> values, Context context) + , Iterable<LongWritable> values, Context context) throws IOException ,InterruptedException { long sum = 0L; //sum up the values @@ -921,7 +921,7 @@ will be stored at the output data store. Now that the job is constructed, we can run the Hadoop job as usual. Note that the run function of the LogAnalytics class parses the arguments and runs the job. We can run the program by - $ bin/gora loganalytics [<input data store> [<output data store>]] + $ bin/gora loganalytics [<input data store> [<output data store>]] ###Running the job with SQL Now, let's run the log analytics tools with the SQL backend(either Hsql or MySql). The input data store will be @@ -998,7 +998,7 @@ under which some example classes can be <gora-core>/src/examples/ Second, various unit tests of Gora modules can be referred to see the API in use. The unit tests can be found -at <gora-module>/src/test/ +at <gora-module>/src/test/ The source code for the projects using Gora can also be checked out as a reference. [Apache Nutch](http://nutch.apache.org) is one of the first class users of Gora; so looking into how Nutch uses Gora is always a good idea.