You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sn...@apache.org on 2014/03/27 18:21:02 UTC

[15/27] Put queryindex classes all under one top-level "index" package to eliminate conflict with old persistence classes.

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/ContainsOperand.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/ContainsOperand.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/ContainsOperand.java
new file mode 100644
index 0000000..b952d13
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/ContainsOperand.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF 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.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.usergrid.persistence.index.query.tree;
+
+
+import org.antlr.runtime.Token;
+import org.apache.usergrid.persistence.index.exceptions.PersistenceException;
+
+
+/** @author tnine */
+public class ContainsOperand extends EqualityOperand {
+
+    /**
+     * @param property
+     * @param literal
+     */
+    public ContainsOperand( Token t ) {
+        super( t );
+    }
+
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see
+     * org.apache.usergrid.persistence.query.tree.Operand#visit(org.apache.usergrid.persistence
+     * .query.tree.QueryVisitor)
+     */
+    @Override
+    public void visit( QueryVisitor visitor ) throws PersistenceException {
+        visitor.visit( this );
+    }
+
+
+    public StringLiteral getString() {
+        return ( StringLiteral ) getLiteral();
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.usergrid.persistence.query.tree.EqualityOperand#newProperty(java.lang.String)
+     */
+    @Override
+    protected Property newProperty( String name ) {
+        return new ContainsProperty( name );
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.usergrid.persistence.query.tree.EqualityOperand#getProperty()
+     */
+    @Override
+    public ContainsProperty getProperty() {
+        return ( ContainsProperty ) this.children.get( 0 );
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/ContainsProperty.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/ContainsProperty.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/ContainsProperty.java
new file mode 100644
index 0000000..0c282ac
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/ContainsProperty.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF 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.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.usergrid.persistence.index.query.tree;
+
+
+import org.antlr.runtime.ClassicToken;
+import org.antlr.runtime.Token;
+
+
+/**
+ * A property for full text searching that requires special renaming
+ *
+ * @author tnine
+ */
+public class ContainsProperty extends Property {
+
+    private String indexedName = null;
+
+
+    public ContainsProperty( Token t ) {
+        super( t );
+        this.indexedName = String.format( "%s.keywords", super.getValue() );
+    }
+
+
+    public ContainsProperty( String property ) {
+        this( new ClassicToken( 0, property ) );
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.usergrid.persistence.query.tree.Property#getIndexedValue()
+     */
+    @Override
+    public String getIndexedValue() {
+        return this.indexedName;
+    }
+
+
+    /** @return the property */
+    public ContainsProperty getProperty() {
+        return ( ContainsProperty ) this.children.get( 0 );
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/Equal.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/Equal.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/Equal.java
new file mode 100644
index 0000000..0769f39
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/Equal.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF 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.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.usergrid.persistence.index.query.tree;
+
+
+import org.antlr.runtime.ClassicToken;
+import org.antlr.runtime.Token;
+import org.apache.usergrid.persistence.index.exceptions.NoIndexException;
+
+
+/** @author tnine */
+public class Equal extends EqualityOperand {
+
+    /**
+     * @param property
+     * @param literal
+     */
+    public Equal( Token t ) {
+        super( t );
+    }
+
+
+    public Equal() {
+        super( new ClassicToken( 0, "=" ) );
+    }
+
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see
+     * org.apache.usergrid.persistence.query.tree.Operand#visit(org.apache.usergrid.persistence
+     * .query.tree.QueryVisitor)
+     */
+    @Override
+    public void visit( QueryVisitor visitor ) throws NoIndexException {
+        visitor.visit( this );
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/EqualityOperand.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/EqualityOperand.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/EqualityOperand.java
new file mode 100644
index 0000000..3ae654d
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/EqualityOperand.java
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF 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.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.usergrid.persistence.index.query.tree;
+
+
+import org.antlr.runtime.Token;
+
+
+/**
+ * A base class for any equality expression. Expressions must have a property and a value. Examples are >=, >, =, <,
+ * <=,
+ *
+ * @author tnine
+ */
+public abstract class EqualityOperand extends Operand {
+
+    /**
+     * @param property
+     * @param literal
+     */
+    public EqualityOperand( Token t ) {
+        super( t );
+    }
+
+
+    public EqualityOperand( String propName, Literal<?> value ) {
+        super( null );
+    }
+
+
+    /** Set the property on this operand */
+    public void setProperty( String name ) {
+        setAtIndex( 0, newProperty( name ) );
+    }
+
+
+    /** Get the property to set into the equality. Allows subclasses to override the type */
+    protected Property newProperty( String name ) {
+        return new Property( name );
+    }
+
+
+    /** Set the literal on this operand from the given value */
+    public void setLiteral( Object value ) {
+        setAtIndex( 1, LiteralFactory.getLiteral( value ) );
+    }
+
+
+    /** Set the child at the specified index. If it doesn't exist, it's added until it does */
+    @SuppressWarnings("unchecked")
+    private void setAtIndex( int index, Literal<?> value ) {
+
+        if ( children == null ) {
+            children = createChildrenList();
+        }
+
+        while ( children.size() - 1 < index ) {
+            children.add( null );
+        }
+
+        setChild( index, value );
+    }
+
+
+    /** @return the property */
+    public Property getProperty() {
+        return ( Property ) this.children.get( 0 );
+    }
+
+
+    /** @return the literal */
+    public Literal<?> getLiteral() {
+        return ( Literal<?> ) this.children.get( 1 );
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/FloatLiteral.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/FloatLiteral.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/FloatLiteral.java
new file mode 100644
index 0000000..eaec4d4
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/FloatLiteral.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF 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.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.usergrid.persistence.index.query.tree;
+
+
+import org.antlr.runtime.ClassicToken;
+import org.antlr.runtime.Token;
+
+
+/** @author tnine */
+public class FloatLiteral extends Literal<Float> implements NumericLiteral {
+
+    private float value;
+
+
+    /**
+     * @param t
+     */
+    public FloatLiteral( Token t ) {
+        super( t );
+        value = Float.valueOf( t.getText() );
+    }
+
+
+    public FloatLiteral( float f ) {
+        super( new ClassicToken( 0, String.valueOf( f ) ) );
+        value = f;
+    }
+
+
+    /** @return the value */
+    public Float getValue() {
+        return value;
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.usergrid.persistence.query.tree.NumericLiteral#getFloatValue()
+     */
+    @Override
+    public float getFloatValue() {
+        return value;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/GreaterThan.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/GreaterThan.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/GreaterThan.java
new file mode 100644
index 0000000..fd8e628
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/GreaterThan.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF 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.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.usergrid.persistence.index.query.tree;
+
+
+import org.antlr.runtime.CommonToken;
+import org.antlr.runtime.Token;
+import org.apache.usergrid.persistence.index.exceptions.NoIndexException;
+
+
+/** @author tnine */
+public class GreaterThan extends EqualityOperand {
+
+    /**
+     * @param property
+     * @param literal
+     */
+    public GreaterThan( Token t ) {
+        super( t );
+    }
+
+
+    public GreaterThan() {
+        super( new CommonToken( 0, ">" ) );
+    }
+
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see
+     * org.apache.usergrid.persistence.query.tree.Operand#visit(org.apache.usergrid.persistence
+     * .query.tree.QueryVisitor)
+     */
+    @Override
+    public void visit( QueryVisitor visitor ) throws NoIndexException {
+        visitor.visit( this );
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/GreaterThanEqual.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/GreaterThanEqual.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/GreaterThanEqual.java
new file mode 100644
index 0000000..075c3a8
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/GreaterThanEqual.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF 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.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.usergrid.persistence.index.query.tree;
+
+
+import org.antlr.runtime.CommonToken;
+import org.antlr.runtime.Token;
+import org.apache.usergrid.persistence.index.exceptions.NoIndexException;
+
+
+/** @author tnine */
+public class GreaterThanEqual extends EqualityOperand {
+
+    /**
+     * @param property
+     * @param literal
+     */
+    public GreaterThanEqual( Token t ) {
+        super( t );
+    }
+
+
+    /**
+     * @param property
+     * @param literal
+     */
+    public GreaterThanEqual() {
+        super( new CommonToken( 0, ">=" ) );
+    }
+
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see
+     * org.apache.usergrid.persistence.query.tree.Operand#visit(org.apache.usergrid.persistence
+     * .query.tree.QueryVisitor)
+     */
+    @Override
+    public void visit( QueryVisitor visitor ) throws NoIndexException {
+        visitor.visit( this );
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/LessThan.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/LessThan.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/LessThan.java
new file mode 100644
index 0000000..9113f20
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/LessThan.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF 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.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.usergrid.persistence.index.query.tree;
+
+
+import org.antlr.runtime.CommonToken;
+import org.antlr.runtime.Token;
+import org.apache.usergrid.persistence.index.exceptions.NoIndexException;
+
+
+/** @author tnine */
+public class LessThan extends EqualityOperand {
+
+    /**
+     * @param property
+     * @param literal
+     */
+    public LessThan( Token t ) {
+        super( t );
+    }
+
+
+    public LessThan() {
+        super( new CommonToken( 0, "<" ) );
+    }
+
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see
+     * org.apache.usergrid.persistence.query.tree.Operand#visit(org.apache.usergrid.persistence
+     * .query.tree.QueryVisitor)
+     */
+    @Override
+    public void visit( QueryVisitor visitor ) throws NoIndexException {
+        visitor.visit( this );
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/LessThanEqual.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/LessThanEqual.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/LessThanEqual.java
new file mode 100644
index 0000000..bc75c78
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/LessThanEqual.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF 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.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.usergrid.persistence.index.query.tree;
+
+
+import org.antlr.runtime.CommonToken;
+import org.antlr.runtime.Token;
+import org.apache.usergrid.persistence.index.exceptions.NoIndexException;
+
+
+/** @author tnine */
+public class LessThanEqual extends EqualityOperand {
+
+    /**
+     * @param property
+     * @param literal
+     */
+    public LessThanEqual( Token t ) {
+        super( t );
+    }
+
+
+    /**
+     */
+    public LessThanEqual() {
+        super( new CommonToken( 0, "<=" ) );
+    }
+
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see
+     * org.apache.usergrid.persistence.query.tree.Operand#visit(org.apache.usergrid.persistence
+     * .query.tree.QueryVisitor)
+     */
+    @Override
+    public void visit( QueryVisitor visitor ) throws NoIndexException {
+        visitor.visit( this );
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/Literal.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/Literal.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/Literal.java
new file mode 100644
index 0000000..cca51f8
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/Literal.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF 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.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.usergrid.persistence.index.query.tree;
+
+
+import org.antlr.runtime.Token;
+import org.antlr.runtime.tree.CommonTree;
+
+
+/**
+ * Abstract class for literals
+ *
+ * @author tnine
+ */
+public abstract class Literal<V> extends CommonTree {
+
+
+    protected Literal( Token t ) {
+        super( t );
+    }
+
+
+    /** Return the value of the literal the user has passed in */
+    public abstract V getValue();
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/LiteralFactory.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/LiteralFactory.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/LiteralFactory.java
new file mode 100644
index 0000000..672a6df
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/LiteralFactory.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF 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.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.usergrid.persistence.index.query.tree;
+
+
+import java.util.UUID;
+
+
+/**
+ * Simple factory for generating literal instance based on the runtime value
+ *
+ * @author tnine
+ */
+public class LiteralFactory {
+
+    /** Generate the correct literal subclass based on the runtime instance. */
+    public static final Literal<?> getLiteral( Object value ) {
+        if ( value instanceof Integer ) {
+            return new LongLiteral( ( Integer ) value );
+        }
+        if ( value instanceof Long ) {
+            return new LongLiteral( ( Long ) value );
+        }
+
+        if ( value instanceof String ) {
+            return new StringLiteral( ( String ) value );
+        }
+
+        if ( value instanceof Float ) {
+            return new FloatLiteral( ( Float ) value );
+        }
+
+        if ( value instanceof UUID ) {
+            return new UUIDLiteral( ( UUID ) value );
+        }
+
+        if ( value instanceof Boolean ) {
+            return new BooleanLiteral( ( Boolean ) value );
+        }
+
+        throw new UnsupportedOperationException(
+                String.format( "Unsupported type of %s was passed when trying to construct a literal",
+                        value.getClass() ) );
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/LongLiteral.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/LongLiteral.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/LongLiteral.java
new file mode 100644
index 0000000..690fb51
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/LongLiteral.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF 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.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.usergrid.persistence.index.query.tree;
+
+
+import org.antlr.runtime.ClassicToken;
+import org.antlr.runtime.Token;
+
+
+/** @author tnine */
+public class LongLiteral extends Literal<Long> implements NumericLiteral {
+
+    private long value;
+
+
+    /**
+     * @param t
+     */
+    public LongLiteral( Token t ) {
+        super( t );
+        this.value = Long.valueOf( t.getText() );
+    }
+
+
+    /**
+     *
+     * @param value
+     */
+    public LongLiteral( long value ) {
+        super( new ClassicToken( 0, String.valueOf( value ) ) );
+        this.value = value;
+    }
+
+
+    /**
+     *
+     * @return
+     */
+    public Long getValue() {
+        return this.value;
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.usergrid.persistence.query.tree.NumericLiteral#getFloatValue()
+     */
+    @Override
+    public float getFloatValue() {
+        return value;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/NotOperand.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/NotOperand.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/NotOperand.java
new file mode 100644
index 0000000..e41e94b
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/NotOperand.java
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * Copyright 2012 Apigee Corporation
+ *
+ * Licensed 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.apache.usergrid.persistence.index.query.tree;
+
+
+import org.antlr.runtime.Token;
+import org.apache.usergrid.persistence.index.exceptions.PersistenceException;
+
+
+/** @author tnine */
+public class NotOperand extends Operand {
+
+
+    public NotOperand( Token t ) {
+        super( t );
+    }
+
+
+    /** get the only child operation */
+    public Operand getOperation() {
+        return ( Operand ) this.children.get( 0 );
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.usergrid.persistence.query.tree.Operand#visit(org.apache.usergrid.persistence.query.tree.QueryVisitor)
+     */
+    @Override
+    public void visit( QueryVisitor visitor ) throws PersistenceException {
+        visitor.visit( this );
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/NumericLiteral.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/NumericLiteral.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/NumericLiteral.java
new file mode 100644
index 0000000..493a211
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/NumericLiteral.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF 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.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.usergrid.persistence.index.query.tree;
+
+
+/** @author tnine */
+public interface NumericLiteral {
+
+    /** Return the value of this numeric literal as a float */
+    public float getFloatValue();
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/Operand.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/Operand.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/Operand.java
new file mode 100644
index 0000000..1363941
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/Operand.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF 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.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.usergrid.persistence.index.query.tree;
+
+
+import org.antlr.runtime.Token;
+import org.antlr.runtime.tree.CommonTree;
+import org.apache.usergrid.persistence.index.exceptions.PersistenceException;
+
+
+/**
+ * Any logical operation should subclass.  Boolean logic, equality, not, contains, within and others are examples of
+ * operands
+ *
+ * @author tnine
+ */
+public abstract class Operand extends CommonTree {
+
+
+    /** Default constructor to take a token */
+    public Operand( Token t ) {
+        super( t );
+    }
+
+
+    /** Get the pointer to the parent node */
+    public Operand getParent() {
+        return ( Operand ) super.getParent();
+    }
+
+
+    /** Visitor method */
+    public abstract void visit( QueryVisitor visitor ) throws PersistenceException;
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/OrOperand.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/OrOperand.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/OrOperand.java
new file mode 100644
index 0000000..97678bc
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/OrOperand.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF 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.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.usergrid.persistence.index.query.tree;
+
+
+import org.antlr.runtime.CommonToken;
+import org.antlr.runtime.Token;
+import org.apache.usergrid.persistence.index.exceptions.PersistenceException;
+
+
+/** @author tnine */
+public class OrOperand extends BooleanOperand {
+
+    /**
+     * @param left
+     * @param token
+     * @param right
+     */
+    public OrOperand( Token t ) {
+        super( t );
+    }
+
+
+    public OrOperand() {
+        super( new CommonToken( 0, "or" ) );
+    }
+
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see
+     * org.apache.usergrid.persistence.query.tree.Operand#visit(org.apache.usergrid.persistence
+     * .query.tree.QueryVisitor)
+     */
+    @Override
+    public void visit( QueryVisitor visitor ) throws PersistenceException {
+        visitor.visit( this );
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/Property.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/Property.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/Property.java
new file mode 100644
index 0000000..f9bf67c
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/Property.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF 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.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.usergrid.persistence.index.query.tree;
+
+
+import org.antlr.runtime.ClassicToken;
+import org.antlr.runtime.Token;
+
+
+/**
+ * A property
+ *
+ * @author tnine
+ */
+public class Property extends Literal<String> {
+
+    private String property;
+
+
+    public Property( Token t ) {
+        super( t );
+        this.property = t.getText();
+    }
+
+
+    public Property( String property ) {
+        this( new ClassicToken( 0, property ) );
+    }
+
+
+    /*
+     * (non-Javadoc)
+     *
+     * @see org.apache.usergrid.persistence.query.tree.Literal#getValue()
+     */
+    @Override
+    public String getValue() {
+        return this.property;
+    }
+
+
+    /**
+     * Subclasses an override.  Indexed value could be different when stored internally.  By default returns the same
+     * property
+     */
+    public String getIndexedValue() {
+        return this.property;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/QueryVisitor.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/QueryVisitor.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/QueryVisitor.java
new file mode 100644
index 0000000..e12c134
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/QueryVisitor.java
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF 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.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.usergrid.persistence.index.query.tree;
+
+
+import org.apache.usergrid.persistence.index.exceptions.NoFullTextIndexException;
+import org.apache.usergrid.persistence.index.exceptions.NoIndexException;
+import org.apache.usergrid.persistence.index.exceptions.PersistenceException;
+import org.elasticsearch.index.query.FilterBuilder;
+import org.elasticsearch.index.query.QueryBuilder;
+
+
+/**
+ * Interface for visiting nodes in our AST as we produce
+ *
+ * @author tnine
+ */
+public interface QueryVisitor {
+
+    /**
+     *
+     * @param op
+     * @throws PersistenceException
+     */
+    public void visit( AndOperand op ) throws PersistenceException;
+
+    /**
+     * @param op
+     * @throws PersistenceException
+     */
+    public void visit( OrOperand op ) throws PersistenceException;
+
+    /**
+     * @param op
+     * @throws PersistenceException
+     */
+    public void visit( NotOperand op ) throws PersistenceException;
+
+    /**
+     * @param op
+     * @throws NoIndexException
+     */
+    public void visit( LessThan op ) throws NoIndexException;
+
+    /**
+     * @param op
+     * @throws NoFullTextIndexException
+     */
+    public void visit( ContainsOperand op ) throws NoFullTextIndexException;
+
+    /**
+     * @param op
+     */
+    public void visit( WithinOperand op );
+
+    /**
+     * @param op
+     * @throws NoIndexException
+     */
+    public void visit( LessThanEqual op ) throws NoIndexException;
+
+    /**
+     * @param op
+     * @throws NoIndexException
+     */
+    public void visit( Equal op ) throws NoIndexException;
+
+    /**
+     * @param op
+     * @throws NoIndexException
+     */
+    public void visit( GreaterThan op ) throws NoIndexException;
+
+    /**
+     * @param op
+     * @throws NoIndexException
+     */
+    public void visit( GreaterThanEqual op ) throws NoIndexException;
+
+    /** 
+     * Returns resulting query builder.
+     */
+    public QueryBuilder getQueryBuilder();
+
+	public FilterBuilder getFilterBuilder();
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/StringLiteral.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/StringLiteral.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/StringLiteral.java
new file mode 100644
index 0000000..196fcfa
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/StringLiteral.java
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF 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.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.usergrid.persistence.index.query.tree;
+
+
+import org.antlr.runtime.ClassicToken;
+import org.antlr.runtime.Token;
+
+import static org.apache.commons.lang.StringUtils.removeEnd;
+
+
+/** @author tnine */
+public class StringLiteral extends Literal<String> {
+
+    private String value;
+    private String finishValue;
+
+
+    /**
+     * @param t
+     */
+    public StringLiteral( Token t ) {
+        super( t );
+        String newValue = t.getText();
+        newValue = newValue.substring( 1, newValue.length() - 1 );
+
+        parseValue( newValue );
+    }
+
+
+    public StringLiteral( String value ) {
+        super( new ClassicToken( 0, value ) );
+        parseValue( value );
+    }
+
+
+    /** Parse the value and set the optional end value */
+    private void parseValue( String value ) {
+
+        this.value = value.trim().toLowerCase();
+
+        if ( "*".equals( value ) ) {
+            this.value = null;
+            this.finishValue = null;
+            return;
+        }
+
+        if ( value != null && value.endsWith( "*" ) ) {
+            this.value = removeEnd( value.toString(), "*" );
+
+            finishValue = this.value + "\uFFFF";
+        }
+        // set the end value to the same as the start value
+        else {
+            finishValue = value;
+        }
+    }
+
+
+    /** If this were a string literal */
+    public String getEndValue() {
+        return this.finishValue;
+    }
+
+
+    public String getValue() {
+        return this.value;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/UUIDLiteral.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/UUIDLiteral.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/UUIDLiteral.java
new file mode 100644
index 0000000..0cf91a3
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/UUIDLiteral.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF 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.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.usergrid.persistence.index.query.tree;
+
+
+import java.util.UUID;
+
+import org.antlr.runtime.ClassicToken;
+import org.antlr.runtime.Token;
+
+
+/** @author tnine */
+public class UUIDLiteral extends Literal<UUID> {
+
+    private UUID value;
+
+
+    /**
+     * @param t
+     */
+    public UUIDLiteral( Token t ) {
+        super( t );
+        value = UUID.fromString( t.getText() );
+    }
+
+
+    public UUIDLiteral( UUID value ) {
+        super( new ClassicToken( 0, String.valueOf( value ) ) );
+        this.value = value;
+    }
+
+
+    public UUID getValue() {
+        return this.value;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/WithinOperand.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/WithinOperand.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/WithinOperand.java
new file mode 100644
index 0000000..602fc34
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/WithinOperand.java
@@ -0,0 +1,111 @@
+/*******************************************************************************
+ * Copyright 2012 Apigee Corporation
+ *
+ * Licensed 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.apache.usergrid.persistence.index.query.tree;
+
+
+import org.antlr.runtime.Token;
+
+
+/** @author tnine */
+public class WithinOperand extends Operand {
+
+    /**
+     * @param property
+     * @param literal
+     */
+    public WithinOperand( Token t ) {
+        super( t );
+    }
+
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see
+     * org.apache.usergrid.persistence.query.tree.Operand#visit(org.apache.usergrid.persistence
+     * .query.tree.QueryVisitor)
+     */
+    @Override
+    public void visit( QueryVisitor visitor ) {
+        visitor.visit( this );
+    }
+
+
+    /**
+     * @param propName
+     */
+    public void setProperty( String propName ) {
+        setChild( 0, new WithinProperty( propName ) );
+    }
+
+
+    /**
+     * @param distance
+     */
+    public void setDistance( float distance ) {
+        setChild( 1, new FloatLiteral( distance ) );
+    }
+
+
+    /**
+     * @param Latitude
+     */
+    public void setLatitude( float Latitude ) {
+        setChild( 2, new FloatLiteral( Latitude ) );
+    }
+
+
+    /**
+     * @param longitude
+     */
+    public void setLongitude( float longitude ) {
+        setChild( 3, new FloatLiteral( longitude ) );
+    }
+
+
+    /**
+     *
+     * @return
+     */
+    public WithinProperty getProperty() {
+        return ( WithinProperty ) this.children.get( 0 );
+    }
+
+
+    /**
+     *
+     * @return
+     */
+    public NumericLiteral getDistance() {
+        return ( NumericLiteral ) this.children.get( 1 );
+    }
+
+
+    /**
+     * @return
+     */
+    public NumericLiteral getLatitude() {
+        return ( NumericLiteral ) this.children.get( 2 );
+    }
+
+
+    /**
+     * @return
+     */
+    public NumericLiteral getLongitude() {
+        return ( NumericLiteral ) this.children.get( 3 );
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/WithinProperty.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/WithinProperty.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/WithinProperty.java
new file mode 100644
index 0000000..a9b5899
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/WithinProperty.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF 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.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.usergrid.persistence.index.query.tree;
+
+
+import org.antlr.runtime.ClassicToken;
+import org.antlr.runtime.Token;
+
+
+/**
+ * A property
+ *
+ * @author tnine
+ */
+public class WithinProperty extends Property {
+
+    private String indexedName = null;
+
+
+    public WithinProperty( Token t ) {
+        super( t );
+        this.indexedName = String.format( "%s.coordinates", super.getValue() );
+    }
+
+
+    public WithinProperty( String property ) {
+        this( new ClassicToken( 0, property ) );
+    }
+
+
+    /** Get the */
+    public String getIndexedName() {
+        return this.indexedName;
+    }
+
+
+    /** @return the property */
+    public WithinProperty getProperty() {
+        return ( WithinProperty ) this.children.get( 0 );
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/ClassUtils.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/ClassUtils.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/ClassUtils.java
new file mode 100644
index 0000000..ab51d55
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/ClassUtils.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.apache.usergrid.persistence.index.utils;
+
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+
+public class ClassUtils extends org.apache.commons.lang.ClassUtils {
+
+    @SuppressWarnings("unchecked")
+    public static <A, B> B cast( A a ) {
+        return ( B ) a;
+    }
+
+
+    @SuppressWarnings("unchecked")
+    private static final Set<Class<?>> WRAPPER_TYPES = new HashSet<Class<?>>(
+            Arrays.asList( Boolean.class, Byte.class, Character.class, Double.class, Float.class, Integer.class,
+                    Long.class, Short.class, Void.class ) );
+
+
+    public static boolean isWrapperType( Class<?> clazz ) {
+        return WRAPPER_TYPES.contains( clazz );
+    }
+
+
+    public static boolean isPrimitiveType( Class<?> clazz ) {
+        if ( clazz == null ) {
+            return false;
+        }
+        return clazz.isPrimitive() || isWrapperType( clazz );
+    }
+
+
+    public static boolean isBasicType( Class<?> clazz ) {
+        if ( clazz == null ) {
+            return false;
+        }
+        return ( String.class.isAssignableFrom( clazz ) ) || isPrimitiveType( clazz );
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/ConversionUtils.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/ConversionUtils.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/ConversionUtils.java
new file mode 100644
index 0000000..503d597
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/ConversionUtils.java
@@ -0,0 +1,765 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.apache.usergrid.persistence.index.utils;
+
+
+import java.io.UnsupportedEncodingException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.commons.lang.math.NumberUtils;
+
+
+/** Convenience methods for converting to and from formats, primarily between byte arrays and UUIDs, Strings,
+ * and Longs. */
+public class ConversionUtils {
+
+    private static final Logger logger = LoggerFactory.getLogger( ConversionUtils.class );
+
+    /**
+     *
+     */
+    public static final String UTF8_ENCODING = "UTF-8";
+
+    /**
+     *
+     */
+    public static final String ASCII_ENCODING = "US-ASCII";
+
+    public static final ByteBuffer HOLDER = ByteBuffer.wrap( new byte[] { 0 } );
+
+
+    /**
+     * @param uuid
+     * @return
+     */
+    public static UUID uuid( byte[] uuid ) {
+        return uuid( uuid, 0 );
+    }
+
+
+    /**
+     * @param uuid
+     * @param offset
+     * @return
+     */
+    public static UUID uuid( byte[] uuid, int offset ) {
+        ByteBuffer bb = ByteBuffer.wrap( uuid, offset, 16 );
+        return new UUID( bb.getLong(), bb.getLong() );
+    }
+
+
+    public static UUID uuid( ByteBuffer bb ) {
+        if ( bb == null ) {
+            return null;
+        }
+        if ( bb.remaining() < 16 ) {
+            return null;
+        }
+        bb = bb.slice();
+        return new UUID( bb.getLong(), bb.getLong() );
+    }
+
+
+    /**
+     * @param uuid
+     * @return
+     */
+    public static UUID uuid( String uuid ) {
+        try {
+            return UUID.fromString( uuid );
+        }
+        catch ( Exception e ) {
+            logger.error( "Bad UUID", e );
+        }
+        return UUIDUtils.ZERO_UUID;
+    }
+
+
+    /**
+     * @param obj
+     * @return
+     */
+    public static UUID uuid( Object obj ) {
+        return uuid( obj, UUIDUtils.ZERO_UUID );
+    }
+
+
+    public static UUID uuid( Object obj, UUID defaultValue ) {
+        if ( obj instanceof UUID ) {
+            return ( UUID ) obj;
+        }
+        else if ( obj instanceof byte[] ) {
+            return uuid( ( byte[] ) obj );
+        }
+        else if ( obj instanceof ByteBuffer ) {
+            return uuid( ( ByteBuffer ) obj );
+        }
+        else if ( obj instanceof String ) {
+            return uuid( ( String ) obj );
+        }
+        return defaultValue;
+    }
+
+
+    /**
+     * @param uuid
+     * @return
+     */
+    public static byte[] bytes( UUID uuid ) {
+        if ( uuid == null ) {
+            return null;
+        }
+        long msb = uuid.getMostSignificantBits();
+        long lsb = uuid.getLeastSignificantBits();
+        byte[] buffer = new byte[16];
+
+        for ( int i = 0; i < 8; i++ ) {
+            buffer[i] = ( byte ) ( msb >>> ( 8 * ( 7 - i ) ) );
+        }
+        for ( int i = 8; i < 16; i++ ) {
+            buffer[i] = ( byte ) ( lsb >>> ( 8 * ( 7 - i ) ) );
+        }
+
+        return buffer;
+    }
+
+
+    public static ByteBuffer bytebuffer( UUID uuid ) {
+        if ( uuid == null ) {
+            return null;
+        }
+        return ByteBuffer.wrap( bytes( uuid ) );
+    }
+
+
+    /**
+     * @param uuid
+     * @return
+     */
+    public static byte[] uuidToBytesNullOk( UUID uuid ) {
+        if ( uuid != null ) {
+            return bytes( uuid );
+        }
+        return new byte[16];
+    }
+
+
+    /**
+     * @param s
+     * @return
+     */
+    public static byte[] bytes( String s ) {
+        return bytes( s, UTF8_ENCODING );
+    }
+
+
+    public static ByteBuffer bytebuffer( String s ) {
+        return ByteBuffer.wrap( bytes( s ) );
+    }
+
+
+    /**
+     * @param s
+     * @return
+     */
+    public static byte[] ascii( String s ) {
+        if ( s == null ) {
+            return new byte[0];
+        }
+        return bytes( s, ASCII_ENCODING );
+    }
+
+
+    public ByteBuffer asciibuffer( String s ) {
+        return ByteBuffer.wrap( ascii( s ) );
+    }
+
+
+    /**
+     * @param s
+     * @param encoding
+     * @return
+     */
+    public static byte[] bytes( String s, String encoding ) {
+        try {
+            return s.getBytes( encoding );
+        }
+        catch ( UnsupportedEncodingException e ) {
+            // logger.log(Level.SEVERE, "UnsupportedEncodingException ", e);
+            throw new RuntimeException( e );
+        }
+    }
+
+
+    public static byte[] bytes( ByteBuffer bb ) {
+        byte[] b = new byte[bb.remaining()];
+        bb.duplicate().get( b );
+        return b;
+    }
+
+
+    public static ByteBuffer bytebuffer( String s, String encoding ) {
+        return ByteBuffer.wrap( bytes( s, encoding ) );
+    }
+
+
+    /**
+     * @param b
+     * @return
+     */
+    public static byte[] bytes( Boolean b ) {
+        byte[] bytes = new byte[1];
+        bytes[0] = b ? ( byte ) 1 : 0;
+        return bytes;
+    }
+
+
+    public static ByteBuffer bytebuffer( Boolean b ) {
+        return ByteBuffer.wrap( bytes( b ) );
+    }
+
+
+    /**
+     * @param val
+     * @return
+     */
+    public static byte[] bytes( Long val ) {
+        ByteBuffer buf = ByteBuffer.allocate( 8 );
+        buf.order( ByteOrder.BIG_ENDIAN );
+        buf.putLong( val );
+        return buf.array();
+    }
+
+
+    public static ByteBuffer bytebuffer( Long val ) {
+        ByteBuffer buf = ByteBuffer.allocate( 8 );
+        buf.order( ByteOrder.BIG_ENDIAN );
+        buf.putLong( val );
+        return ( ByteBuffer ) buf.rewind();
+    }
+
+
+    /**
+     * @param obj
+     * @return
+     */
+    public static byte[] bytes( Object obj ) {
+        if ( obj == null ) {
+            return new byte[0];
+        }
+        else if ( obj instanceof byte[] ) {
+            return ( byte[] ) obj;
+        }
+        else if ( obj instanceof Long ) {
+            return bytes( ( Long ) obj );
+        }
+        else if ( obj instanceof String ) {
+            return bytes( ( String ) obj );
+        }
+        else if ( obj instanceof UUID ) {
+            return bytes( ( UUID ) obj );
+        }
+        else if ( obj instanceof Boolean ) {
+            return bytes( ( Boolean ) obj );
+        }
+        else if ( obj instanceof Date ) {
+            return bytes( ( ( Date ) obj ).getTime() );
+        }
+        else {
+            return bytes( obj.toString() );
+        }
+    }
+
+
+    public static ByteBuffer bytebuffer( byte[] bytes ) {
+        return ByteBuffer.wrap( bytes );
+    }
+
+
+    public static ByteBuffer bytebuffer( ByteBuffer bytes ) {
+        return bytes.duplicate();
+    }
+
+
+    public static ByteBuffer bytebuffer( Object obj ) {
+        if ( obj instanceof ByteBuffer ) {
+            return ( ( ByteBuffer ) obj ).duplicate();
+        }
+        return ByteBuffer.wrap( bytes( obj ) );
+    }
+
+
+    public static List<ByteBuffer> bytebuffers( List<?> l ) {
+        List<ByteBuffer> results = new ArrayList<ByteBuffer>( l.size() );
+        for ( Object o : l ) {
+            results.add( bytebuffer( o ) );
+        }
+        return results;
+    }
+
+
+    /**
+     * @param bytes
+     * @return
+     */
+    public static boolean getBoolean( byte[] bytes ) {
+        return bytes[0] != 0;
+    }
+
+
+    public static boolean getBoolean( ByteBuffer bytes ) {
+        return bytes.slice().get() != 0;
+    }
+
+
+    /**
+     * @param bytes
+     * @param offset
+     * @return
+     */
+    public static boolean getBoolean( byte[] bytes, int offset ) {
+        return bytes[offset] != 0;
+    }
+
+
+    public static boolean getBoolean( Object obj ) {
+        if ( obj instanceof Boolean ) {
+            return ( Boolean ) obj;
+        }
+        else if ( obj instanceof String ) {
+            return Boolean.parseBoolean( ( String ) obj );
+        }
+        else if ( obj instanceof Number ) {
+            return ( ( Number ) obj ).longValue() > 0;
+        }
+
+        return false;
+    }
+
+
+    /**
+     * @param obj
+     * @return
+     */
+    public static String string( Object obj ) {
+        if ( obj instanceof String ) {
+            return ( String ) obj;
+        }
+        else if ( obj instanceof byte[] ) {
+            return string( ( byte[] ) obj );
+        }
+        else if ( obj instanceof ByteBuffer ) {
+            return string( ( ByteBuffer ) obj );
+        }
+        else if ( obj != null ) {
+            return obj.toString();
+        }
+        return null;
+    }
+
+
+    /**
+     * @param bytes
+     * @return
+     */
+    public static String string( byte[] bytes ) {
+        if ( bytes == null ) {
+            return null;
+        }
+        return string( bytes, 0, bytes.length, UTF8_ENCODING );
+    }
+
+
+    public static String string( ByteBuffer bytes ) {
+        if ( bytes == null ) {
+            return null;
+        }
+        return string( bytes.array(), bytes.arrayOffset() + bytes.position(), bytes.remaining(), UTF8_ENCODING );
+    }
+
+
+    /**
+     * @param bytes
+     * @param offset
+     * @param length
+     * @return
+     */
+    public static String string( byte[] bytes, int offset, int length ) {
+        return string( bytes, offset, length, UTF8_ENCODING );
+    }
+
+
+    /**
+     * @param bytes
+     * @param offset
+     * @param length
+     * @param encoding
+     * @return
+     */
+    public static String string( byte[] bytes, int offset, int length, String encoding ) {
+
+        if ( length <= 0 ) {
+            return "";
+        }
+
+        if ( bytes == null ) {
+            return "";
+        }
+
+        try {
+            return new String( bytes, offset, length, encoding );
+        }
+        catch ( UnsupportedEncodingException e ) {
+            // logger.log(Level.SEVERE, "UnsupportedEncodingException ", e);
+            throw new RuntimeException( e );
+        }
+    }
+
+
+    public static <T> List<String> strings( Collection<T> items ) {
+        List<String> strings = new ArrayList<String>();
+        for ( T item : items ) {
+            strings.add( string( item ) );
+        }
+        return strings;
+    }
+
+
+    /**
+     * @param bytes
+     * @param offset
+     * @return
+     */
+    public static String stringFromLong( byte[] bytes, int offset ) {
+        if ( bytes.length == 0 ) {
+            return "";
+        }
+        if ( ( bytes.length - offset ) < 8 ) {
+            throw new IllegalArgumentException( "A long is at least 8 bytes" );
+        }
+        return String.valueOf( ByteBuffer.wrap( bytes, offset, 8 ).getLong() );
+    }
+
+
+    /**
+     * @param bytes
+     * @return
+     */
+    public static long getLong( byte[] bytes ) {
+        return ByteBuffer.wrap( bytes, 0, 8 ).getLong();
+    }
+
+
+    public static long getLong( ByteBuffer bytes ) {
+        return bytes.slice().getLong();
+    }
+
+
+    public static long getLong( Object obj ) {
+        if ( obj instanceof Long ) {
+            return ( Long ) obj;
+        }
+        if ( obj instanceof Number ) {
+            return ( ( Number ) obj ).longValue();
+        }
+        if ( obj instanceof String ) {
+            return NumberUtils.toLong( ( String ) obj );
+        }
+        if ( obj instanceof Date ) {
+            return ( ( Date ) obj ).getTime();
+        }
+        if ( obj instanceof byte[] ) {
+            return getLong( ( byte[] ) obj );
+        }
+        if ( obj instanceof ByteBuffer ) {
+            return getLong( ( ByteBuffer ) obj );
+        }
+        return 0;
+    }
+
+
+    /**
+     * @param bytes
+     * @return
+     */
+    public static int getInt( byte[] bytes ) {
+        return ByteBuffer.wrap( bytes, 0, 4 ).getInt();
+    }
+
+
+    public static int getInt( ByteBuffer bytes ) {
+        return bytes.slice().getInt();
+    }
+
+
+    public static int getInt( Object obj ) {
+        if ( obj instanceof Integer ) {
+            return ( Integer ) obj;
+        }
+        if ( obj instanceof Number ) {
+            return ( ( Number ) obj ).intValue();
+        }
+        if ( obj instanceof String ) {
+            return NumberUtils.toInt( ( String ) obj );
+        }
+        if ( obj instanceof Date ) {
+            return ( int ) ( ( Date ) obj ).getTime();
+        }
+        if ( obj instanceof byte[] ) {
+            return getInt( ( byte[] ) obj );
+        }
+        if ( obj instanceof ByteBuffer ) {
+            return getInt( ( ByteBuffer ) obj );
+        }
+        return 0;
+    }
+
+
+    /**
+     * @param bytes
+     * @return
+     */
+    public static float getFloat( byte[] bytes ) {
+        return ByteBuffer.wrap( bytes, 0, 4 ).getFloat();
+    }
+
+
+    public static float getFloat( ByteBuffer bytes ) {
+        return bytes.slice().getFloat();
+    }
+
+
+    public static float getFloat( Object obj ) {
+        if ( obj instanceof Float ) {
+            return ( Float ) obj;
+        }
+        if ( obj instanceof Number ) {
+            return ( ( Number ) obj ).floatValue();
+        }
+        if ( obj instanceof String ) {
+            return NumberUtils.toFloat( ( String ) obj );
+        }
+        if ( obj instanceof Date ) {
+            return ( ( Date ) obj ).getTime();
+        }
+        if ( obj instanceof byte[] ) {
+            return getFloat( ( byte[] ) obj );
+        }
+        if ( obj instanceof ByteBuffer ) {
+            return getFloat( ( ByteBuffer ) obj );
+        }
+        return 0;
+    }
+
+
+    public static double getDouble( byte[] bytes ) {
+        return ByteBuffer.wrap( bytes, 0, 8 ).getDouble();
+    }
+
+
+    public static double getDouble( ByteBuffer bytes ) {
+        return bytes.slice().getDouble();
+    }
+
+
+    public static double getDouble( Object obj ) {
+        if ( obj instanceof Double ) {
+            return ( Double ) obj;
+        }
+        if ( obj instanceof Number ) {
+            return ( ( Number ) obj ).doubleValue();
+        }
+        if ( obj instanceof String ) {
+            return NumberUtils.toDouble( ( String ) obj );
+        }
+        if ( obj instanceof Date ) {
+            return ( ( Date ) obj ).getTime();
+        }
+        if ( obj instanceof byte[] ) {
+            return getDouble( ( byte[] ) obj );
+        }
+        if ( obj instanceof ByteBuffer ) {
+            return getDouble( ( ByteBuffer ) obj );
+        }
+        return 0;
+    }
+
+
+    /**
+     * @param type
+     * @param bytes
+     * @return
+     */
+    public static Object object( Class<?> type, byte[] bytes ) {
+
+        try {
+            if ( Long.class.isAssignableFrom( type ) ) {
+                return getLong( bytes );
+            }
+            else if ( UUID.class.isAssignableFrom( type ) ) {
+                return uuid( bytes );
+            }
+            else if ( String.class.isAssignableFrom( type ) ) {
+                return string( bytes );
+            }
+            else if ( Boolean.class.isAssignableFrom( type ) ) {
+                return getBoolean( bytes );
+            }
+            else if ( Integer.class.isAssignableFrom( type ) ) {
+                return getInt( bytes );
+            }
+            else if ( Double.class.isAssignableFrom( type ) ) {
+                return getDouble( bytes );
+            }
+            else if ( Float.class.isAssignableFrom( type ) ) {
+                return getFloat( bytes );
+            }
+            else if ( byte[].class.isAssignableFrom( type ) ) {
+                return bytes;
+            }
+        }
+        catch ( Exception e ) {
+            logger.error( "Unable to get object from bytes for type " + type.getName(), e );
+        }
+        return null;
+    }
+
+
+    public static Object object( Class<?> type, ByteBuffer bytes ) {
+
+        try {
+            if ( Long.class.isAssignableFrom( type ) ) {
+                return bytes.slice().getLong();
+            }
+            else if ( UUID.class.isAssignableFrom( type ) ) {
+                return uuid( bytes );
+            }
+            else if ( String.class.isAssignableFrom( type ) ) {
+                return string( bytes );
+            }
+            else if ( Boolean.class.isAssignableFrom( type ) ) {
+                return bytes.slice().get() != 0;
+            }
+            else if ( Integer.class.isAssignableFrom( type ) ) {
+                return bytes.slice().getInt();
+            }
+            else if ( Double.class.isAssignableFrom( type ) ) {
+                return bytes.slice().getDouble();
+            }
+            else if ( Float.class.isAssignableFrom( type ) ) {
+                return bytes.slice().getFloat();
+            }
+            else if ( ByteBuffer.class.isAssignableFrom( type ) ) {
+                return bytes.duplicate();
+            }
+            else if ( byte[].class.isAssignableFrom( type ) ) {
+                byte[] b = new byte[bytes.remaining()];
+                bytes.slice().get( b );
+                return b;
+            }
+        }
+        catch ( Exception e ) {
+            logger.error( "Unable to get object from bytes for type " + type.getName(), e );
+        }
+        return null;
+    }
+
+
+    /**
+     * @param bb
+     * @param bytes
+     * @param len
+     * @return
+     */
+    public static ByteBuffer appendToByteBuffer( ByteBuffer bb, byte[] bytes, int len ) {
+        if ( len > bytes.length ) {
+            int pos = bb.position();
+            bb.put( bytes );
+            bb.position( pos + len );
+        }
+        else {
+            bb.put( bytes, 0, len );
+        }
+        return bb;
+    }
+
+
+    public static Object coerce( Class<?> type, Object obj ) {
+
+        if ( obj == null ) {
+            return null;
+        }
+
+        if ( type == null ) {
+            return obj;
+        }
+
+        try {
+            if ( Long.class.isAssignableFrom( type ) ) {
+                return getLong( obj );
+            }
+            else if ( UUID.class.isAssignableFrom( type ) ) {
+                return uuid( obj );
+            }
+            else if ( String.class.isAssignableFrom( type ) ) {
+                return string( obj );
+            }
+            else if ( Boolean.class.isAssignableFrom( type ) ) {
+                return getBoolean( obj );
+            }
+            else if ( Integer.class.isAssignableFrom( type ) ) {
+                return getInt( obj );
+            }
+            else if ( Double.class.isAssignableFrom( type ) ) {
+                return getDouble( obj );
+            }
+            else if ( Float.class.isAssignableFrom( type ) ) {
+                return getFloat( obj );
+            }
+            else if ( byte[].class.isAssignableFrom( type ) ) {
+                return bytes( obj );
+            }
+            else if ( ByteBuffer.class.isAssignableFrom( type ) ) {
+                return bytebuffer( obj );
+            }
+        }
+        catch ( Exception e ) {
+            logger.error( "Unable to get object from bytes for type " + type.getName(), e );
+        }
+        return null;
+    }
+
+
+    public static Map<String, Object> coerceMap( Map<String, Class<?>> types, Map<String, Object> values ) {
+        for ( Map.Entry<String, Object> entry : values.entrySet() ) {
+            if ( types.containsKey( entry.getKey() ) ) {
+                values.put( entry.getKey(), coerce( types.get( entry.getKey() ), entry.getValue() ) );
+            }
+        }
+        return values;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8f969d8d/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/EntityBuilder.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/EntityBuilder.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/EntityBuilder.java
new file mode 100644
index 0000000..6de9d39
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/EntityBuilder.java
@@ -0,0 +1,177 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF 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.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+
+package org.apache.usergrid.persistence.index.utils;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import org.apache.usergrid.persistence.model.entity.Entity;
+import org.apache.usergrid.persistence.model.field.BooleanField;
+import org.apache.usergrid.persistence.model.field.DoubleField;
+import org.apache.usergrid.persistence.model.field.EntityObjectField;
+import org.apache.usergrid.persistence.model.field.Field;
+import org.apache.usergrid.persistence.model.field.FloatField;
+import org.apache.usergrid.persistence.model.field.IntegerField;
+import org.apache.usergrid.persistence.model.field.ListField;
+import org.apache.usergrid.persistence.model.field.LocationField;
+import org.apache.usergrid.persistence.model.field.LongField;
+import org.apache.usergrid.persistence.model.field.StringField;
+import org.apache.usergrid.persistence.model.field.value.Location;
+
+
+public class EntityBuilder {
+
+    public static Entity fromMap( String scope, Map<String, Object> item ) {
+        return fromMap( scope, null, item );
+    }
+
+    public static Entity fromMap( String scope, Entity entity, Map<String, Object> map ) {
+
+        if ( entity == null ) {
+            entity = new Entity();
+        }
+
+        for ( String fieldName : map.keySet() ) {
+
+            Object value = map.get( fieldName );
+
+            if ( value instanceof String ) {
+                entity.setField( new StringField( fieldName, (String)value ));
+
+            } else if ( value instanceof Boolean ) {
+                entity.setField( new BooleanField( fieldName, (Boolean)value ));
+                        
+            } else if ( value instanceof Integer ) {
+                entity.setField( new IntegerField( fieldName, (Integer)value ));
+
+            } else if ( value instanceof Double ) {
+                entity.setField( new DoubleField( fieldName, (Double)value ));
+
+		    } else if ( value instanceof Float ) {
+                entity.setField( new FloatField( fieldName, (Float)value ));
+				
+            } else if ( value instanceof Long ) {
+                entity.setField( new LongField( fieldName, (Long)value ));
+
+            } else if ( value instanceof List) {
+                entity.setField( listToListField( scope, fieldName, (List)value ));
+
+            } else if ( value instanceof Map ) {
+
+				Field field = null;
+
+				// is the map really a location element?
+				Map<String, Object> m = (Map<String, Object>)value;
+				if ( m.size() == 2) {
+					Double lat = null;
+					Double lon = null;
+					try {
+						if ( m.get("latitude") != null && m.get("longitude") != null ) {
+							lat = Double.parseDouble( m.get("latitude").toString() );
+							lon = Double.parseDouble( m.get("longitude").toString() );
+
+						} else if ( m.get("lat") != null && m.get("lon") != null ) { 
+							lat = Double.parseDouble( m.get("lat").toString() );
+							lon = Double.parseDouble( m.get("lon").toString() );
+						}
+					} catch ( NumberFormatException ignored ) {}
+
+					if ( lat != null && lon != null ) {
+						field = new LocationField( fieldName, new Location( lat, lon ));
+					}
+				}
+
+				if ( field == null ) { 
+
+					// not a location element, process it as map
+					entity.setField( new EntityObjectField( fieldName, 
+						fromMap( scope, (Map<String, Object>)value ))); // recursion
+
+				} else {
+					entity.setField( field );
+				}
+	
+			} else {
+                throw new RuntimeException("Unknown type " + value.getClass().getName());
+            }
+        }
+
+        return entity;
+    }
+
+    
+    private static ListField listToListField( String scope, String fieldName, List list ) {
+
+        if (list.isEmpty()) {
+            return new ListField( fieldName );
+        }
+
+        Object sample = list.get(0);
+
+        if ( sample instanceof Map ) {
+            return new ListField<Entity>( fieldName, processListForField( scope, list ));
+
+        } else if ( sample instanceof List ) {
+            return new ListField<List>( fieldName, processListForField( scope, list ));
+            
+        } else if ( sample instanceof String ) {
+            return new ListField<String>( fieldName, (List<String>)list );
+                    
+        } else if ( sample instanceof Boolean ) {
+            return new ListField<Boolean>( fieldName, (List<Boolean>)list );
+                    
+        } else if ( sample instanceof Integer ) {
+            return new ListField<Integer>( fieldName, (List<Integer>)list );
+
+        } else if ( sample instanceof Double ) {
+            return new ListField<Double>( fieldName, (List<Double>)list );
+
+        } else if ( sample instanceof Long ) {
+            return new ListField<Long>( fieldName, (List<Long>)list );
+
+        } else {
+            throw new RuntimeException("Unknown type " + sample.getClass().getName());
+        }
+    }
+
+    
+    private static List processListForField( String scope, List list ) {
+        if ( list.isEmpty() ) {
+            return list;
+        }
+        Object sample = list.get(0);
+
+        if ( sample instanceof Map ) {
+            List<Entity> newList = new ArrayList<Entity>();
+            for ( Map<String, Object> map : (List<Map<String, Object>>)list ) {
+                newList.add( fromMap( scope, map ) );
+            }
+            return newList;
+
+        } else if ( sample instanceof List ) {
+            return processListForField( scope, list ); // recursion
+            
+        } else { 
+            return list;
+        } 
+    }
+
+
+}