use of com.yahoo.elide.core.request.EntityProjection in project elide by yahoo.
the class SubCollectionFetchQueryBuilderTest method testSubCollectionFetchWithSortingAndFilters.
@Test
public void testSubCollectionFetchWithSortingAndFilters() {
Author author = new Author();
author.setId(1L);
Book book = new Book();
book.setId(2);
List<Path.PathElement> publisherNamePath = Arrays.asList(new Path.PathElement(Book.class, Publisher.class, PUBLISHER), new Path.PathElement(Publisher.class, String.class, NAME));
FilterPredicate publisherNamePredicate = new InPredicate(new Path(publisherNamePath), PUB1);
Map<String, Sorting.SortOrder> sorting = new HashMap<>();
sorting.put(TITLE, Sorting.SortOrder.asc);
EntityProjection entityProjection = EntityProjection.builder().type(Book.class).filterExpression(publisherNamePredicate).sorting(new SortingImpl(sorting, Book.class, dictionary)).build();
Relationship relationshipProjection = Relationship.builder().name(BOOKS).projection(entityProjection).build();
RelationshipImpl relationship = new RelationshipImpl(ClassType.of(Author.class), author, relationshipProjection);
SubCollectionFetchQueryBuilder builder = new SubCollectionFetchQueryBuilder(relationship, dictionary, new TestSessionWrapper());
TestQueryWrapper query = (TestQueryWrapper) builder.build();
String expected = "SELECT example_Book FROM example.Author example_Author__fetch " + "JOIN example_Author__fetch.books example_Book " + "LEFT JOIN example_Book.publisher example_Book_publisher " + "WHERE example_Book_publisher.name IN (:publisher_name_XXX) AND example_Author__fetch=:example_Author__fetch order by example_Book.title asc";
String actual = query.getQueryText();
actual = actual.replaceFirst(":publisher_name_\\w+", ":publisher_name_XXX");
actual = actual.trim().replaceAll(" +", " ");
assertEquals(expected, actual);
}
use of com.yahoo.elide.core.request.EntityProjection in project elide by yahoo.
the class SubCollectionFetchQueryBuilderTest method testSubCollectionFetch.
@Test
public void testSubCollectionFetch() {
Author author = new Author();
author.setId(1L);
Book book = new Book();
book.setId(2);
EntityProjection entityProjection = EntityProjection.builder().type(Book.class).build();
Relationship relationshipProjection = Relationship.builder().name(BOOKS).projection(entityProjection).build();
RelationshipImpl relationship = new RelationshipImpl(ClassType.of(Author.class), author, relationshipProjection);
SubCollectionFetchQueryBuilder builder = new SubCollectionFetchQueryBuilder(relationship, dictionary, new TestSessionWrapper());
TestQueryWrapper query = (TestQueryWrapper) builder.build();
assertNull(query);
}
use of com.yahoo.elide.core.request.EntityProjection in project elide by yahoo.
the class SubCollectionPageTotalsQueryBuilderTest method testSubCollectionPageTotalsWithSorting.
@Test
public void testSubCollectionPageTotalsWithSorting() {
Author author = new Author();
author.setId(1L);
Book book = new Book();
book.setId(2);
Sorting sorting = mock(Sorting.class);
EntityProjection entityProjection = EntityProjection.builder().type(Book.class).sorting(sorting).build();
Relationship relationshipProjection = Relationship.builder().name(BOOKS).projection(entityProjection).build();
RelationshipImpl relationship = new RelationshipImpl(ClassType.of(Author.class), author, relationshipProjection);
TestQueryWrapper query = (TestQueryWrapper) new SubCollectionPageTotalsQueryBuilder(relationship, dictionary, new TestSessionWrapper()).build();
String expected = "SELECT COUNT(DISTINCT example_Author_books) " + "FROM example.Author AS example_Author " + "JOIN example_Author.books example_Author_books " + "WHERE example_Author.id IN (:id_XXX)";
String actual = query.getQueryText();
actual = actual.trim().replaceAll(" +", " ");
actual = actual.replaceFirst(":id_\\w+", ":id_XXX");
assertEquals(expected, actual);
}
use of com.yahoo.elide.core.request.EntityProjection in project elide by yahoo.
the class SubCollectionPageTotalsQueryBuilderTest method testSubCollectionPageTotalsWithJoinFilter.
@Test
public void testSubCollectionPageTotalsWithJoinFilter() {
Author author = new Author();
author.setId(1L);
Book book = new Book();
book.setId(2);
List<Path.PathElement> publisherNamePath = Arrays.asList(new Path.PathElement(Book.class, Publisher.class, PUBLISHER), new Path.PathElement(Publisher.class, String.class, "name"));
FilterPredicate publisherNamePredicate = new InPredicate(new Path(publisherNamePath), "Pub1");
EntityProjection entityProjection = EntityProjection.builder().type(Book.class).filterExpression(publisherNamePredicate).build();
Relationship relationshipProjection = Relationship.builder().name(BOOKS).projection(entityProjection).build();
RelationshipImpl relationship = new RelationshipImpl(ClassType.of(Author.class), author, relationshipProjection);
SubCollectionPageTotalsQueryBuilder builder = new SubCollectionPageTotalsQueryBuilder(relationship, dictionary, new TestSessionWrapper());
TestQueryWrapper query = (TestQueryWrapper) builder.build();
String expected = "SELECT COUNT(DISTINCT example_Author_books) " + "FROM example.Author AS example_Author " + "LEFT JOIN example_Author.books example_Author_books " + "LEFT JOIN example_Author_books.publisher example_Author_books_publisher " + "WHERE (example_Author_books_publisher.name IN (:books_publisher_name_XXX) " + "AND example_Author.id IN (:id_XXX))";
String actual = query.getQueryText();
actual = actual.replaceFirst(":books_publisher_name_\\w+", ":books_publisher_name_XXX");
actual = actual.trim().replaceAll(" +", " ");
actual = actual.replaceFirst(":id_\\w+", ":id_XXX");
assertEquals(expected, actual);
}
use of com.yahoo.elide.core.request.EntityProjection in project elide by yahoo.
the class AggregationDataStoreTransactionTest method loadObjectsExceptionThrownTest.
@Test
public void loadObjectsExceptionThrownTest() throws Exception {
Mockito.reset(queryLogger);
String nullPointerExceptionMessage = "Cannot dereference an object with value Null";
try {
query = Query.builder().source(playerStatsTable).bypassingCache(true).build();
doThrow(new NullPointerException(nullPointerExceptionMessage)).when(queryEngine).executeQuery(query, qeTransaction);
AggregationDataStoreTransaction transaction = new MyAggregationDataStoreTransaction(queryEngine, cache, queryLogger);
EntityProjection entityProjection = EntityProjection.builder().type(PlayerStats.class).build();
transaction.loadObjects(entityProjection, scope);
} catch (Exception e) {
assertEquals(nullPointerExceptionMessage, e.getMessage());
Mockito.verify(queryLogger).completeQuery(Mockito.eq(scope.getRequestId()), argThat((QueryResponse qResponse) -> qResponse.getErrorMessage() == e.getMessage()));
}
Mockito.verify(queryLogger, times(1)).acceptQuery(Mockito.eq(scope.getRequestId()), any(), any(), any(), any(), any());
Mockito.verify(queryLogger, times(1)).processQuery(Mockito.eq(scope.getRequestId()), any(), any(), Mockito.eq(false));
Mockito.verify(queryLogger, times(1)).completeQuery(Mockito.eq(scope.getRequestId()), any());
}
Aggregations