Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JoinTo annotation #1006

Merged
merged 8 commits into from
Oct 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
import com.yahoo.elide.core.DataStore;
import com.yahoo.elide.core.DataStoreTransaction;
import com.yahoo.elide.core.EntityDictionary;
import com.yahoo.elide.core.RequestScope;
import com.yahoo.elide.datastores.aggregation.schema.Schema;
import com.yahoo.elide.request.EntityProjection;

/**
* DataStore that supports Aggregation. Uses {@link QueryEngine} to return results.
Expand All @@ -30,10 +27,4 @@ public AggregationDataStore(QueryEngine queryEngine) {
public DataStoreTransaction beginTransaction() {
return new AggregationDataStoreTransaction(queryEngine);
}

public static Query buildQuery(EntityProjection entityProjection, RequestScope scope) {
Schema schema = new Schema(entityProjection.getType(), scope.getDictionary());
AggregationDataStoreHelper agHelper = new AggregationDataStoreHelper(schema, entityProjection);
return agHelper.getQuery();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@

import com.yahoo.elide.core.DataStoreTransaction;
import com.yahoo.elide.core.RequestScope;
import com.yahoo.elide.datastores.aggregation.schema.Schema;
import com.yahoo.elide.request.EntityProjection;

import com.google.common.annotations.VisibleForTesting;

import java.io.IOException;

/**
Expand Down Expand Up @@ -48,12 +51,20 @@ public void createObject(Object entity, RequestScope scope) {

@Override
public Iterable<Object> loadObjects(EntityProjection entityProjection, RequestScope scope) {
Query query = AggregationDataStore.buildQuery(entityProjection, scope);
Query query = buildQuery(entityProjection, scope);
return queryEngine.executeQuery(query);
}

@Override
public void close() throws IOException {

}

@VisibleForTesting
Query buildQuery(EntityProjection entityProjection, RequestScope scope) {
Schema schema = queryEngine.getSchema(entityProjection.getType());

AggregationDataStoreHelper agHelper = new AggregationDataStoreHelper(schema, entityProjection);
return agHelper.getQuery();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import com.yahoo.elide.core.DataStore;
import com.yahoo.elide.core.DataStoreTransaction;
import com.yahoo.elide.datastores.aggregation.schema.Schema;

/**
* A {@link QueryEngine} is an abstraction that an AggregationDataStore leverages to run analytic queries (OLAP style)
Expand Down Expand Up @@ -49,7 +50,6 @@
* <p>
* This is a {@link java.util.function functional interface} whose functional method is {@link #executeQuery(Query)}.
*/
@FunctionalInterface
public interface QueryEngine {

/**
Expand All @@ -61,4 +61,11 @@ public interface QueryEngine {
* @return query results
*/
Iterable<Object> executeQuery(Query query);

/**
* Returns the schema for a given entity class.
* @param entityClass The class to map to a schema.
* @return The schema that represents the provided entity.
*/
Schema getSchema(Class<?> entityClass);
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,12 @@ protected Map<Object, Object> getRelationshipValues(
.getResultList();

return loaded.stream()
.map(obj -> new AbstractMap.SimpleImmutableEntry<>(CoerceUtil.coerce((Object) getEntityDictionary()
.getId(obj), getEntityDictionary().getIdType(relationshipType)), obj))
.map(obj -> new AbstractMap.SimpleImmutableEntry<>(
CoerceUtil.coerce(
(Object) getEntityDictionary().getId(obj),
getEntityDictionary().getIdType(relationshipType)
),
obj))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}
}
Loading