Re: Riak API for Java

2014-11-12 Thread Guido Medina
You need to learn how to use Jackson, there is no other way around it, 
like you were told, you need a default constructor, or an annotated 
constructor to instruct Jackson how to instantiate your class, like the 
following example:



public class TestClass  {

  @JsonCreator
  public TestClass(
 @JsonProperty(property1) Type1 property1,
 @JsonProperty(property2) Type2 property2,
 @JsonProperty(property3) Type3 property3,
 @JsonProperty(property4) Type4 property4) {
...
...
  }
}


And here is an article about it, written by the Jackson author: 
http://www.cowtowncoder.com/blog/archives/2011/07/entry_457.html


P.D.: Did you take a look at the Exception when your code failed, 
Jackson exceptions can't be more clear...


Guido.

On 12/11/14 01:43, Ebbinge wrote:

Hello, I am trying to use the MapReduce function that comes along with the
Java API. I am using this code:

try{
 IRiakClient client = RiakFactory.pbcClient(192.168.0.41,
8087);
 Bucket myBucket = client.fetchBucket(Productos).execute();
//Bucket called Productos
 BucketMapReduce m = client.mapReduce(Productos);
 m.addMapPhase(new NamedJSFunction(Riak.mapValuesJson), true);
 MapReduceResult result = m.execute();
 //System.out.println(result.getResultRaw());
 CollectionProducto tmp = result.getResult(Producto.class);
 for (Producto p : tmp) {
 System.out.println(p.Nombre+\n);
 }

 client.shutdown();
 
 }
 
 catch(Exception Ex){

 System.out.println(Ex.getMessage());
 }

I have a Producto Class like this:

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.StringTokenizer;
import javax.swing.JFileChooser;

/**
  *
  * @author edwinfernandez
  */
public class Producto {
 public String ID;
 public String Nombre;
 public String Descripcion;
 public String Vendedor;
 public String Url;
 public String Precio;
 
 public Producto(String id,String name,String desc,String seller,String

precio,String url){
 ID = id;
 Nombre = name;
 Descripcion = desc;
 Vendedor = seller;
 Precio = precio;
 Url = url;
 }
 public Producto(){
 
 }

}

I can't seem to make it work, I just need to mapreduce the description of
each product in order to get the top ten most used words to describe
products.

Thank you in advance.



--
View this message in context: 
http://riak-users.197444.n3.nabble.com/Riak-API-for-Java-tp4032055.html
Sent from the Riak Users mailing list archive at Nabble.com.

___
riak-users mailing list
riak-users@lists.basho.com
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com


___
riak-users mailing list
riak-users@lists.basho.com
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com


Re: Riak API for Java

2014-11-12 Thread Ebbinge
run: 
java.io.IOException: Error receiving outputs: normal 

That's the error I am receiving :/ Could you guide me to make it work with
my Producto Class, I am total beginner to the Riak API for Java.

Thanks in advance,
Edwin.



--
View this message in context: 
http://riak-users.197444.n3.nabble.com/Riak-API-for-Java-tp4032055p4032059.html
Sent from the Riak Users mailing list archive at Nabble.com.

___
riak-users mailing list
riak-users@lists.basho.com
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com


Re: Riak API for Java

2014-11-12 Thread Brian Roach
On Wed, Nov 12, 2014 at 8:20 AM, Ebbinge edwinpanad...@gmail.com wrote:
 run:
 java.io.IOException: Error receiving outputs: normal

 That's the error I am receiving :/ Could you guide me to make it work with
 my Producto Class, I am total beginner to the Riak API for Java.

The error message you're receiving is coming from Riak itself, not the
client. You're discarding the stack trace in your code by printing
`Ex.getMessage()` instead of just `Ex`.

Your code, as it it written now, is fine. You've got some problem on
the Riak side that you'll ned to look in the log files to diagnose.

Here's a gist showing that your code isn't the problem:

https://gist.github.com/broach/d0d79df429f5ff725c8a

Thanks,
Roach




 Thanks in advance,
 Edwin.



 --
 View this message in context: 
 http://riak-users.197444.n3.nabble.com/Riak-API-for-Java-tp4032055p4032059.html
 Sent from the Riak Users mailing list archive at Nabble.com.

 ___
 riak-users mailing list
 riak-users@lists.basho.com
 http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com

___
riak-users mailing list
riak-users@lists.basho.com
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com


