use of com.yahoo.elide.core.sort.SortingImpl in project elide by yahoo.
the class RootCollectionFetchQueryBuilderTest method testRootFetchWithRelationshipSortingAndFilters.
@Test
public void testRootFetchWithRelationshipSortingAndFilters() {
Map<String, Sorting.SortOrder> sorting = new HashMap<>();
sorting.put(PUBLISHER + PERIOD + EDITOR + PERIOD + FIRSTNAME, Sorting.SortOrder.desc);
Path.PathElement idPath = new Path.PathElement(Book.class, Chapter.class, "id");
FilterPredicate idPredicate = new InPredicate(idPath, 1);
EntityProjection entityProjection = EntityProjection.builder().type(Book.class).sorting(new SortingImpl(sorting, Book.class, dictionary)).filterExpression(idPredicate).build();
RootCollectionFetchQueryBuilder builder = new RootCollectionFetchQueryBuilder(entityProjection, dictionary, new TestSessionWrapper());
TestQueryWrapper query = (TestQueryWrapper) builder.build();
String expected = "SELECT example_Book FROM example.Book AS example_Book" + " LEFT JOIN example_Book.publisher example_Book_publisher" + " LEFT JOIN example_Book_publisher.editor example_Book_publisher_editor" + " WHERE example_Book.id IN (:id_XXX)" + " order by example_Book_publisher_editor.firstName desc";
String actual = query.getQueryText();
actual = actual.trim().replaceAll(" +", " ");
actual = actual.replaceFirst(":id_\\w+", ":id_XXX");
assertEquals(expected, actual);
}
use of com.yahoo.elide.core.sort.SortingImpl 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.sort.SortingImpl in project elide by yahoo.
the class DefaultQueryValidatorTest method testSortingOnNotQueriedMetric.
@Test
public void testSortingOnNotQueriedMetric() {
Map<String, Sorting.SortOrder> sortMap = new TreeMap<>();
sortMap.put("highScore", Sorting.SortOrder.asc);
Query query = Query.builder().source(playerStatsTable).metricProjection(playerStatsTable.getMetricProjection("lowScore")).dimensionProjection(playerStatsTable.getDimensionProjection("overallRating")).sorting(new SortingImpl(sortMap, PlayerStats.class, dictionary)).build();
validateQuery(query, "Invalid operation: Can not sort on highScore as it is not present in query");
}
use of com.yahoo.elide.core.sort.SortingImpl in project elide by yahoo.
the class DefaultQueryValidatorTest method testSortingOnId.
@Test
public void testSortingOnId() {
Map<String, Sorting.SortOrder> sortMap = new TreeMap<>();
sortMap.put("id", Sorting.SortOrder.asc);
Query query = Query.builder().source(playerStatsTable).metricProjection(playerStatsTable.getMetricProjection("lowScore")).metricProjection(playerStatsTable.getMetricProjection("id")).dimensionProjection(playerStatsTable.getDimensionProjection("overallRating")).sorting(new SortingImpl(sortMap, PlayerStats.class, dictionary)).build();
validateQuery(query, "Invalid operation: Sorting on id field is not permitted");
}
use of com.yahoo.elide.core.sort.SortingImpl in project elide by yahoo.
the class QueryKeyExtractorTest method testFullQuery.
@Test
public void testFullQuery() throws Exception {
RSQLFilterDialect filterParser = RSQLFilterDialect.builder().dictionary(dictionary).build();
Map<String, Sorting.SortOrder> sortMap = new TreeMap<>();
sortMap.put("playerName", Sorting.SortOrder.asc);
Query query = Query.builder().source(playerStatsTable).metricProjection(playerStatsTable.getMetricProjection("highScore")).dimensionProjection(playerStatsTable.getDimensionProjection("overallRating")).timeDimensionProjection(playerStatsTable.getTimeDimensionProjection("recordedDate")).whereFilter(filterParser.parseFilterExpression("countryNickName=='Uncle Sam'", ClassType.of(PlayerStats.class), false)).havingFilter(filterParser.parseFilterExpression("highScore > 300", ClassType.of(PlayerStats.class), false)).sorting(new SortingImpl(sortMap, PlayerStats.class, dictionary)).pagination(new ImmutablePagination(0, 2, false, true)).build();
assertEquals(// table name
"example_PlayerStats;" + // columns
"{highScore;{}}" + // group by
"{overallRating;{}}" + // time dimensions
"{recordedDate;{}}" + // where
"{P;{{example.PlayerStats;java.lang.String;countryNickName;}}IN;9;Uncle Sam;}" + // having
"{P;{{example.PlayerStats;long;highScore;}}GT;3;300;}" + // sort
"{example.PlayerStats;{{example.PlayerStats;java.lang.String;playerName;}}asc;}" + // pagination
"{0;2;1;}", QueryKeyExtractor.extractKey(query));
}
Aggregations