Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Users can now chose columns wanted from select
  • Loading branch information
edwardcapriolo committed Feb 3, 2013
1 parent 79d4d90 commit 24df119
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/main/java/org/usergrid/vx/experimental/IntraOp.java
Expand Up @@ -542,6 +542,14 @@ public void execute(IntraReq req, IntraRes res, IntraState state,
ServiceProcessor sp = IntraState.serviceProcessors.get(name);
sp.process(req, res, state, i, vertx, is);
}
}, COMPONENTSELECT {
@Override
public void execute(IntraReq req, IntraRes res, IntraState state,
int i, Vertx vertx, IntraService is) {
IntraOp op = req.getE().get(i);
Set<String> parts = (Set<String>) op.getOp().get("components");
state.components = parts;
}
};

public abstract void execute(IntraReq req, IntraRes res, IntraState state, int i, Vertx vertx, IntraService is);
Expand Down
16 changes: 13 additions & 3 deletions src/main/java/org/usergrid/vx/experimental/IntraService.java
Expand Up @@ -123,9 +123,19 @@ static void readCf(ColumnFamily cf , List<Map> finalResults, IntraState state, I
while (it.hasNext()) {
IColumn ic = it.next();
if (ic.isLive()){
HashMap m = new HashMap();
m.put("name", TypeHelper.getTypedIfPossible(state, "column", ic.name(), op));
m.put("value", TypeHelper.getTypedIfPossible(state, "value", ic.value(), op));
HashMap m = new HashMap();
if (state.components.contains("name")){
m.put("name", TypeHelper.getTypedIfPossible(state, "column", ic.name(), op));
}
if (state.components.contains("value")){
m.put("value", TypeHelper.getTypedIfPossible(state, "value", ic.value(), op));
}
if (state.components.contains("timestamp")){
m.put("timestamp",ic.timestamp());
}
if (state.components.contains("markeddelete")){
m.put("markeddelete", ic.getMarkedForDeleteAt());
}
if (state.currentFilter != null){
Map newMap = state.currentFilter.filter(m);
if (newMap != null){
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/org/usergrid/vx/experimental/IntraState.java
Expand Up @@ -11,11 +11,17 @@

/* class that holds properties for the request lifecycle */
public class IntraState {

public IntraState(){
components.add("name");
components.add("value");
}
//TODO this should be an epiring cache
private static Map<Integer,IntraState> savedState = new HashMap<Integer,IntraState>();
private static AtomicInteger id=new AtomicInteger(0);
String currentKeyspace="";
String currentColumnFamily="";
Set<String> components = new HashSet<String>();
boolean autoTimestamp= true;
long nanotime = System.nanoTime();
ConsistencyLevel consistency= ConsistencyLevel.ONE;
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/usergrid/vx/experimental/Operations.java
Expand Up @@ -5,6 +5,7 @@

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
* Factory class for building IntraOp objects
Expand Down Expand Up @@ -227,6 +228,10 @@ public static IntraOp createServiceProcess(String name, String spec, String valu
public static IntraOp serviceProcess(String name, Map params){
return new IntraOp(IntraOp.Type.SERVICEPROCESS).set(NAME, name).set(PARAMS, params);
}

public static IntraOp componentSelect(Set<String> components){
return new IntraOp(IntraOp.Type.COMPONENTSELECT).set("components", components);
}

private static void checkForBlankStr(String arg, String msg, IntraOp.Type type) {
Preconditions.checkArgument(arg != null && arg.length() > 0,
Expand Down
29 changes: 28 additions & 1 deletion src/test/java/org/usergrid/vx/experimental/IntraServiceTest.java
Expand Up @@ -496,7 +496,7 @@ public void jsonTest() throws Exception {
" List<Map> results = new ArrayList<HashMap>();"+
" for (Map row: input){" +
" Map newRow = new HashMap(); "+
// grovvy requires you to escape ?
// grovvy requires you to escape $
" Integer match = JsonPath.read(row.get(\"value\").toString(), \"\\$.[1].value\"); \n"+
" newRow.put(\"value\",match.toString()); \n "+
" results.add(newRow); \n"+
Expand Down Expand Up @@ -605,4 +605,31 @@ public void optioanKSandCSTest() {
Assert.assertEquals( "wow", x.get(0).get("value") );
Assert.assertEquals( 1, x.get(0).get("name") );
}


@Test
@RequiresColumnFamily(ksName = "myks", cfName = "mycf")
public void componentTest() {
IntraReq req = new IntraReq();
req.add(Operations.setAutotimestampOp()); // 0
req.add(Operations.assumeOp("myks", "mycf", "value", "UTF-8"));// 1
req.add(Operations.assumeOp("myks", "mycf", "column", "int32"));// 2
IntraOp setOp = Operations.setOp("optional", 1, "wow"); // 3
setOp.set("keyspace", "myks");
setOp.set("columnfamily", "mycf");
req.add(setOp);
Set<String> wanted = new HashSet<String>();
wanted.addAll( Arrays.asList( new String []{"value","timestamp"}));
req.add( Operations.componentSelect(wanted)); //4
// opa sexyy builder style
req.add(Operations.getOp("optional", 1).set("keyspace", "myks")
.set("columnfamily", "mycf")); // 5
IntraRes res = new IntraRes();
is.handleIntraReq(req, res, x);
List<Map> x = (List<Map>) res.getOpsRes().get(5);

Assert.assertEquals("wow", x.get(0).get("value"));
Assert.assertEquals(true, x.get(0).containsKey("timestamp"));
Assert.assertTrue( (Long)x.get(0).get("timestamp") > 0);
}
}

0 comments on commit 24df119

Please sign in to comment.