Re: Riak API for Java

2014-11-12 Thread Ebbinge
Great, thank you so much. I tried using the format of the class that you
wrote in the gist github you sent me.

I get now all my 20 productos printed on the console of netbeans, which is
something :D!!!

Now, any idea of how I can map-reduce the top ten most used words of the
descriptions of each product? 
If I have the product object, and there is a description in it, can I
manually count the words, adding them to a list, then matching them and
reducing them, manually? Or does the Java API of riak do it alone? I am
closer to be done, thank you SO MUCH for your help :D!



--
View this message in context: 
http://riak-users.197444.n3.nabble.com/Riak-API-for-Java-tp4032055p4032065.html
Sent from the Riak Users mailing list archive at Nabble.com.

___
riak-users mailing list
riak-users@lists.basho.com
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com


Re: Riak API for Java

2014-11-12 Thread Ebbinge
I am aware that the BucketMapReduce has a method called addReducePhase, but
the documentation on java does not tell me what should go in the parameters,
and I haven't found any examples of it. I have a clue of how to do what I
need to do manually, using an arraylist, but, If the API has the reducephase
option It would be cool to understand how it works.



--
View this message in context: 
http://riak-users.197444.n3.nabble.com/Riak-API-for-Java-tp4032055p4032066.html
Sent from the Riak Users mailing list archive at Nabble.com.

___
riak-users mailing list
riak-users@lists.basho.com
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com


Re: Riak API for Java

2014-11-12 Thread Ebbinge
Now... I have another problem :/
Before I was using a node installed on my mac, I have an Ubuntu machine
which is a cluster along with other 2 Ubuntu Machines (Virtual Machines
using VMware). When I use the IP for the node on my mac, it works FINE,
but... If I use the IP of my Virtual Machine which, by the way is the name
of the node, it doesn't work and throws this error:

Exception in thread main com.basho.riak.client.RiakException:
java.io.IOException: Error receiving outputs: normal
at com.basho.riak.client.query.MapReduce.execute(MapReduce.java:81)
at riak.App.main(App.java:38)
Caused by: java.io.IOException: Error receiving outputs: normal
at
com.basho.riak.client.raw.pbc.PBClientAdapter.mapReduce(PBClientAdapter.java:429)
at com.basho.riak.client.query.MapReduce.execute(MapReduce.java:79)
... 1 more

The last question and this would be the LAST ONES I promise.



--
View this message in context: 
http://riak-users.197444.n3.nabble.com/Riak-API-for-Java-tp4032055p4032067.html
Sent from the Riak Users mailing list archive at Nabble.com.

___
riak-users mailing list
riak-users@lists.basho.com
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com


Riak API for Java

2014-11-11 Thread Ebbinge
Hello, I am trying to use the MapReduce function that comes along with the
Java API. I am using this code: 

try{ 
IRiakClient client = RiakFactory.pbcClient(192.168.0.41,
8087); 
Bucket myBucket = client.fetchBucket(Productos).execute();
//Bucket called Productos
BucketMapReduce m = client.mapReduce(Productos); 
m.addMapPhase(new NamedJSFunction(Riak.mapValuesJson), true); 
MapReduceResult result = m.execute(); 
//System.out.println(result.getResultRaw()); 
CollectionProducto tmp = result.getResult(Producto.class); 
for (Producto p : tmp) { 
System.out.println(p.Nombre+\n); 
} 

client.shutdown(); 

} 

catch(Exception Ex){ 
System.out.println(Ex.getMessage()); 
} 

I have a Producto Class like this:

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.StringTokenizer;
import javax.swing.JFileChooser;

/**
 *
 * @author edwinfernandez
 */
public class Producto {
public String ID;
public String Nombre;
public String Descripcion;
public String Vendedor;
public String Url;
public String Precio;

public Producto(String id,String name,String desc,String seller,String
precio,String url){
ID = id;
Nombre = name;
Descripcion = desc;
Vendedor = seller;
Precio = precio;
Url = url;
}
public Producto(){

}
}

I can't seem to make it work, I just need to mapreduce the description of
each product in order to get the top ten most used words to describe
products.

Thank you in advance.



--
View this message in context: 
http://riak-users.197444.n3.nabble.com/Riak-API-for-Java-tp4032055.html
Sent from the Riak Users mailing list archive at Nabble.com.

___
riak-users mailing list
riak-users@lists.basho.com
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com