You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by to...@apache.org on 2015/04/10 18:28:04 UTC
[3/5] incubator-usergrid git commit: Removed legacy 1.0 code Cleaned
up Query object to only be query state/builder Refactor of tests to use query
language
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e534d9c7/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/ElasticSearchQueryExecutor.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/ElasticSearchQueryExecutor.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/ElasticSearchQueryExecutor.java
index ae2e350..aa4f743 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/ElasticSearchQueryExecutor.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/ElasticSearchQueryExecutor.java
@@ -26,14 +26,13 @@ import java.util.NoSuchElementException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.apache.usergrid.persistence.Query;
import org.apache.usergrid.persistence.Results;
import org.apache.usergrid.persistence.core.scope.ApplicationScope;
import org.apache.usergrid.persistence.index.ApplicationEntityIndex;
-import org.apache.usergrid.persistence.index.EntityIndex;
-import org.apache.usergrid.persistence.index.IndexScope;
+import org.apache.usergrid.persistence.index.CandidateResults;
+import org.apache.usergrid.persistence.index.SearchEdge;
import org.apache.usergrid.persistence.index.SearchTypes;
-import org.apache.usergrid.persistence.index.query.CandidateResults;
-import org.apache.usergrid.persistence.Query;
public class ElasticSearchQueryExecutor implements QueryExecutor {
@@ -46,7 +45,7 @@ public class ElasticSearchQueryExecutor implements QueryExecutor {
private final ApplicationEntityIndex entityIndex;
- private final IndexScope indexScope;
+ private final SearchEdge indexScope;
private final SearchTypes types;
@@ -59,7 +58,7 @@ public class ElasticSearchQueryExecutor implements QueryExecutor {
public ElasticSearchQueryExecutor( final ResultsLoaderFactory resultsLoaderFactory, final ApplicationEntityIndex entityIndex,
- final ApplicationScope applicationScope, final IndexScope indexScope,
+ final ApplicationScope applicationScope, final SearchEdge indexScope,
final SearchTypes types, final Query query ) {
this.resultsLoaderFactory = resultsLoaderFactory;
this.applicationScope = applicationScope;
@@ -90,42 +89,38 @@ public class ElasticSearchQueryExecutor implements QueryExecutor {
Results results = null;
int queryCount = 0;
- boolean satisfied = false;
+ CandidateResults crs = null;
- while ( !satisfied && queryCount++ < maxQueries ) {
+ while ( queryCount++ < maxQueries ) {
- CandidateResults crs = entityIndex.search( indexScope, types, query );
+ crs = entityIndex.search( indexScope, types, query.getQl(), query.getLimit() );
logger.debug( "Calling build results 1" );
results = buildResults( indexScope, query, crs );
- if ( crs.isEmpty() || !crs.hasCursor() ) { // no results, no cursor, can't get more
- satisfied = true;
- }
-
/**
* In an edge case where we delete stale entities, we could potentially get less results than expected.
* This will only occur once during the repair phase.
* We need to ensure that we short circuit before we overflow the requested limit during a repair.
*/
- else if ( results.size() > 0 ) { // got what we need
- satisfied = true;
+ if ( crs.isEmpty() || !crs.hasCursor() || results.size() > 0 ) { // no results, no cursor, can't get more
+ break;
}
+
+
//we didn't load anything, but there was a cursor, this means a read repair occured. We have to short
//circuit to avoid over returning the result set
- else if ( crs.hasCursor() ) {
- satisfied = false;
- // need to query for more
- // ask for just what we need to satisfy, don't want to exceed limit
- query.setCursor( results.getCursor() );
- query.setLimit( originalLimit - results.size() );
- logger.warn( "Satisfy query limit {}, new limit {} query count {}", new Object[] {
- originalLimit, query.getLimit(), queryCount
- } );
- }
+ // need to query for more
+ // ask for just what we need to satisfy, don't want to exceed limit
+ query.setCursor( results.getCursor() );
+ query.setLimit( originalLimit - results.size() );
+
+ logger.warn( "Satisfy query limit {}, new limit {} query count {}", new Object[] {
+ originalLimit, query.getLimit(), queryCount
+ } );
}
//now set our cursor if we have one for the next iteration
@@ -139,6 +134,12 @@ public class ElasticSearchQueryExecutor implements QueryExecutor {
}
+ //set our select subjects into our query if provided
+ if(crs != null){
+ query.setSelectSubjects( crs.getGetFieldMappings() );
+ }
+
+
//set our current results and the flag
this.currentResults = results;
}
@@ -150,7 +151,7 @@ public class ElasticSearchQueryExecutor implements QueryExecutor {
* @param query Query that was executed
* @param crs Candidates to be considered for results
*/
- private Results buildResults( final IndexScope indexScope, final Query query, final CandidateResults crs ) {
+ private Results buildResults( final SearchEdge indexScope, final Query query, final CandidateResults crs ) {
logger.debug( "buildResults() from {} candidates", crs.size() );
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e534d9c7/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/EntityVerifier.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/EntityVerifier.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/EntityVerifier.java
index 075abc4..a2dd5e0 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/EntityVerifier.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/EntityVerifier.java
@@ -38,7 +38,7 @@ import org.apache.usergrid.persistence.Results;
import org.apache.usergrid.persistence.collection.EntityCollectionManager;
import org.apache.usergrid.persistence.collection.EntitySet;
import org.apache.usergrid.persistence.collection.MvccEntity;
-import org.apache.usergrid.persistence.index.query.CandidateResult;
+import org.apache.usergrid.persistence.index.CandidateResult;
import org.apache.usergrid.persistence.model.entity.Id;
import com.fasterxml.uuid.UUIDComparator;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e534d9c7/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/FilteringLoader.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/FilteringLoader.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/FilteringLoader.java
index c12bb2c..a48e1b8 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/FilteringLoader.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/FilteringLoader.java
@@ -38,9 +38,9 @@ import org.apache.usergrid.persistence.collection.EntityCollectionManager;
import org.apache.usergrid.persistence.core.scope.ApplicationScope;
import org.apache.usergrid.persistence.index.ApplicationEntityIndex;
import org.apache.usergrid.persistence.index.EntityIndexBatch;
-import org.apache.usergrid.persistence.index.IndexScope;
-import org.apache.usergrid.persistence.index.query.CandidateResult;
-import org.apache.usergrid.persistence.index.query.CandidateResults;
+import org.apache.usergrid.persistence.index.SearchEdge;
+import org.apache.usergrid.persistence.index.CandidateResult;
+import org.apache.usergrid.persistence.index.CandidateResults;
import org.apache.usergrid.persistence.model.entity.Id;
import com.fasterxml.uuid.UUIDComparator;
@@ -55,7 +55,7 @@ public class FilteringLoader implements ResultsLoader {
private final ManagerCache managerCache;
private final ResultsVerifier resultsVerifier;
private final ApplicationScope applicationScope;
- private final IndexScope indexScope;
+ private final SearchEdge indexScope;
private final EntityIndexBatch indexBatch;
@@ -68,7 +68,7 @@ public class FilteringLoader implements ResultsLoader {
* @param indexScope The index scope used in the search
*/
protected FilteringLoader( final ManagerCache managerCache, final ResultsVerifier resultsVerifier,
- final ApplicationScope applicationScope, final IndexScope indexScope ) {
+ final ApplicationScope applicationScope, final SearchEdge indexScope ) {
this.managerCache = managerCache;
this.resultsVerifier = resultsVerifier;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e534d9c7/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/ResultsLoader.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/ResultsLoader.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/ResultsLoader.java
index 28df6b6..e8a7bdf 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/ResultsLoader.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/ResultsLoader.java
@@ -21,7 +21,7 @@ package org.apache.usergrid.corepersistence.results;
import org.apache.usergrid.persistence.Results;
-import org.apache.usergrid.persistence.index.query.CandidateResults;
+import org.apache.usergrid.persistence.index.CandidateResults;
/**
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e534d9c7/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/ResultsLoaderFactory.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/ResultsLoaderFactory.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/ResultsLoaderFactory.java
index 12589e2..3399a35 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/ResultsLoaderFactory.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/ResultsLoaderFactory.java
@@ -20,10 +20,9 @@
package org.apache.usergrid.corepersistence.results;
-import org.apache.usergrid.persistence.EntityRef;
-import org.apache.usergrid.persistence.core.scope.ApplicationScope;
-import org.apache.usergrid.persistence.index.IndexScope;
import org.apache.usergrid.persistence.Query;
+import org.apache.usergrid.persistence.core.scope.ApplicationScope;
+import org.apache.usergrid.persistence.index.SearchEdge;
/**
@@ -37,6 +36,6 @@ public interface ResultsLoaderFactory {
* @param indexScope The index scope used in the search
* @param
*/
- ResultsLoader getLoader( final ApplicationScope applicationScope, final IndexScope indexScope,
+ ResultsLoader getLoader( final ApplicationScope applicationScope, final SearchEdge indexScope,
final Query.Level resultsLevel );
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e534d9c7/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/ResultsVerifier.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/ResultsVerifier.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/ResultsVerifier.java
index 1b92bcc..46e0983 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/ResultsVerifier.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/ResultsVerifier.java
@@ -23,7 +23,7 @@ package org.apache.usergrid.corepersistence.results;
import java.util.Collection;
import org.apache.usergrid.persistence.Results;
import org.apache.usergrid.persistence.collection.EntityCollectionManager;
-import org.apache.usergrid.persistence.index.query.CandidateResult;
+import org.apache.usergrid.persistence.index.CandidateResult;
import org.apache.usergrid.persistence.model.entity.Id;
@@ -37,7 +37,7 @@ public interface ResultsVerifier {
public void loadResults(Collection<Id> ids, EntityCollectionManager ecm);
/**
- * Return true if the candidate result is a valid result that should be retained. If it should
+ * Return true if the candidate result is a valid result that should be retained. If it should
* not it should also be removed from the list of possible return values in this loader
* @param candidateResult
*/
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e534d9c7/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/VersionVerifier.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/VersionVerifier.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/VersionVerifier.java
index c541550..574ba55 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/VersionVerifier.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/VersionVerifier.java
@@ -29,7 +29,7 @@ import org.slf4j.LoggerFactory;
import org.apache.usergrid.persistence.collection.EntityCollectionManager;
import org.apache.usergrid.persistence.collection.MvccLogEntry;
import org.apache.usergrid.persistence.collection.VersionSet;
-import org.apache.usergrid.persistence.index.query.CandidateResult;
+import org.apache.usergrid.persistence.index.CandidateResult;
import org.apache.usergrid.persistence.model.entity.Id;
import com.fasterxml.uuid.UUIDComparator;
@@ -59,7 +59,7 @@ public abstract class VersionVerifier implements ResultsVerifier {
//version wasn't found ,deindex
if ( version == null ) {
- logger.warn( "Version for Entity {}:{} not found",
+ logger.warn( "Version for Entity {}:{} not found",
entityId.getUuid(), entityId.getUuid() );
return false;
@@ -69,10 +69,10 @@ public abstract class VersionVerifier implements ResultsVerifier {
if ( UUIDComparator.staticCompare( savedVersion, candidateResult.getVersion() ) > 0 ) {
logger.debug( "Stale version of Entity uuid:{} type:{}, stale v:{}, latest v:{}",
- new Object[] {
- entityId.getUuid(),
- entityId.getType(),
- candidateResult.getVersion(),
+ new Object[] {
+ entityId.getUuid(),
+ entityId.getType(),
+ candidateResult.getVersion(),
savedVersion
} );
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e534d9c7/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpNamingUtils.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpNamingUtils.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpNamingUtils.java
index 49929dc..0376780 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpNamingUtils.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpNamingUtils.java
@@ -22,19 +22,23 @@ package org.apache.usergrid.corepersistence.util;
import java.util.UUID;
import org.apache.usergrid.persistence.EntityRef;
-import org.apache.usergrid.persistence.Schema;
import org.apache.usergrid.persistence.core.scope.ApplicationScope;
import org.apache.usergrid.persistence.core.scope.ApplicationScopeImpl;
import org.apache.usergrid.persistence.entities.Application;
import org.apache.usergrid.persistence.graph.Edge;
-import org.apache.usergrid.persistence.index.IndexScope;
-import org.apache.usergrid.persistence.index.impl.IndexScopeImpl;
+import org.apache.usergrid.persistence.graph.SearchByEdge;
+import org.apache.usergrid.persistence.graph.SearchByEdgeType;
+import org.apache.usergrid.persistence.graph.impl.SimpleEdge;
+import org.apache.usergrid.persistence.graph.impl.SimpleSearchByEdge;
+import org.apache.usergrid.persistence.index.IndexEdge;
+import org.apache.usergrid.persistence.index.SearchEdge;
+import org.apache.usergrid.persistence.index.impl.IndexEdgeImpl;
+import org.apache.usergrid.persistence.index.impl.SearchEdgeImpl;
import org.apache.usergrid.persistence.map.MapScope;
import org.apache.usergrid.persistence.map.impl.MapScopeImpl;
import org.apache.usergrid.persistence.model.entity.Id;
import org.apache.usergrid.persistence.model.entity.SimpleId;
-
-import com.clearspring.analytics.util.Preconditions;
+import org.apache.usergrid.utils.UUIDUtils;
/**
@@ -49,12 +53,10 @@ public class CpNamingUtils {
public static final String EDGE_CONN_SUFFIX = "zzzconnzzz";
/** App where we store management info */
- public static final UUID MANAGEMENT_APPLICATION_ID =
- UUID.fromString("b6768a08-b5d5-11e3-a495-11ddb1de66c8");
+ public static final UUID MANAGEMENT_APPLICATION_ID = UUID.fromString( "b6768a08-b5d5-11e3-a495-11ddb1de66c8" );
/** Old and deprecated SYSTEM_APP */
- public static final UUID SYSTEM_APP_ID =
- UUID.fromString("b6768a08-b5d5-11e3-a495-10ddb1de66c3");
+ public static final UUID SYSTEM_APP_ID = UUID.fromString( "b6768a08-b5d5-11e3-a495-10ddb1de66c3" );
/**
* Information about applications is stored in the management app using these types
@@ -71,162 +73,140 @@ public class CpNamingUtils {
public static String TYPES_BY_UUID_MAP = "zzz_typesbyuuid_zzz";
-
-
/**
- * Get the collection name from the entity/id type
- * @param type
- * @return
+ * Create an Id object from the entity ref
*/
- private static String getCollectionScopeNameFromEntityType( String type ) {
- String csn = EDGE_COLL_SUFFIX + Schema.defaultCollectionName( type );
- return csn.toLowerCase();
+ public static Id createId( final EntityRef entityRef ) {
+ return new SimpleId( entityRef.getUuid(), entityRef.getType() );
}
- private static String getCollectionScopeNameFromCollectionName( String name ) {
- String csn = EDGE_COLL_SUFFIX + name;
- return csn.toLowerCase();
+ /**
+ * Generate a standard edge name for our graph using the connection name. To be used only for searching. DO NOT use
+ * for creation. Use the createConnectionEdge instead.
+ *
+ * @param connectionType The type of connection made
+ */
+ public static String getEdgeTypeFromConnectionType( String connectionType ) {
+ return ( EDGE_CONN_SUFFIX + "|" + connectionType ).toLowerCase();
}
- private static String getConnectionScopeName( String connectionType ) {
- String csn = EDGE_CONN_SUFFIX + connectionType ;
- return csn.toLowerCase();
+ /**
+ * Generate a standard edges from for a collection
+ *
+ * To be used only for searching DO NOT use for creation. Use the createCollectionEdge instead.
+ */
+ public static String getEdgeTypeFromCollectionName( String collectionName ) {
+ return ( EDGE_COLL_SUFFIX + "|" + collectionName ).toLowerCase();
}
/**
* Get the index scope for the edge from the source
- * @param edge
- * @return
*/
- public static IndexScope generateScopeFromSource(final Edge edge ){
-
-
- final Id nodeId = edge.getSourceNode();
- final String scopeName = getNameFromEdgeType( edge.getType() );
-
-
- return new IndexScopeImpl( nodeId, scopeName );
-
+ public static IndexEdge generateScopeFromSource( final Edge edge ) {
+ return new IndexEdgeImpl( edge.getSourceNode(), edge.getType(), SearchEdge.NodeType.SOURCE,
+ edge.getTimestamp() );
}
-
-
-
/**
* Get the index scope for the edge from the source
- * @param edge
- * @return
*/
- public static IndexScope generateScopeToTarget(final Edge edge ){
-
-
-
- final Id nodeId = edge.getTargetNode();
- final String scopeName = getNameFromEdgeType( edge.getType() );
-
+ public static IndexEdge generateScopeToTarget( final Edge edge ) {
+ return new IndexEdgeImpl( edge.getTargetNode(), edge.getType(), SearchEdge.NodeType.TARGET,
+ edge.getTimestamp() );
+ }
- return new IndexScopeImpl( nodeId, scopeName );
+ /**
+ * Create the search edge from the source
+ */
+ public static SearchEdge createSearchEdgeFromSource( final Edge edge ) {
+ return new SearchEdgeImpl( edge.getSourceNode(), edge.getType(), SearchEdge.NodeType.SOURCE );
}
/**
- * Generate either the collection name or connection name from the edgeName
- * @param edgeName
+ *
+ * @param sourceId
+ * @param collectionName
+ * @param entityId
* @return
*/
- public static String getNameFromEdgeType(final String edgeName){
+ public static Edge createCollectionEdge( final Id sourceId, final String collectionName, final Id entityId ) {
+ final String edgeType = CpNamingUtils.getEdgeTypeFromCollectionName( collectionName );
+ final UUID entityIdUUID = entityId.getUuid();
- if(isCollectionEdgeType( edgeName )){
- return getCollectionScopeNameFromCollectionName(getCollectionName(edgeName) );
- }
+ //if they don't use a time based uuid (such as in devices) we need to create a timestamp from "now" since
+ // this is when the entity
+ //will be added to the collection
+ final UUID timeStampUuid = UUIDUtils.isTimeBased( entityIdUUID ) ? entityIdUUID : UUIDUtils.newTimeUUID();
- return getConnectionScopeName(getConnectionType( edgeName ) );
+ long uuidTimestamp = UUIDUtils.getUUIDLong( timeStampUuid );
+ // create graph edge connection from head entity to member entity
+ return new SimpleEdge( sourceId, edgeType, entityId, uuidTimestamp );
}
/**
- * Get the index scope from the colleciton name
- * @param nodeId The source or target node id
- * @param collectionName The name of the collection. Ex "users"
- * @return
+ * Create a connection searchEdge
*/
- public static IndexScope generateScopeFromCollection( final Id nodeId, final String collectionName ){
- return new IndexScopeImpl( nodeId, getCollectionScopeNameFromCollectionName( collectionName ) );
+ public static SearchEdge createCollectionSearchEdge( final Id sourceId, final String connectionType ) {
+ return new SearchEdgeImpl( sourceId, getEdgeTypeFromCollectionName( connectionType ),
+ SearchEdge.NodeType.SOURCE );
}
/**
- * Get the scope from the connection
- * @param nodeId
- * @param connectionName
- * @return
+ * Create a new connection edge from the source node with the given connection type and target id
*/
- public static IndexScope generateScopeFromConnection( final Id nodeId, final String connectionName ){
- return new IndexScopeImpl( nodeId, getConnectionScopeName( connectionName ) );
+ public static Edge createConnectionEdge( final Id sourceEntityId, final String connectionType,
+ final Id targetEntityId ) {
+ final String edgeType = getEdgeTypeFromConnectionType( connectionType );
+
+ // create graph edge connection from head entity to member entity
+ return new SimpleEdge( sourceEntityId, edgeType, targetEntityId, System.currentTimeMillis() );
}
/**
- * Create an Id object from the entity ref
- * @param entityRef
- * @return
+ * Create a connection searchEdge
+ *
+ * @param sourceId The source id in the connection
+ * @param connectionType The type of the connection to create a search for
*/
- public static Id createId(final EntityRef entityRef){
- return new SimpleId( entityRef.getUuid(), entityRef.getType() );
- }
-
- private static boolean isCollectionEdgeType( String type ) {
- return type.startsWith( EDGE_COLL_SUFFIX );
- }
-
-
- private static boolean isConnectionEdgeType( String type ) {
- return type.startsWith( EDGE_CONN_SUFFIX );
- }
-
-
-
- private static String getConnectionType( String edgeType ) {
- String[] parts = edgeType.split( "\\|" );
- return parts[1];
- }
-
-
- private static String getCollectionName( String edgeType ) {
- String[] parts = edgeType.split( "\\|" );
- return parts[1];
+ public static SearchEdge createConnectionSearchEdge( final Id sourceId, final String connectionType ) {
+ return new SearchEdgeImpl( sourceId, getEdgeTypeFromConnectionType( connectionType ),
+ SearchEdge.NodeType.SOURCE );
}
/**
- * Generate a standard edge name for our graph using the connection name
- * @param connectionType The type of connection made
- * @return
+ * search for all versions of a connection between 2 entities in teh graph
+ *
+ * @param sourceId The source id of the edge
+ * @param connectionType The connection type used in the edge
+ * @param targetId The target id
+ *
+ * @return A search by edge command to search the graph
*/
- public static String getEdgeTypeFromConnectionType( String connectionType ) {
- return (EDGE_CONN_SUFFIX + "|" + connectionType).toLowerCase();
- }
+ public static SearchByEdge createConnectionSearchByEdge( final Id sourceId, final String connectionType,
+ final Id targetId ) {
+ final String edgeType = getEdgeTypeFromConnectionType( connectionType );
- /**
- * Generate a standard edges from for a collection
- * @param collectionName
- * @return
- */
- public static String getEdgeTypeFromCollectionName( String collectionName ) {
- return (EDGE_COLL_SUFFIX + "|" + collectionName).toLowerCase();
+ return new SimpleSearchByEdge( sourceId, edgeType, targetId, Long.MAX_VALUE, SearchByEdgeType.Order.DESCENDING,
+ null );
}
/**
* Get the application scope from the given uuid
+ *
* @param applicationId The applicationId
*/
public static ApplicationScope getApplicationScope( UUID applicationId ) {
@@ -240,8 +220,8 @@ public class CpNamingUtils {
/**
* Generate an applicationId from the given UUID
- * @param applicationId the applicationId
*
+ * @param applicationId the applicationId
*/
public static Id generateApplicationId( UUID applicationId ) {
return new SimpleId( applicationId, Application.ENTITY_TYPE );
@@ -250,11 +230,51 @@ public class CpNamingUtils {
/**
* Get the map scope for the applicationId to store entity uuid to type mapping
- *
- * @param applicationId
- * @return
*/
- public static MapScope getEntityTypeMapScope( final Id applicationId ){
- return new MapScopeImpl(applicationId, CpNamingUtils.TYPES_BY_UUID_MAP );
+ public static MapScope getEntityTypeMapScope( final Id applicationId ) {
+ return new MapScopeImpl( applicationId, CpNamingUtils.TYPES_BY_UUID_MAP );
+ }
+
+
+ /**
+ * Generate either the collection name or connection name from the edgeName
+ */
+ public static String getNameFromEdgeType( final String edgeName ) {
+
+
+ if ( isCollectionEdgeType( edgeName ) ) {
+ return getCollectionScopeNameFromCollectionName( getCollectionName( edgeName ) );
+ }
+
+ return getConnectionScopeName( getConnectionType( edgeName ) );
+ }
+
+
+ private static boolean isCollectionEdgeType( String type ) {
+ return type.startsWith( EDGE_COLL_SUFFIX );
+ }
+
+
+ private static String getConnectionType( String edgeType ) {
+ String[] parts = edgeType.split( "\\|" );
+ return parts[1];
+ }
+
+
+ private static String getCollectionName( String edgeType ) {
+ String[] parts = edgeType.split( "\\|" );
+ return parts[1];
+ }
+
+
+ private static String getCollectionScopeNameFromCollectionName( String name ) {
+ String csn = EDGE_COLL_SUFFIX + name;
+ return csn.toLowerCase();
+ }
+
+
+ private static String getConnectionScopeName( String connectionType ) {
+ String csn = EDGE_CONN_SUFFIX + connectionType;
+ return csn.toLowerCase();
}
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e534d9c7/stack/core/src/main/java/org/apache/usergrid/persistence/Query.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/Query.java b/stack/core/src/main/java/org/apache/usergrid/persistence/Query.java
index 66152d4..163593e 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/Query.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/Query.java
@@ -19,62 +19,44 @@
package org.apache.usergrid.persistence;
-import com.fasterxml.jackson.annotation.JsonIgnore;
+import java.io.IOException;
import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
-import java.util.LinkedHashMap;
+import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
-import java.util.Set;
import java.util.UUID;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import java.io.IOException;
-import org.antlr.runtime.ANTLRStringStream;
-import org.antlr.runtime.ClassicToken;
-import org.antlr.runtime.CommonTokenStream;
-import org.antlr.runtime.RecognitionException;
-import org.antlr.runtime.Token;
-import org.antlr.runtime.TokenRewriteStream;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang.StringUtils;
-import org.apache.usergrid.persistence.index.exceptions.IndexException;
+
+import org.apache.usergrid.persistence.index.SelectFieldMapping;
import org.apache.usergrid.persistence.index.exceptions.QueryParseException;
-import org.apache.usergrid.persistence.index.impl.EsQueryVistor;
-import org.apache.usergrid.persistence.index.impl.IndexingUtils;
import org.apache.usergrid.persistence.index.query.CounterResolution;
import org.apache.usergrid.persistence.index.query.Identifier;
-import org.apache.usergrid.persistence.index.query.tree.AndOperand;
-import org.apache.usergrid.persistence.index.query.tree.ContainsOperand;
-import org.apache.usergrid.persistence.index.query.tree.CpQueryFilterLexer;
-import org.apache.usergrid.persistence.index.query.tree.CpQueryFilterParser;
-import org.apache.usergrid.persistence.index.query.tree.Equal;
-import org.apache.usergrid.persistence.index.query.tree.EqualityOperand;
-import org.apache.usergrid.persistence.index.query.tree.GreaterThan;
-import org.apache.usergrid.persistence.index.query.tree.GreaterThanEqual;
-import org.apache.usergrid.persistence.index.query.tree.LessThan;
-import org.apache.usergrid.persistence.index.query.tree.LessThanEqual;
import org.apache.usergrid.persistence.index.query.tree.Operand;
-import org.apache.usergrid.persistence.index.query.tree.QueryVisitor;
import org.apache.usergrid.persistence.index.utils.ClassUtils;
import org.apache.usergrid.persistence.index.utils.ConversionUtils;
import org.apache.usergrid.persistence.index.utils.ListUtils;
import org.apache.usergrid.persistence.index.utils.MapUtils;
-import org.elasticsearch.index.query.FilterBuilder;
-import org.elasticsearch.index.query.QueryBuilder;
-import org.elasticsearch.index.query.QueryBuilders;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.databind.ObjectMapper;
public class Query {
private static final Logger logger = LoggerFactory.getLogger( Query.class );
+
+
+
public enum Level {
IDS, REFS, CORE_PROPERTIES, ALL_PROPERTIES, LINKED_PROPERTIES
}
@@ -105,6 +87,7 @@ public class Query {
private List<CounterFilterPredicate> counterFilters;
private String collection;
private String ql;
+ private Collection<SelectFieldMapping> selectFields;
private static ObjectMapper mapper = new ObjectMapper();
@@ -339,6 +322,31 @@ public class Query {
}
+ /**
+ * Return true if the query generated select subjects
+ * @return
+ */
+ public boolean hasSelectSubjects() {
+ return this.selectFields != null || this.selectFields.size() > 0;
+ }
+
+
+ /**
+ * Set the select subjects from our query results
+ */
+ public void setSelectSubjects( final Collection<SelectFieldMapping> selectFields ) {
+ this.selectFields = selectFields;
+ }
+
+
+ /**
+ * Get the select assignments from our resetus if they were set
+ */
+ public Collection<SelectFieldMapping> getSelectAssignments() {
+ return this.selectFields;
+ }
+
+
public boolean containsNameOrEmailIdentifiersOnly() {
if ( hasQueryPredicates() ) {
return false;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e534d9c7/stack/core/src/main/java/org/apache/usergrid/persistence/QueryUtils.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/QueryUtils.java b/stack/core/src/main/java/org/apache/usergrid/persistence/QueryUtils.java
index 4f8ad18..b2397c8 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/QueryUtils.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/QueryUtils.java
@@ -18,16 +18,17 @@ package org.apache.usergrid.persistence;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-import java.util.Set;
-import org.apache.usergrid.persistence.Query;
-import static org.apache.usergrid.utils.ClassUtils.cast;
-import org.apache.usergrid.utils.JsonUtils;
+import org.apache.usergrid.persistence.index.SelectFieldMapping;
+import org.apache.usergrid.utils.JsonUtils;
import org.apache.usergrid.utils.ListUtils;
+import static org.apache.usergrid.utils.ClassUtils.cast;
+
/**
* Utilities to deal with query extraction and generation
@@ -54,6 +55,13 @@ public class QueryUtils {
return null;
}
+
+ /**
+ * When a query has select fields, parse the results into a result set by the field mappings
+ * @param q
+ * @param rs
+ * @return
+ */
public static List<Object> getSelectionResults( Query q, Results rs ) {
List<Entity> entities = rs.getEntities();
@@ -68,33 +76,14 @@ public class QueryUtils {
List<Object> results = new ArrayList<Object>();
for ( Entity entity : entities ) {
- if ( q.isMergeSelectResults() ) {
- boolean include = false;
- Map<String, Object> result = new LinkedHashMap<String, Object>();
- Map<String, String> selects = q.getSelectAssignments();
- for ( Map.Entry<String, String> select : selects.entrySet() ) {
- Object obj = JsonUtils.select( entity, select.getValue(), false );
- if ( obj != null ) {
- include = true;
- }
- result.put( select.getKey(), obj );
- }
- if ( include ) {
- results.add( result );
- }
- }
- else {
- boolean include = false;
- List<Object> result = new ArrayList<Object>();
- Set<String> selects = q.getSelectSubjects();
- for ( String select : selects ) {
- Object obj = JsonUtils.select( entity, select );
- if ( obj != null ) {
- include = true;
- }
- result.add( obj );
- }
- if ( include ) {
+
+
+ Collection<SelectFieldMapping> selects = q.getSelectAssignments();
+ for ( SelectFieldMapping select : selects ) {
+ Object obj = JsonUtils.select( entity, select.getSourceFieldName(), false );
+ if ( obj != null ) {
+ Map<String, Object> result = new LinkedHashMap<String, Object>();
+ result.put( select.getTargetFieldName(), obj );
results.add( result );
}
}
@@ -106,14 +95,4 @@ public class QueryUtils {
return results;
}
-
-
- public static Object getSelectionResult( Query q, Results rs ) {
- List<Object> r = QueryUtils.getSelectionResults( q, rs );
- if ( ( r != null ) && ( r.size() > 0 ) ) {
- return r.get( 0 );
- }
- return null;
- }
-
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e534d9c7/stack/core/src/main/java/org/apache/usergrid/persistence/RelationManager.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/RelationManager.java b/stack/core/src/main/java/org/apache/usergrid/persistence/RelationManager.java
index 52a4806..218ea3a 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/RelationManager.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/RelationManager.java
@@ -116,6 +116,5 @@ public interface RelationManager {
public Set<String> getConnectionIndexes( String connectionType ) throws Exception;
- public void batchUpdateSetIndexes( Mutator<ByteBuffer> batch, String setName, Object elementValue,
- boolean removeFromSet, UUID timestampUuid ) throws Exception;
+
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e534d9c7/stack/core/src/test/java/org/apache/usergrid/Application.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/Application.java b/stack/core/src/test/java/org/apache/usergrid/Application.java
index faa9b4f..56028bb 100644
--- a/stack/core/src/test/java/org/apache/usergrid/Application.java
+++ b/stack/core/src/test/java/org/apache/usergrid/Application.java
@@ -26,7 +26,7 @@ import org.apache.usergrid.persistence.Entity;
import org.apache.usergrid.persistence.EntityManager;
import org.apache.usergrid.persistence.EntityRef;
import org.apache.usergrid.persistence.Results;
-import org.apache.usergrid.persistence.index.query.Query;
+import org.apache.usergrid.persistence.Query;
/**
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e534d9c7/stack/core/src/test/java/org/apache/usergrid/CoreApplication.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/CoreApplication.java b/stack/core/src/test/java/org/apache/usergrid/CoreApplication.java
index c59ff72..d3861a6 100644
--- a/stack/core/src/test/java/org/apache/usergrid/CoreApplication.java
+++ b/stack/core/src/test/java/org/apache/usergrid/CoreApplication.java
@@ -36,7 +36,7 @@ import org.apache.usergrid.persistence.EntityManager;
import org.apache.usergrid.persistence.EntityRef;
import org.apache.usergrid.persistence.Results;
import org.apache.usergrid.persistence.SimpleEntityRef;
-import org.apache.usergrid.persistence.index.query.Query;
+import org.apache.usergrid.persistence.Query;
import org.apache.usergrid.persistence.model.util.UUIDGenerator;
import static junit.framework.Assert.assertNotNull;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e534d9c7/stack/core/src/test/java/org/apache/usergrid/batch/job/SchedulerRuntime8IT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/batch/job/SchedulerRuntime8IT.java b/stack/core/src/test/java/org/apache/usergrid/batch/job/SchedulerRuntime8IT.java
index abc5a13..a8c88ff 100644
--- a/stack/core/src/test/java/org/apache/usergrid/batch/job/SchedulerRuntime8IT.java
+++ b/stack/core/src/test/java/org/apache/usergrid/batch/job/SchedulerRuntime8IT.java
@@ -24,7 +24,7 @@ import org.junit.Test;
import org.apache.usergrid.persistence.Results;
import org.apache.usergrid.persistence.entities.JobData;
-import org.apache.usergrid.persistence.index.query.Query;
+import org.apache.usergrid.persistence.Query;
import org.apache.usergrid.utils.UUIDUtils;
import static org.junit.Assert.assertEquals;
@@ -66,8 +66,7 @@ public class SchedulerRuntime8IT extends AbstractSchedulerRuntimeIT {
// now query and make sure it equals the saved value
- Query query = new Query();
- query.addEqualityFilter( "notificationId", notificationId );
+ Query query = Query.fromQL( "notificationId = " + notificationId );
Results r = scheduler.queryJobData( query );
@@ -77,8 +76,7 @@ public class SchedulerRuntime8IT extends AbstractSchedulerRuntimeIT {
assertEquals( saved.getUuid(), r.getEntity().getUuid() );
// query by uuid
- query = new Query();
- query.addEqualityFilter( "stringprop", "test" );
+ query = Query.fromQL( "stringprop = 'test'" );
r = scheduler.queryJobData( query );
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e534d9c7/stack/core/src/test/java/org/apache/usergrid/corepersistence/StaleIndexCleanupTest.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/corepersistence/StaleIndexCleanupTest.java b/stack/core/src/test/java/org/apache/usergrid/corepersistence/StaleIndexCleanupTest.java
index f743f0b..ce12419 100644
--- a/stack/core/src/test/java/org/apache/usergrid/corepersistence/StaleIndexCleanupTest.java
+++ b/stack/core/src/test/java/org/apache/usergrid/corepersistence/StaleIndexCleanupTest.java
@@ -46,12 +46,11 @@ import org.apache.usergrid.persistence.collection.EntityCollectionManagerFactory
import org.apache.usergrid.persistence.core.scope.ApplicationScope;
import org.apache.usergrid.persistence.core.scope.ApplicationScopeImpl;
import org.apache.usergrid.persistence.index.ApplicationEntityIndex;
+import org.apache.usergrid.persistence.index.CandidateResults;
import org.apache.usergrid.persistence.index.EntityIndexFactory;
-import org.apache.usergrid.persistence.index.IndexScope;
+import org.apache.usergrid.persistence.index.SearchEdge;
import org.apache.usergrid.persistence.index.SearchTypes;
-import org.apache.usergrid.persistence.index.impl.IndexScopeImpl;
-import org.apache.usergrid.persistence.index.query.CandidateResults;
-import org.apache.usergrid.persistence.index.query.Query;
+import org.apache.usergrid.persistence.Query;
import org.apache.usergrid.persistence.model.entity.Id;
import org.apache.usergrid.persistence.model.entity.SimpleId;
@@ -61,7 +60,6 @@ import com.google.inject.Injector;
import net.jcip.annotations.NotThreadSafe;
import static org.apache.usergrid.corepersistence.CoreModule.EVENTS_DISABLED;
-import static org.apache.usergrid.corepersistence.util.CpNamingUtils.generateScopeFromCollection;
import static org.apache.usergrid.persistence.Schema.TYPE_APPLICATION;
import static org.apache.usergrid.persistence.core.util.IdGenerator.createId;
import static org.junit.Assert.assertEquals;
@@ -494,13 +492,10 @@ public class StaleIndexCleanupTest extends AbstractCoreIT {
ApplicationEntityIndex ei = eif.createApplicationEntityIndex(as);
final Id rootId = createId(em.getApplicationId(), TYPE_APPLICATION);
- IndexScope is = generateScopeFromCollection(rootId, collName );
- Query rcq = Query.fromQL( query );
+ SearchEdge is = CpNamingUtils.createCollectionSearchEdge( rootId, collName );
- // TODO: why does this have no effect; max we ever get is 1000 entities
- rcq.setLimit( 10000 ); // no paging
- return ei.search( is, SearchTypes.fromTypes( type ), rcq );
+ return ei.search( is, SearchTypes.fromTypes( type ), query, 10000 );
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e534d9c7/stack/core/src/test/java/org/apache/usergrid/persistence/CollectionIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/CollectionIT.java b/stack/core/src/test/java/org/apache/usergrid/persistence/CollectionIT.java
index 129a701..3f05d05 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/CollectionIT.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/CollectionIT.java
@@ -36,8 +36,8 @@ import org.apache.usergrid.CoreApplication;
import org.apache.usergrid.persistence.entities.User;
import org.apache.usergrid.persistence.exceptions.DuplicateUniquePropertyExistsException;
import org.apache.usergrid.persistence.index.query.Identifier;
-import org.apache.usergrid.persistence.index.query.Query;
-import org.apache.usergrid.persistence.index.query.Query.Level;
+import org.apache.usergrid.persistence.Query;
+import org.apache.usergrid.persistence.Query.Level;
import org.apache.usergrid.utils.JsonUtils;
import org.apache.usergrid.utils.UUIDUtils;
@@ -146,13 +146,12 @@ public class CollectionIT extends AbstractCoreIT {
assertEquals( 3, r.size() ); // success
// query verb
- query = new Query().addEqualityFilter( "verb", "tweet2" );
+ query = Query.fromQL( "verb = 'tweet2'" );
r = app.searchCollection( user, "activities", query );
assertEquals( 2, r.size() );
// query verb, sort created
- query = new Query().addEqualityFilter( "verb", "tweet2" );
- query.addSort( "created" );
+ query = Query.fromQL( "verb = 'tweet2' order by created" );
r = app.searchCollection( user, "activities", query );
assertEquals( 2, r.size() );
List<Entity> entities = r.getEntities();
@@ -160,8 +159,7 @@ public class CollectionIT extends AbstractCoreIT {
assertEquals( entities.get( 1 ).getUuid(), activity3.getUuid() );
// query verb, sort ordinal
- query = new Query().addEqualityFilter( "verb", "tweet2" );
- query.addSort( "ordinal" );
+ query = Query.fromQL( "verb = 'tweet2' order by ordinal" );
r = app.searchCollection( user, "activities", query );
assertEquals( 2, r.size() );
entities = r.getEntities();
@@ -172,8 +170,7 @@ public class CollectionIT extends AbstractCoreIT {
// it works in the exact same test in the QueryIndex module/
// // empty query, sort content
- query = new Query();
- query.addSort( "content" );
+ query = Query.fromQL( "order by content" );
r = app.searchCollection( user, "activities", query );
assertEquals( 3, r.size() );
entities = r.getEntities();
@@ -183,14 +180,12 @@ public class CollectionIT extends AbstractCoreIT {
assertEquals( entities.get( 2 ).getUuid(), activity3.getUuid() );
// empty query, sort verb
- query = new Query();
- query.addSort( "verb" );
+ query = Query.fromQL( "order by verb" );
r = app.searchCollection( user, "activities", query );
assertEquals( 3, r.size() );
// empty query, sort ordinal
- query = new Query();
- query.addSort( "ordinal" );
+ query = Query.fromQL( "order by ordinal" );
r = app.searchCollection( user, "activities", query );
assertEquals( 3, r.size() );
entities = r.getEntities();
@@ -199,13 +194,12 @@ public class CollectionIT extends AbstractCoreIT {
assertEquals( entities.get( 2 ).getUuid(), activity.getUuid() );
// query ordinal
- query = new Query().addEqualityFilter( "ordinal", 2 );
+ query = Query.fromQL( "ordinal = 2" );
r = app.searchCollection( user, "activities", query );
assertEquals( 1, r.size() );
// query ordinal and sort ordinal
- query = new Query().addEqualityFilter( "ordinal", 2 );
- query.addSort( "ordinal" );
+ query = Query.fromQL( "ordinal = 2 order by ordinal");
r = app.searchCollection( user, "activities", query );
assertEquals( 1, r.size() );
}
@@ -231,8 +225,7 @@ public class CollectionIT extends AbstractCoreIT {
app.refreshIndex();
// EntityRef
- Query query = new Query();
- query.addEqualityFilter( "firstname", firstName );
+ Query query = Query.fromQL( "firstname = '" + firstName + "'" );
Results r = em.searchCollection( em.getApplicationRef(), "users", query );
@@ -252,15 +245,14 @@ public class CollectionIT extends AbstractCoreIT {
app.refreshIndex();
// search with the old username, should be no results
- query.addEqualityFilter( "firstname", firstName );
+ query = Query.fromQL( "firstname = '" + firstName + "'" );
r = em.searchCollection( em.getApplicationRef(), "users", query );
assertEquals( 0, r.size() );
// search with the new username, should be results.
- query = new Query();
- query.addEqualityFilter( "firstname", newFirstName );
+ query = Query.fromQL( "firstname = '" + newFirstName + "'" );
r = em.searchCollection( em.getApplicationRef(), "users", query );
@@ -292,8 +284,7 @@ public class CollectionIT extends AbstractCoreIT {
app.refreshIndex();
// EntityRef
- Query query = new Query();
- query.addEqualityFilter( "middlename", middleName );
+ final Query query = Query.fromQL( "middlename = '" + middleName + "'" );
Results r = em.searchCollection( em.getApplicationRef(), "users", query );
@@ -325,8 +316,7 @@ public class CollectionIT extends AbstractCoreIT {
app.refreshIndex();
// EntityRef
- Query query = new Query();
- query.addEqualityFilter( "lastname", lastName );
+ final Query query = Query.fromQL( "lastname = '" + lastName + "'" );
Results r = em.searchCollection( em.getApplicationRef(), "users", query );
@@ -373,9 +363,11 @@ public class CollectionIT extends AbstractCoreIT {
app.refreshIndex();
+ final Query query = Query.fromQL( "nickname = 'ed'" );
+
Results r = em.searchCollection( group, "users",
- new Query().addEqualityFilter( "nickname", "ed" )
- .withResultsLevel(Level.LINKED_PROPERTIES ) );
+ query
+ .withResultsLevel( Level.LINKED_PROPERTIES ) );
LOG.info( JsonUtils.mapToFormattedJsonString( r.getEntities() ) );
assertEquals( 1, r.size() );
@@ -404,8 +396,7 @@ public class CollectionIT extends AbstractCoreIT {
app.refreshIndex();
// EntityRef
- Query query = new Query();
- query.addEqualityFilter( "name", groupName );
+ final Query query = Query.fromQL( "name = '" + groupName + "'" );
Results r = em.searchCollection( em.getApplicationRef(), "groups", query );
@@ -437,8 +428,8 @@ public class CollectionIT extends AbstractCoreIT {
app.refreshIndex();
// EntityRef
- Query query = new Query();
- query.addEqualityFilter( "title", titleName );
+
+ final Query query = Query.fromQL( "title = '" + titleName + "'" );
Results r = em.searchCollection( em.getApplicationRef(), "groups", query );
@@ -494,7 +485,9 @@ public class CollectionIT extends AbstractCoreIT {
app.refreshIndex();
- Results r = em.searchCollection( user, "activities", Query.searchForProperty( "verb", "post" ) );
+ final Query query = Query.fromQL( "verb = 'post'" );
+
+ Results r = em.searchCollection( user, "activities", query);
LOG.info( JsonUtils.mapToFormattedJsonString( r.getEntities() ) );
assertEquals( 2, r.size() );
}
@@ -1019,10 +1012,7 @@ public class CollectionIT extends AbstractCoreIT {
int pageSize = 10;
app.refreshIndex();
-
- Query query = new Query();
- query.setLimit( pageSize );
- query.addFilter( "index < " + size * 2 );
+ final Query query = Query.fromQL( "index < " + size * 2 );
Results r = null;
@@ -1073,9 +1063,8 @@ public class CollectionIT extends AbstractCoreIT {
app.refreshIndex();
- Query query = Query.fromQL("select * where index >= " + size / 2);
+ Query query = Query.fromQL("select * where index >= " + size / 2 + " + sort by index asc");
query.setLimit( pageSize );
- query.addSort(new Query.SortPredicate("index", Query.SortDirection.ASCENDING));
Results r = null;
@@ -1125,9 +1114,8 @@ public class CollectionIT extends AbstractCoreIT {
int pageSize = 10;
- Query query = Query.fromQL("select * where index >= 10 and index <= 29");
+ Query query = Query.fromQL("select * where index >= 10 and index <= 29 sort by index asc");
query.setLimit( pageSize );
- query.addSort(new Query.SortPredicate("index", Query.SortDirection.ASCENDING));
Results r = null;
@@ -1177,9 +1165,8 @@ public class CollectionIT extends AbstractCoreIT {
int pageSize = 10;
- Query query = Query.fromQL("select * where index >= 10 and index <= 29");
+ Query query = Query.fromQL("select * where index >= 10 and index <= 29 sort by index asc");
query.setLimit( pageSize );
- query.addSort(new Query.SortPredicate("index", Query.SortDirection.ASCENDING));
Results r = em.searchCollection( em.getApplicationRef(), "pages", query );
@@ -1227,18 +1214,16 @@ public class CollectionIT extends AbstractCoreIT {
app.refreshIndex();
- Query query = new Query();
- query.addEqualityFilter( "rootprop1", "simpleprop" );
+ Query query = Query.fromQL( "rootprop1 = 'simpleprop'" );
Entity entity;
Results results;
- results = em.searchCollection(em.getApplicationRef(), "tests", query);
- entity = results.getEntitiesMap().get(saved.getUuid());
+ results = em.searchCollection( em.getApplicationRef(), "tests", query );
+ entity = results.getEntitiesMap().get( saved.getUuid() );
assertNotNull( entity );
// query on the nested int value
- query = new Query();
- query.addEqualityFilter( "subentity.intprop", 10 );
+ query = Query.fromQL( "subentity.intprop = 10" );
results = em.searchCollection( em.getApplicationRef(), "tests", query );
@@ -1247,9 +1232,7 @@ public class CollectionIT extends AbstractCoreIT {
assertNotNull( entity );
// query on the nexted tokenized value
- query = new Query();
- query.addContainsFilter( "subentity.substring", "tokenized" );
- query.addContainsFilter( "subentity.substring", "indexed" );
+ query = Query.fromQL( "subentity.substring contains 'tokenized' and subentity.substring contains 'indexed'" );
results = em.searchCollection( em.getApplicationRef(), "tests", query );
@@ -1278,8 +1261,7 @@ public class CollectionIT extends AbstractCoreIT {
app.refreshIndex();
- Query query = new Query();
- query.addEqualityFilter( "intprop", 10 );
+ Query query = Query.fromQL( "intprop = 10" );
Results results = em.searchCollection( em.getApplicationRef(), "tests", query );
@@ -1288,8 +1270,7 @@ public class CollectionIT extends AbstractCoreIT {
assertNotNull( entity );
// query on the nested int value
- query = new Query();
- query.addEqualityFilter( "array", "val1" );
+ query = Query.fromQL( "array = 'val1'" );
results = em.searchCollection( em.getApplicationRef(), "tests", query );
@@ -1298,8 +1279,7 @@ public class CollectionIT extends AbstractCoreIT {
assertNotNull( entity );
// query on the nexted tokenized value
- query = new Query();
- query.addEqualityFilter( "array", "val2" );
+ query = Query.fromQL( "array = 'val2'" );
results = em.searchCollection( em.getApplicationRef(), "tests", query );
@@ -1307,8 +1287,7 @@ public class CollectionIT extends AbstractCoreIT {
assertNotNull( entity );
- query = new Query();
- query.addEqualityFilter( "array", "val3" );
+ query = Query.fromQL( "array = 'val3'" );
results = em.searchCollection( em.getApplicationRef(), "tests", query );
@@ -1316,8 +1295,7 @@ public class CollectionIT extends AbstractCoreIT {
assertNull( entity );
- query = new Query();
- query.addContainsFilter( "array", "spaces" );
+ query = Query.fromQL( "array contains 'spaces'" );
results = em.searchCollection( em.getApplicationRef(), "tests", query );
entity = results.getEntitiesMap().get( saved.getUuid() );
@@ -1342,8 +1320,7 @@ public class CollectionIT extends AbstractCoreIT {
app.refreshIndex();
- Query query = new Query();
- query.addEqualityFilter( "myString", "My simple string" );
+ Query query = Query.fromQL("myString = 'My simple string'" );
Results results = em.searchCollection( em.getApplicationRef(), "tests", query );
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e534d9c7/stack/core/src/test/java/org/apache/usergrid/persistence/CounterIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/CounterIT.java b/stack/core/src/test/java/org/apache/usergrid/persistence/CounterIT.java
index a5e1493..5bc448f 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/CounterIT.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/CounterIT.java
@@ -37,7 +37,7 @@ import org.apache.usergrid.persistence.entities.Event;
import org.apache.usergrid.persistence.entities.Group;
import org.apache.usergrid.persistence.entities.User;
import org.apache.usergrid.persistence.index.query.CounterResolution;
-import org.apache.usergrid.persistence.index.query.Query;
+import org.apache.usergrid.persistence.Query;
import org.apache.usergrid.persistence.model.util.UUIDGenerator;
import org.apache.usergrid.utils.ImmediateCounterRule;
import org.apache.usergrid.utils.JsonUtils;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e534d9c7/stack/core/src/test/java/org/apache/usergrid/persistence/CountingMutatorIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/CountingMutatorIT.java b/stack/core/src/test/java/org/apache/usergrid/persistence/CountingMutatorIT.java
index 175cc74..abb9417 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/CountingMutatorIT.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/CountingMutatorIT.java
@@ -31,7 +31,7 @@ import org.apache.commons.lang3.RandomStringUtils;
import org.apache.usergrid.AbstractCoreIT;
import org.apache.usergrid.persistence.hector.CountingMutator;
-import org.apache.usergrid.persistence.index.query.Query.Level;
+import org.apache.usergrid.persistence.Query.Level;
import org.apache.usergrid.persistence.model.util.UUIDGenerator;
import org.apache.usergrid.utils.UUIDUtils;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e534d9c7/stack/core/src/test/java/org/apache/usergrid/persistence/EntityConnectionsIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/EntityConnectionsIT.java b/stack/core/src/test/java/org/apache/usergrid/persistence/EntityConnectionsIT.java
index 2e7de4f..6b508b4 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/EntityConnectionsIT.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/EntityConnectionsIT.java
@@ -31,7 +31,7 @@ import org.slf4j.LoggerFactory;
import org.apache.usergrid.AbstractCoreIT;
import org.apache.usergrid.persistence.entities.User;
-import org.apache.usergrid.persistence.index.query.Query.Level;
+import org.apache.usergrid.persistence.Query.Level;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e534d9c7/stack/core/src/test/java/org/apache/usergrid/persistence/EntityManagerIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/EntityManagerIT.java b/stack/core/src/test/java/org/apache/usergrid/persistence/EntityManagerIT.java
index cd255c6..3545739 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/EntityManagerIT.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/EntityManagerIT.java
@@ -37,8 +37,8 @@ import org.apache.commons.lang3.RandomStringUtils;
import org.apache.usergrid.AbstractCoreIT;
import org.apache.usergrid.persistence.entities.Group;
import org.apache.usergrid.persistence.entities.User;
-import org.apache.usergrid.persistence.index.query.Query;
-import org.apache.usergrid.persistence.index.query.Query.Level;
+import org.apache.usergrid.persistence.Query;
+import org.apache.usergrid.persistence.Query.Level;
import org.apache.usergrid.persistence.model.util.UUIDGenerator;
import org.apache.usergrid.utils.UUIDUtils;
@@ -79,7 +79,7 @@ public class EntityManagerIT extends AbstractCoreIT {
user = em.get( user );
assertNotNull( user );
assertEquals( "user.username not expected value", "edanuff", user.getProperty( "username"));
- assertEquals( "user.email not expected value", "ed@anuff.com", user.getProperty( "email" ));
+ assertEquals( "user.email not expected value", "ed@anuff.com", user.getProperty( "email" ) );
app.refreshIndex();
@@ -93,20 +93,22 @@ public class EntityManagerIT extends AbstractCoreIT {
LOG.info( "user.username: " + user.getProperty( "username" ) );
LOG.info( "user.email: " + user.getProperty( "email" ) );
- Results results = em.searchCollection( em.getApplicationRef(), "users",
- new Query().addEqualityFilter( "username", "edanuff" ) );
+ final Query query = Query.fromQL("username = 'edanuff'");
+
+ Results results = em.searchCollection( em.getApplicationRef(), "users", query );
assertNotNull( results );
assertEquals( 1, results.size() );
user = results.getEntity();
assertNotNull( user );
- assertEquals( "user.username not expected value", "edanuff", user.getProperty( "username"));
- assertEquals( "user.email not expected value", "ed@anuff.com", user.getProperty( "email"));
+ assertEquals( "user.username not expected value", "edanuff", user.getProperty( "username" ) );
+ assertEquals( "user.email not expected value", "ed@anuff.com", user.getProperty( "email" ) );
LOG.info( "user.username: " + user.getProperty( "username" ) );
LOG.info( "user.email: " + user.getProperty( "email" ) );
- results = em.searchCollection( em.getApplicationRef(), "users",
- new Query().addEqualityFilter( "email", "ed@anuff.com" ) );
+ final Query emailQuery = Query.fromQL( "email = 'ed@anuff.com'" );
+
+ results = em.searchCollection( em.getApplicationRef(), "users", emailQuery );
assertNotNull( results );
assertEquals( 1, results.size() );
user = results.getEntity();
@@ -287,8 +289,12 @@ public class EntityManagerIT extends AbstractCoreIT {
// now search by username, no results should be returned
+
+ final Query emailQuery = Query.fromQL( "name = '" + name +"'" );
+
+
Results r = em.searchCollection( em.getApplicationRef(), "thing",
- new Query().addEqualityFilter( "name", name ) );
+ emailQuery );
assertEquals( 0, r.size() );
}
@@ -320,8 +326,9 @@ public class EntityManagerIT extends AbstractCoreIT {
// now search by username, no results should be returned
+ final Query query = Query.fromQL( "username = '" + name + "'" );
Results r = em.searchCollection( em.getApplicationRef(), "users",
- new Query().addEqualityFilter( "username", name ) );
+ query );
assertEquals( 0, r.size() );
@@ -337,8 +344,9 @@ public class EntityManagerIT extends AbstractCoreIT {
app.refreshIndex();
- r = em.searchCollection( em.getApplicationRef(), "users",
- new Query().addEqualityFilter( "username", name ) );
+ final Query userNameQuery = Query.fromQL( "username = '" + name + "'" );
+
+ r = em.searchCollection( em.getApplicationRef(), "users", userNameQuery);
assertEquals( 1, r.size() );
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e534d9c7/stack/core/src/test/java/org/apache/usergrid/persistence/EntityPropertyComparatorTest.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/EntityPropertyComparatorTest.java b/stack/core/src/test/java/org/apache/usergrid/persistence/EntityPropertyComparatorTest.java
deleted file mode 100644
index b5284a9..0000000
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/EntityPropertyComparatorTest.java
+++ /dev/null
@@ -1,222 +0,0 @@
-/*
- * 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;
-
-
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-
-
-/** Test for the entity comparator */
-public class EntityPropertyComparatorTest {
-
-
- @Test
- public void testNulls() throws Exception {
-
- DynamicEntity first = new DynamicEntity();
- first.setProperty( "test", true );
-
- EntityPropertyComparator forward = new EntityPropertyComparator( "test", false );
-
-
- assertEquals( 0, forward.compare( null, null ) );
-
- assertEquals( -1, forward.compare( first, null ) );
-
- assertEquals( 1, forward.compare( null, first ) );
-
-
- //now test in reverse
-
- EntityPropertyComparator reverse = new EntityPropertyComparator( "test", true );
-
-
- assertEquals( 0, reverse.compare( null, null ) );
-
- assertEquals( -1, reverse.compare( first, null ) );
-
- assertEquals( 1, reverse.compare( null, first ) );
- }
-
-
- @Test
- public void testBooleans() throws Exception {
-
- DynamicEntity second = new DynamicEntity();
- second.setProperty( "test", true );
-
-
- DynamicEntity first = new DynamicEntity();
- first.setProperty( "test", false );
-
- EntityPropertyComparator forward = new EntityPropertyComparator( "test", false );
-
-
- assertEquals( 0, forward.compare( second, second ) );
-
- assertEquals( 1, forward.compare( second, first ) );
-
- assertEquals( -1, forward.compare( first, second ) );
-
-
- //now test in reverse
-
- EntityPropertyComparator reverse = new EntityPropertyComparator( "test", true );
-
-
- assertEquals( 0, reverse.compare( second, second ) );
-
- assertEquals( 1, reverse.compare( first, second ) );
-
- assertEquals( -1, reverse.compare( second, first ) );
- }
-
-
- @Test
- public void testFloat() throws Exception {
-
- DynamicEntity second = new DynamicEntity();
- second.setProperty( "test", 1.0f );
-
-
- DynamicEntity first = new DynamicEntity();
- first.setProperty( "test", 0.0f );
-
- EntityPropertyComparator forward = new EntityPropertyComparator( "test", false );
-
-
- assertEquals( 0, forward.compare( second, second ) );
-
- assertEquals( 1, forward.compare( second, first ) );
-
- assertEquals( -1, forward.compare( first, second ) );
-
-
- //now test in reverse
-
- EntityPropertyComparator reverse = new EntityPropertyComparator( "test", true );
-
-
- assertEquals( 0, reverse.compare( second, second ) );
-
- assertEquals( 1, reverse.compare( first, second ) );
-
- assertEquals( -1, reverse.compare( second, first ) );
- }
-
-
- @Test
- public void testLong() throws Exception {
-
- DynamicEntity second = new DynamicEntity();
- second.setProperty( "test", 1l );
-
-
- DynamicEntity first = new DynamicEntity();
- first.setProperty( "test", 0l );
-
- EntityPropertyComparator forward = new EntityPropertyComparator( "test", false );
-
-
- assertEquals( 0, forward.compare( second, second ) );
-
- assertEquals( 1, forward.compare( second, first ) );
-
- assertEquals( -1, forward.compare( first, second ) );
-
-
- //now test in reverse
-
- EntityPropertyComparator reverse = new EntityPropertyComparator( "test", true );
-
-
- assertEquals( 0, reverse.compare( second, second ) );
-
- assertEquals( 1, reverse.compare( first, second ) );
-
- assertEquals( -1, reverse.compare( second, first ) );
- }
-
-
- @Test
- public void testDouble() throws Exception {
-
- DynamicEntity second = new DynamicEntity();
- second.setProperty( "test", 1d );
-
-
- DynamicEntity first = new DynamicEntity();
- first.setProperty( "test", 0d );
-
-
- EntityPropertyComparator forward = new EntityPropertyComparator( "test", false );
-
-
- assertEquals( 0, forward.compare( second, second ) );
-
- assertEquals( 1, forward.compare( second, first ) );
-
- assertEquals( -1, forward.compare( first, second ) );
-
-
- //now test in reverse
-
- EntityPropertyComparator reverse = new EntityPropertyComparator( "test", true );
-
-
- assertEquals( 0, reverse.compare( second, second ) );
-
- assertEquals( 1, reverse.compare( first, second ) );
-
- assertEquals( -1, reverse.compare( second, first ) );
- }
-
-
- @Test
- public void testString() throws Exception {
-
- DynamicEntity second = new DynamicEntity();
- second.setProperty( "test", "b" );
-
-
- DynamicEntity first = new DynamicEntity();
- first.setProperty( "test", "a" );
-
- EntityPropertyComparator forward = new EntityPropertyComparator( "test", false );
-
-
- assertEquals( 0, forward.compare( second, second ) );
-
- assertEquals( 1, forward.compare( second, first ) );
-
- assertEquals( -1, forward.compare( first, second ) );
-
-
- //now test in reverse
-
- EntityPropertyComparator reverse = new EntityPropertyComparator( "test", true );
-
-
- assertEquals( 0, reverse.compare( second, second ) );
-
- assertEquals( 1, reverse.compare( first, second ) );
-
- assertEquals( -1, reverse.compare( second, first ) );
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e534d9c7/stack/core/src/test/java/org/apache/usergrid/persistence/GeoIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/GeoIT.java b/stack/core/src/test/java/org/apache/usergrid/persistence/GeoIT.java
index c50ccaf..614e5f6 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/GeoIT.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/GeoIT.java
@@ -28,8 +28,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.usergrid.AbstractCoreIT;
-import org.apache.usergrid.persistence.geo.model.Point;
-import org.apache.usergrid.persistence.index.query.Query;
import org.apache.usergrid.persistence.model.field.value.Location;
import org.apache.usergrid.utils.MapUtils;
@@ -143,10 +141,11 @@ public class GeoIT extends AbstractCoreIT {
assertNotNull(user);
app.refreshIndex();
- Point center = new Point(37.776753, -122.407846);
+ final double lat = 37.776753;
+ final double lon = -122.407846;
//2. Query from a point near the entity's location
Query query = Query.fromQL("select * where location within 100 of "
- + center.getLat() + "," + center.getLon());
+ + lat + "," + lon);
Results listResults = em.searchCollection(em.getApplicationRef(), "users", query);
assertEquals(1, listResults.size());
@@ -263,9 +262,10 @@ public class GeoIT extends AbstractCoreIT {
EntityManager em = loadGeolocationTestEntities();
//2. Query the collection from a point more than 10000m from the locations
// and ensure that no entities are returned when restricted to a 10000m radius
- Point center = new Point(37.776753, -122.407846);
+ final double lat = 37.776753;
+ final double lon = -122.407846;
Query query = Query.fromQL("select * where location within " + NEARBY_RADIUS + " of "
- + center.getLat() + "," + center.getLon());
+ + lat + "," + lon);
Results listResults = em.searchCollection(em.getApplicationRef(), "stores", query);
assertEquals("Results within " + NEARBY_RADIUS + "m from center", 0, listResults.size());
@@ -273,7 +273,7 @@ public class GeoIT extends AbstractCoreIT {
// and ensure that all entities are returned when the distance is set to the
// circumference of the earth
Query query2 = Query.fromQL("select * where location within " + CIRCUMFERENCE_OF_THE_EARTH + " of "
- + center.getLat() + "," + center.getLon());
+ + lat + "," + lon);
listResults = em.searchCollection(em.getApplicationRef(), "stores", query2);
assertEquals("Results within " + CIRCUMFERENCE_OF_THE_EARTH
@@ -292,27 +292,28 @@ public class GeoIT extends AbstractCoreIT {
* circumference of the earth
*/
public void testGeoFromNearbyLocation() throws Exception {
- LOG.info("GeoIT.testGeoFromNearbyLocation");
+ LOG.info( "GeoIT.testGeoFromNearbyLocation" );
//1. create entities with geo
EntityManager em = loadGeolocationTestEntities();
- Point center = new Point(-33.746369, 150.952185);
+ final double lat = -33.746369;
+ final double lon = 150.952185;
//2. Query the collection from a point less than 10000m from the locations
// and ensure that one entity is returned when restricted to a 10000m radius
Query query = Query.fromQL("select * where location within " + NEARBY_RADIUS + " of "
- + center.getLat() + "," + center.getLon());
+ + lat + "," + lon);
Results listResults = em.searchCollection(em.getApplicationRef(), "stores", query);
- assertEquals("Results within " + NEARBY_RADIUS + "m from center", 1, listResults.size());
+ assertEquals( "Results within " + NEARBY_RADIUS + "m from center", 1, listResults.size() );
//3. Query the collection from a point less than 10000m from the locations
// and ensure that all entities are returned when the distance is set to the
// circumference of the earth
- query = Query.fromQL("select * where location within " + CIRCUMFERENCE_OF_THE_EARTH + " of "
- + center.getLat() + "," + center.getLon());
+ query = Query.fromQL(
+ "select * where location within " + CIRCUMFERENCE_OF_THE_EARTH + " of " + lat + "," + lon );
listResults = em.searchCollection(em.getApplicationRef(), "stores", query);
- assertEquals("Results within " + CIRCUMFERENCE_OF_THE_EARTH
- + "m from center", LOCATION_PROPERTIES.size(), listResults.size());
+ assertEquals( "Results within " + CIRCUMFERENCE_OF_THE_EARTH + "m from center", LOCATION_PROPERTIES.size(),
+ listResults.size() );
}
/**
@@ -332,26 +333,29 @@ public class GeoIT extends AbstractCoreIT {
//1 Create entities with geo
EntityManager em = loadGeolocationTestEntities();
//2 Create a list of points from different geographic areas
- List<Point> points = new ArrayList<Point>();
- points.add(new Point(-90.000000, 90.000000));//Antarctica
- points.add(new Point(90, 90));//Santa's house
- points.add(new Point(33.746369, -89));//Woodland, MS
- points.add(new Point(34.35, 58.22)); //Buenos Aires
- points.add(new Point(39.55, 116.25));//Beijing, China
- points.add(new Point(44.52, 20.32)); //Belgrade, Serbia
- points.add(new Point(-1.000000, 102.000000));//Somewhere in Indonesia
- for (Point center : points) {
+ List<double[]> points = new ArrayList<>();
+ points.add(new double[]{-90.000000, 90.000000});//Antarctica
+ points.add(new double[]{90, 90});;//Santa's house
+ points.add( new double[]{ 33.746369, -89});;//Woodland, MS
+ points.add( new double[] { 34.35, 58.22 } );; //Buenos Aires
+ points.add( new double[] { 39.55, 116.25 } );;//Beijing, China
+ points.add( new double[]{ 44.52, 20.32});; //Belgrade, Serbia
+ points.add( new double[] { -1.000000, 102.000000 } );;//Somewhere in Indonesia
+ for (double[] center : points) {
//3 Query the collection from each point
// and ensure that no entities are returned when restricted to a 10000m radius
+ final double lat = center[0];
+ final double lon = center[1];
+
Query query = Query.fromQL("select * where location within 10000 of "
- + center.getLat() + "," + center.getLon());
+ + lat + "," + lon);
Results listResults = em.searchCollection(em.getApplicationRef(), "stores", query);
assertEquals("Results less than 10000m away from center", 0, listResults.size());
//4 Query the collection from each point
// and ensure that all entities are returned when the distance is set to the
// circumference of the earth
Query query2 = Query.fromQL("select * where location within 40000000 of "
- + center.getLat() + "," + center.getLon());
+ + lat + "," + lon);
listResults = em.searchCollection(em.getApplicationRef(), "stores", query2);
assertEquals("Results from center point to ridiculously far",
LOCATION_PROPERTIES.size(), listResults.size());
@@ -364,7 +368,7 @@ public class GeoIT extends AbstractCoreIT {
EntityManager em = app.getEntityManager();
- assertNotNull(em);
+ assertNotNull( em );
// save objects in a diagonal line from -90 -180 to 90 180
@@ -394,11 +398,11 @@ public class GeoIT extends AbstractCoreIT {
app.refreshIndex();
- Query query = new Query();
- // earth's circumference is 40,075 kilometers. Up it to 50,000kilometers
+ // earth's circumference is 40,075 kilometers. Up it to 50,000kilometers
// just to be save
- query.addFilter("location within 50000000 of -90, -180");
- query.setLimit(100);
+ Query query = Query.fromQL("location within 50000000 of -90, -180" );
+
+ query.setLimit( 100 );
int count = 0;
Results results;
@@ -417,7 +421,7 @@ public class GeoIT extends AbstractCoreIT {
while (results.getCursor() != null);
// check we got back all 500 entities
- assertEquals(numEntities, count);
+ assertEquals( numEntities, count );
}
@@ -441,11 +445,10 @@ public class GeoIT extends AbstractCoreIT {
app.refreshIndex();
- Query query = new Query();
// earth's circumference is 40,075 kilometers. Up it to 50,000kilometers
- // just to be save
- query.addFilter("location within 50000000 of 0, 0");
- query.setLimit(100);
+ // just to be save
+ Query query = Query.fromQL("location within 50000000 of 0, 0" );
+ query.setLimit( 100 );
int count = 0;
Results results;
@@ -502,10 +505,10 @@ public class GeoIT extends AbstractCoreIT {
app.refreshIndex();
- Query query = new Query();
- // earth's circumference is 40,075 kilometers. Up it to 50,000kilometers
+ // earth's circumference is 40,075 kilometers. Up it to 50,000kilometers
// just to be save
- query.addFilter("location within 50000000 of -90, -180");
+ Query query = Query.fromQL( "location within 50000000 of -90, -180" );
+
query.setLimit(100);
int count = 0;
@@ -529,7 +532,7 @@ public class GeoIT extends AbstractCoreIT {
public void testGeoWithIntersection() throws Exception {
EntityManager em = app.getEntityManager();
- assertNotNull(em);
+ assertNotNull( em );
int size = 100;
int min = 50;
@@ -643,9 +646,7 @@ public class GeoIT extends AbstractCoreIT {
long startTime = System.currentTimeMillis();
//now test at the EM level, there should be 0 results.
- Query query = new Query();
-
- query.addFilter("location within 1000 of 48.38626, 9.94175"); // lat, lon
+ Query query = Query.fromQL( "location within 1000 of 48.38626, 9.94175");
query.setLimit(limit);
Results results = em.searchCollection(em.getApplicationRef(), "stores", query);
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e534d9c7/stack/core/src/test/java/org/apache/usergrid/persistence/GeoQueryBooleanTest.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/GeoQueryBooleanTest.java b/stack/core/src/test/java/org/apache/usergrid/persistence/GeoQueryBooleanTest.java
index 3dfab3f..8d01754 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/GeoQueryBooleanTest.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/GeoQueryBooleanTest.java
@@ -26,12 +26,8 @@ import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.apache.commons.lang3.RandomStringUtils;
import org.apache.usergrid.AbstractCoreIT;
-import org.apache.usergrid.persistence.geo.model.Point;
-import org.apache.usergrid.persistence.index.query.Query;
-import org.apache.usergrid.persistence.model.util.UUIDGenerator;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -87,22 +83,23 @@ public class GeoQueryBooleanTest extends AbstractCoreIT {
app.refreshIndex();
// define center point about 300m from that location
- Point center = new Point( 37.774277, -122.404744 );
+ final double lat = 37.774277;
+ final double lon = -122.404744 ;
Query query = Query.fromQL( "select * where location within 400 of "
- + center.getLat() + "," + center.getLon());
+ + lat + "," + lon);
Results listResults = em.searchCollection( em.getApplicationRef(), "users", query );
assertEquals( 2, listResults.size() );
query = Query.fromQL( "select * where employer='Apigee' or location within 100 of "
- + center.getLat() + "," + center.getLon());
+ + lat + "," + lon);
listResults = em.searchCollection( em.getApplicationRef(), "users", query );
// no results because geo filter applied after query even in the case or 'or'
assertEquals( 0, listResults.size() );
query = Query.fromQL( "select * where employer='Apigee' or location within 400 of "
- + center.getLat() + "," + center.getLon());
+ + lat + "," + lon);
listResults = em.searchCollection( em.getApplicationRef(), "users", query );
// only one result because geo filter applied after query even in the case or 'or'
@@ -166,19 +163,20 @@ public class GeoQueryBooleanTest extends AbstractCoreIT {
app.refreshIndex();
// define center point about 300m from that location
- Point center = new Point( 37.774277, -122.404744 );
+ final double lat = 37.774277;
+ final double lon = -122.404744 ;
// one user within 400 meters IS NOT blocked by bart
Query query = Query.fromQL(
"select * where NOT blockedBy.name='bart' and location within 400 of "
- + center.getLat() + "," + center.getLon());
+ + lat + "," + lon);
Results listResults = em.searchCollection( em.getApplicationRef(), "users", query );
assertEquals( 1, listResults.size() );
// one user within 400 meters IS blocked by bart
query = Query.fromQL(
"select * where blockedBy.name='bart' and location within 400 of "
- + center.getLat() + "," + center.getLon());
+ + lat + "," + lon);
listResults = em.searchCollection( em.getApplicationRef(), "users", query );
assertEquals( 1, listResults.size() );