Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Supper meta_data ranges like a-z #188

Merged
merged 1 commit into from

2 participants

@edwardcapriolo
Collaborator

Meta ranges.

@zznate zznate merged commit 13f31e4 into master
@zznate zznate deleted the ranged_meta_data branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 3, 2013
  1. @edwardcapriolo
This page is out of date. Refresh to see the latest.
View
14 src/main/java/org/usergrid/vx/experimental/Operations.java
@@ -58,6 +58,8 @@
private static final String MODE = "mode";
private static final String SAVE = "save";
private static final String GET = "get";
+ public static final String RANGE_START="range_start";
+ public static final String RANGE_END="range_end";
private Operations() {}
@@ -177,10 +179,20 @@ public static IntraOp assumeColumnOp(String keyspace , String columnfamily, Obje
return new IntraOp(IntraOp.Type.ASSUME)
.set(KEYSPACE, keyspace)
.set(COLUMN_FAMILY, columnfamily)
- .set(NAME, column) //should be column rowkey value
+ .set(NAME, column) //name of column
.set(CLAZZ, clazz );
}
+ public static IntraOp assumeRangedOp(String keyspace , String columnfamily, Object rangeStart, Object rangeEnd, String clazz){
+ return new IntraOp(IntraOp.Type.ASSUME)
+ .set(KEYSPACE, keyspace)
+ .set(COLUMN_FAMILY, columnfamily)
+ .set(RANGE_START, rangeStart)
+ .set(RANGE_END, rangeEnd)
+ .set(CLAZZ, clazz );
+ }
+
+
public static IntraOp createProcessorOp(String name, String spec, String value){
return new IntraOp(IntraOp.Type.CREATEPROCESSOR)
.set(NAME,name)
View
21 src/main/java/org/usergrid/vx/server/operations/AssumeHandler.java
@@ -3,6 +3,7 @@
import java.nio.ByteBuffer;
import org.apache.cassandra.utils.ByteBufferUtil;
+import org.usergrid.vx.experimental.Operations;
import org.vertx.java.core.eventbus.Message;
import org.vertx.java.core.json.JsonObject;
@@ -27,7 +28,7 @@ public void handleUser(Message<JsonObject> event) {
JsonObject state = event.body.getObject("state");
JsonObject meta = state.getObject("meta");
JsonObject metaColumn = state.getObject("metaColumn");
- JsonObject metaRanged = state.getObject("metaranged");
+ JsonObject metaRanged = state.getObject("metaRanged");
if (meta == null) {
meta = new JsonObject();
}
@@ -63,6 +64,24 @@ public void handleUser(Message<JsonObject> event) {
state.putObject("metaColumn", metaColumn);
event.reply(new JsonObject().putString(id.toString(), "OK")
.putObject("state", state));
+ } else if (params.getField(Operations.RANGE_START) !=null) {
+ Object start = params.getField(Operations.RANGE_START);
+ Object end = params.getField(Operations.RANGE_END);
+ ByteBuffer sbuf = HandlerUtils.byteBufferForObject(start);
+ ByteBuffer ebuf = HandlerUtils.byteBufferForObject(end);
+ StringBuilder key = new StringBuilder();
+ key.append(HandlerUtils.determineKs(params, state, null));
+ key.append(' ');
+ key.append(HandlerUtils.determineCf(params, state, null));
+ key.append(' ');
+ key.append(ByteBufferUtil.bytesToHex(sbuf));
+ JsonObject value = new JsonObject();
+ value.putString("clazz", params.getString("clazz"));
+ value.putString("end",ByteBufferUtil.bytesToHex(ebuf));
+ metaRanged.putObject(key.toString(), value);
+ state.putObject("metaRanged", metaRanged);
+ event.reply(new JsonObject().putString(id.toString(), "OK")
+ .putObject("state", state));
} else {
throw new RuntimeException("hit bottom this is bad ok");
}
View
36 src/main/java/org/usergrid/vx/server/operations/HandlerUtils.java
@@ -151,6 +151,9 @@ public static JsonArray readCf(ColumnFamily columnFamily, JsonObject state, Json
if (valueMetadata == null){
valueMetadata = findMetaData(columnFamily, state, "value");
}
+ if (valueMetadata == null){
+ valueMetadata = findRangedMetaData(columnFamily, state, ic.name().duplicate());
+ }
if (valueMetadata == null) {
m.put("value", TypeHelper.getBytes(ic.value()));
} else {
@@ -190,6 +193,34 @@ public static JsonObject findMetaData(ColumnFamily cf, JsonObject state, String
return meta.getObject(key.toString());
}
}
+ public static JsonObject findRangedMetaData(ColumnFamily cf, JsonObject state, ByteBuffer name) {
+ //System.out.println();
+ //System.out.println("ranged meta data");
+ StringBuilder key = new StringBuilder();
+ key.append(cf.metadata().ksName);
+ key.append(' ');
+ key.append(cf.metadata().cfName);
+ key.append(' ');
+ key.append(ByteBufferUtil.bytesToHex(name));
+ String skey = key.toString();
+ JsonObject meta = state.getObject("metaRanged");
+ Set<String> names = meta.getFieldNames();
+ for (String s: names){
+ //System.out.println("compare "+skey+ " to "+s);
+ if (skey.compareTo(s)>-1){
+ //System.out.println(skey+ " greater then "+s);
+ JsonObject value = meta.getObject(s);
+ String end = cf.metadata().ksName+' '+cf.metadata().cfName+' '+value.getString("end");
+ //System.out.println("compare "+skey+ " to "+end);
+ if (skey.compareToIgnoreCase(end)<0){
+ //System.out.println("matched!");
+ return value;
+ }
+ }
+ }
+ //System.out.println();
+ return null;
+ }
public static JsonObject findColumnMetaData(ColumnFamily cf, JsonObject state, ByteBuffer name) {
StringBuilder key = new StringBuilder();
@@ -209,7 +240,6 @@ public static JsonObject findColumnMetaData(ColumnFamily cf, JsonObject state, B
public static void readCf(ColumnFamily columnFamily, JsonObject state, EventBus eb,
Handler<Message<JsonArray>> filterReplyHandler) {
JsonArray components = state.getArray("components");
- System.out.println("state" + state);
JsonArray array = new JsonArray();
for (IColumn column : columnFamily) {
@@ -218,6 +248,7 @@ public static void readCf(ColumnFamily columnFamily, JsonObject state, EventBus
if (components.contains("name")) {
JsonObject columnMetadata = findMetaData(columnFamily, state, "column");
+
if (columnMetadata == null) {
m.put("name", ByteBufferUtil.getArray(column.name()));
} else {
@@ -232,6 +263,9 @@ public static void readCf(ColumnFamily columnFamily, JsonObject state, EventBus
JsonObject valueMetaData = HandlerUtils.findColumnMetaData(columnFamily, state, column.name().duplicate());
if (valueMetaData == null){
valueMetaData = findMetaData(columnFamily, state, "value");
+ }
+ if (valueMetaData == null){
+ valueMetaData = findRangedMetaData(columnFamily, state, column.name().duplicate());
}
if (valueMetaData == null) {
m.put("value", ByteBufferUtil.getArray(column.value()));
View
23 src/test/java/org/usergrid/vx/experimental/AssumeITest.java
@@ -84,4 +84,27 @@ public void columnAssumeTest() throws Exception{
Assert.assertEquals(5, x.get(0).get("value"));
Assert.assertEquals("wow", x.get(1).get("value"));
}
+
+ @Test
+ @RequiresColumnFamily(ksName = "myks", cfName = "columnasscf")
+ public void rangedAssumeTest() throws Exception{
+ IntraReq r = new IntraReq();
+ r.add( Operations.assumeRangedOp("myks", "columnasscf", "e", "f", "Int32Type") )
+ .add( Operations.assumeRangedOp("myks", "columnasscf", "y", "z", "UTF8Type") )
+ .add( Operations.setKeyspaceOp("myks"))
+ .add( Operations.setColumnFamilyOp("columnasscf"))
+ .add( Operations.setOp("darow", "e", 10) )
+ .add( Operations.setOp("darow", "e1", 11) )
+ .add( Operations.setOp("darow", "e5", 9) )
+ .add( Operations.setOp("darow", "y", "nice") )
+ .add( Operations.setOp("darow", "y1", "dude") )
+ .add( Operations.sliceOp("darow", "e", "z", 10));
+ IntraClient2 ic2 = new IntraClient2("localhost", 8080);
+ IntraRes res = ic2.sendBlocking(r);
+ List<Map> x = (List<Map>) res.getOpsRes().get(9);
+ Assert.assertEquals(10, x.get(0).get("value"));
+ Assert.assertEquals(11, x.get(1).get("value"));
+ Assert.assertEquals("nice", x.get(3).get("value"));
+ }
+
}
View
11 src/test/java/org/usergrid/vx/experimental/ThriftITest.java
@@ -10,6 +10,7 @@
import junit.framework.Assert;
import org.apache.cassandra.db.marshal.AbstractType;
+import org.apache.cassandra.db.marshal.Int32Type;
import org.apache.cassandra.db.marshal.UTF8Type;
import org.apache.cassandra.locator.SimpleStrategy;
import org.apache.cassandra.thrift.Cassandra;
@@ -206,4 +207,14 @@ public void deleteByPredicateTEst() throws Exception {
wrap.close();
}
+ @Test
+ public void testWriteReadComposites(){
+ byte [] bob = "bob".getBytes();
+ byte [] tall = ByteBufferUtil.getArray(Int32Type.instance.decompose(5));
+ byte [] composite = CompositeTool.makeComposite(Arrays.asList(bob,tall));
+ List<byte[]> results = CompositeTool.readComposite(composite);
+ Assert.assertEquals(new String (bob), new String(results.get(0)));
+ Assert.assertEquals(new Integer(5), Int32Type.instance.compose(ByteBuffer.wrap(results.get(1))) );
+ }
+
}
Something went wrong with that request. Please try again.