usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdun...@apache.org
Subject [23/44] usergrid git commit: change parsing logic to parse uuid as string
Date Sat, 26 Sep 2015 01:42:28 GMT
change parsing logic to parse uuid as string


Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/e2fe9398
Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/e2fe9398
Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/e2fe9398

Branch: refs/heads/USERGRID-933
Commit: e2fe93981ea11d78906eafbecd26f912e3dd6703
Parents: 723ee3a
Author: Shawn Feldman <sfeldman@apache.org>
Authored: Tue Sep 15 18:18:21 2015 -0600
Committer: Shawn Feldman <sfeldman@apache.org>
Committed: Tue Sep 15 18:18:21 2015 -0600

----------------------------------------------------------------------
 .../index/impl/EntityMappingParser.java         |  2 +-
 .../persistence/index/impl/EsQueryVistor.java   | 52 ++++++++++----------
 .../persistence/index/impl/EntityIndexTest.java | 12 ++++-
 3 files changed, 38 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/e2fe9398/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EntityMappingParser.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EntityMappingParser.java
b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EntityMappingParser.java
index bfefaa9..e328d29 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EntityMappingParser.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EntityMappingParser.java
@@ -72,7 +72,7 @@ public class EntityMappingParser implements FieldParser {
      * Visit al the primitive values
      */
     private void visit( final UUID value ) {
-        fields.add( EntityField.create( fieldStack.peek(), value ) );
+       visit(value.toString());
     }
 
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/e2fe9398/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsQueryVistor.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsQueryVistor.java
b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsQueryVistor.java
index 7b66c0d..af60ed6 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsQueryVistor.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsQueryVistor.java
@@ -107,7 +107,7 @@ public class EsQueryVistor implements QueryVisitor {
          * We use a left and a right, add our boolean query
          */
         if ( useLeftQuery && useRightQuery ) {
-            final BoolQueryBuilder qb = QueryBuilders.boolQuery().must( leftQuery ).must(
rightQuery );
+            final BoolQueryBuilder qb = QueryBuilders.boolQuery().must(leftQuery).must(rightQuery);
             queryBuilders.push( qb );
         }
         //only use the left
@@ -131,7 +131,7 @@ public class EsQueryVistor implements QueryVisitor {
 
         //use left and right
         if ( useLeftFilter && useRightFilter ) {
-            final BoolFilterBuilder fb = FilterBuilders.boolFilter().must( leftFilter ).must(
rightFilter );
+            final BoolFilterBuilder fb = FilterBuilders.boolFilter().must(leftFilter).must(rightFilter);
             filterBuilders.push( fb );
         }
 
@@ -166,13 +166,13 @@ public class EsQueryVistor implements QueryVisitor {
 
 
         final boolean useLeftQuery = use( leftQuery );
-        final boolean useRightQuery = use( rightQuery );
+        final boolean useRightQuery = use(rightQuery);
 
         //push our boolean filters
         if ( useLeftQuery && useRightQuery ) {
             //when we issue an OR query in usergrid, 1 or more of the terms should match.
 When doing bool query in ES, there is no requirement for more than 1 to match, where as in
a filter more than 1 must match
-            final BoolQueryBuilder qb = QueryBuilders.boolQuery().should( leftQuery ).should(
rightQuery ).minimumNumberShouldMatch(
-                1 );
+            final BoolQueryBuilder qb = QueryBuilders.boolQuery().should( leftQuery ).should(rightQuery).minimumNumberShouldMatch(
+                1);
             queryBuilders.push( qb );
         }
         else if ( useLeftQuery ) {
@@ -189,7 +189,7 @@ public class EsQueryVistor implements QueryVisitor {
 
 
         final boolean useLeftFilter = use( leftFilter );
-        final boolean useRightFilter = use( rightFilter );
+        final boolean useRightFilter = use(rightFilter);
 
         //use left and right
         if ( useLeftFilter && useRightFilter ) {
@@ -225,7 +225,7 @@ public class EsQueryVistor implements QueryVisitor {
         final QueryBuilder notQueryBuilder = queryBuilders.pop();
 
         if ( use( notQueryBuilder ) ) {
-            final QueryBuilder notQuery = QueryBuilders.boolQuery().mustNot( notQueryBuilder
);
+            final QueryBuilder notQuery = QueryBuilders.boolQuery().mustNot(notQueryBuilder);
             queryBuilders.push( notQuery  );
         }
         else {
@@ -307,14 +307,14 @@ public class EsQueryVistor implements QueryVisitor {
 
         final GeoDistanceSortBuilder geoSort =
                 SortBuilders.geoDistanceSort( IndexingUtils.FIELD_LOCATION_NESTED ).unit(
DistanceUnit.METERS )
-                            .geoDistance( GeoDistance.SLOPPY_ARC ).point( lat, lon );
+                            .geoDistance(GeoDistance.SLOPPY_ARC).point(lat, lon);
 
-        final TermFilterBuilder sortPropertyName = sortPropertyTermFilter( name );
+        final TermFilterBuilder sortPropertyName = sortPropertyTermFilter(name);
 
         geoSort.setNestedFilter( sortPropertyName );
 
 
-        geoSortFields.addField( name, geoSort );
+        geoSortFields.addField(name, geoSort);
         //no op for query, push
 
 
@@ -329,7 +329,7 @@ public class EsQueryVistor implements QueryVisitor {
 
 
         final RangeFilterBuilder termQuery =
-                FilterBuilders.rangeFilter( getFieldNameForType( value ) ).lt( sanitize(
value ) );
+                FilterBuilders.rangeFilter( getFieldNameForType( value ) ).lt(sanitize(value));
 
 
         queryBuilders.push( NoOpQueryBuilder.INSTANCE );
@@ -347,7 +347,7 @@ public class EsQueryVistor implements QueryVisitor {
 
 
         final RangeFilterBuilder termQuery =
-                FilterBuilders.rangeFilter( getFieldNameForType( value ) ).lte( sanitize(
value ) );
+                FilterBuilders.rangeFilter( getFieldNameForType( value ) ).lte(sanitize(value));
 
 
         queryBuilders.push( NoOpQueryBuilder.INSTANCE );
@@ -362,8 +362,8 @@ public class EsQueryVistor implements QueryVisitor {
         final Object value = op.getLiteral().getValue();
 
         //special case so we support our '*' char with wildcard
-        if ( value instanceof String ) {
-            final String stringValue = (( String ) value).toLowerCase().trim();
+        if ( value instanceof String || value instanceof UUID ) {
+            final String stringValue = (value.toString()).toLowerCase().trim();
 
             // or field is just a string that does need a prefix us a query
             if ( stringValue.contains( "*" ) ) {
@@ -390,7 +390,7 @@ public class EsQueryVistor implements QueryVisitor {
         // assume all other types need prefix
 
         final TermFilterBuilder termQuery =
-                FilterBuilders.termFilter( getFieldNameForType( value ), sanitize( value
) );
+                FilterBuilders.termFilter(getFieldNameForType(value), sanitize(value));
 
         filterBuilders.push( fieldNameTerm( name, termQuery ) );
 
@@ -405,7 +405,7 @@ public class EsQueryVistor implements QueryVisitor {
 
 
         final RangeFilterBuilder rangeQuery =
-                FilterBuilders.rangeFilter( getFieldNameForType( value ) ).gt( sanitize(
value ) );
+                FilterBuilders.rangeFilter( getFieldNameForType( value ) ).gt(sanitize(value));
 
         filterBuilders.push( fieldNameTerm( name, rangeQuery ) );
 
@@ -420,9 +420,9 @@ public class EsQueryVistor implements QueryVisitor {
 
 
         final RangeFilterBuilder rangeQuery =
-                FilterBuilders.rangeFilter( getFieldNameForType( value ) ).gte( sanitize(
value ) );
+                FilterBuilders.rangeFilter( getFieldNameForType( value ) ).gte(sanitize(value));
 
-        filterBuilders.push( fieldNameTerm( name, rangeQuery ) );
+        filterBuilders.push(fieldNameTerm(name, rangeQuery));
 
         queryBuilders.push( NoOpQueryBuilder.INSTANCE );
     }
@@ -474,12 +474,12 @@ public class EsQueryVistor implements QueryVisitor {
 
         final BoolQueryBuilder booleanQuery = QueryBuilders.boolQuery();
 
-        booleanQuery.must( QueryBuilders.termQuery( IndexingUtils.FIELD_NAME_NESTED, fieldName
) );
+        booleanQuery.must( QueryBuilders.termQuery(IndexingUtils.FIELD_NAME_NESTED, fieldName)
);
 
         booleanQuery.must( fieldValueQuery );
 
 
-        return QueryBuilders.nestedQuery( IndexingUtils.ENTITY_FIELDS, booleanQuery );
+        return QueryBuilders.nestedQuery(IndexingUtils.ENTITY_FIELDS, booleanQuery);
     }
 
 
@@ -503,7 +503,11 @@ public class EsQueryVistor implements QueryVisitor {
      * Get the field name for the primitive type
      */
     private String getFieldNameForType( final Object object ) {
-        if ( object instanceof String ) {
+        if ( object instanceof String) {
+            return IndexingUtils.FIELD_STRING_NESTED;
+        }
+
+        if(object instanceof UUID){
             return IndexingUtils.FIELD_STRING_NESTED;
         }
 
@@ -521,10 +525,6 @@ public class EsQueryVistor implements QueryVisitor {
         }
 
 
-        if ( object instanceof UUID ) {
-            return IndexingUtils.FIELD_UUID_NESTED;
-        }
-
 
         throw new UnsupportedOperationException(
                 "Unkown search type of " + object.getClass().getName() + " encountered" );
@@ -540,7 +540,7 @@ public class EsQueryVistor implements QueryVisitor {
         }
 
         if ( input instanceof UUID ) {
-            return input.toString();
+            return  input.toString() ;
         }
 
         return input;

http://git-wip-us.apache.org/repos/asf/usergrid/blob/e2fe9398/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java
b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java
index 34256ca..7aa97b1 100644
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java
@@ -127,11 +127,13 @@ public class EntityIndexTest extends BaseIT {
         EntityIndexBatch batch = entityIndex.createBatch();
 
 
+        UUID uuid = UUID.randomUUID();
         Entity entity1 = new Entity( entityType );
         EntityUtils.setVersion(entity1, UUIDGenerator.newTimeUUID());
-        entity1.setField( new UUIDField( IndexingUtils.ENTITY_ID_FIELDNAME, UUID.randomUUID()
) );
+        entity1.setField(new UUIDField(IndexingUtils.ENTITY_ID_FIELDNAME, UUID.randomUUID()));
         entity1.setField( new StringField( "testfield", "test" ) );
         entity1.setField(new IntegerField("ordinal", 0));
+        entity1.setField(new UUIDField("testuuid",uuid));
 
 
         batch.index( indexEdge, entity1 );
@@ -176,6 +178,14 @@ public class EntityIndexTest extends BaseIT {
         //check the id and version
         assertEquals( entity2.getId(), candidate2.getId() );
         assertEquals( entity2.getVersion(), candidate2.getVersion() );
+
+        candidateResults =
+            entityIndex.search( indexEdge, searchTypes, "select * where testuuid = '"+uuid+"'",
100, 0 );
+        assertEquals(entity1.getId(),candidateResults.get(0).getId());
+
+        candidateResults =
+            entityIndex.search( indexEdge, searchTypes, "select * where testuuid = "+uuid,
100, 0 );
+        assertEquals(entity1.getId(),candidateResults.get(0).getId());
     }
 
 


Mime
View raw message