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

fix: SpannerStatementQueryExecutor query generation for IsNotNull conditions #1171

Merged
merged 2 commits into from
Jun 17, 2022
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 @@ -689,7 +689,7 @@ private static void buildWhere(
andString += "<" + insertedTag;
break;
case IS_NOT_NULL:
andString += "<>NULL";
andString += " IS NOT NULL";
break;
case LESS_THAN_EQUAL:
andString += "<=" + insertedTag;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,17 @@ void findAllByIdReturnsNothingOnEmptyRequestIterable() {
assertThat(foundTrades).isEmpty();
}

@Test
void findAllByActionIsNotNull() {
insertTrades("trader1", "SELL", 2);
insertTrades("trader2", null, 3);

assertThat(this.tradeRepository.count()).isEqualTo(5L);

List<Trade> tradesWithActionNotNull = this.tradeRepository.findAllByActionIsNotNull("not used");
assertThat(tradesWithActionNotNull).hasSize(2);
}

private List<Trade> insertTrades(String traderId, String action, int numTrades) {
List<Trade> trades = new ArrayList<>();
for (int i = 0; i < numTrades; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ void compoundNameConventionTest() throws NoSuchMethodException {
String expectedQuery =
"SELECT DISTINCT shares, trader_id, ticker, price, action, id, value FROM trades"
+ " WHERE ( LOWER(action)=LOWER(@tag0) AND ticker=@tag1 ) OR ("
+ " trader_id=@tag2 AND price<@tag3 ) OR ( price>=@tag4 AND id<>NULL AND"
+ " trader_id=@tag2 AND price<@tag3 ) OR ( price>=@tag4 AND id IS NOT NULL AND"
+ " trader_id=NULL AND trader_id LIKE @tag7 AND price=TRUE AND price=FALSE"
+ " AND price>@tag10 AND price<=@tag11 AND price IN UNNEST(@tag12) AND"
+ " value<@tag13 ) ORDER BY id DESC LIMIT 3";
Expand Down Expand Up @@ -231,7 +231,7 @@ void compoundNameConventionCountTest() throws NoSuchMethodException {
String expectedSql =
"SELECT EXISTS(SELECT DISTINCT shares, trader_id, ticker, price, action, id,"
+ " value FROM trades WHERE ( LOWER(action)=LOWER(@tag0) AND ticker=@tag1 )"
+ " OR ( trader_id=@tag2 AND price<@tag3 ) OR ( price>=@tag4 AND id<>NULL AND"
+ " OR ( trader_id=@tag2 AND price<@tag3 ) OR ( price>=@tag4 AND id IS NOT NULL AND"
+ " trader_id=NULL AND trader_id LIKE @tag7 AND price=TRUE AND price=FALSE"
+ " AND price>@tag10 AND price<=@tag11 ) ORDER BY id DESC LIMIT 1)";
assertThat(statement.getSql()).isEqualTo(expectedSql);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ void compoundNameConventionTest() throws NoSuchMethodException {
+ " WHERE price=#{#tag3 * -1} AND price<>#{#tag3 * -1} OR "
+ "price<>#{#tag4 * -1} AND "
+ "( action=@tag0 AND ticker=@tag1 ) OR "
+ "( trader_id=@tag2 AND price<@tag3 ) OR ( price>=@tag4 AND id<>NULL AND "
+ "( trader_id=@tag2 AND price<@tag3 ) OR ( price>=@tag4 AND id IS NOT NULL AND "
+ "trader_id=NULL AND trader_id LIKE %@tag5 AND price=TRUE AND price=FALSE AND "
+ "struct_val = @tag8 AND struct_val = @tag9 "
+ "price>@tag6 AND price<=@tag7 and price in unnest(@tag10)) ORDER BY id DESC LIMIT 3;";
Expand All @@ -396,7 +396,7 @@ void compoundNameConventionTest() throws NoSuchMethodException {
+ " children FROM (SELECT DISTINCT * FROM trades@{index=fakeindex} WHERE"
+ " price=@SpELtag1 AND price<>@SpELtag1 OR price<>@SpELtag2 AND ( action=@tag0 AND"
+ " ticker=@tag1 ) OR ( trader_id=@tag2 AND price<@tag3 ) OR ( price>=@tag4 AND"
+ " id<>NULL AND trader_id=NULL AND trader_id LIKE %@tag5 AND price=TRUE AND"
+ " id IS NOT NULL AND trader_id=NULL AND trader_id LIKE %@tag5 AND price=TRUE AND"
+ " price=FALSE AND struct_val = @tag8 AND struct_val = @tag9 price>@tag6 AND"
+ " price<=@tag7 and price in unnest(@tag10)) ORDER BY id DESC LIMIT 3) trades ORDER BY"
+ " COLA ASC , COLB DESC LIMIT 10 OFFSET 30";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ public interface TradeRepository extends SpannerRepository<Trade, Key> {

List<Trade> findBySymbolNotContains(String symbolFragment);

List<Trade> findAllByActionIsNotNull(String actionNotUsed);

@Query(
"SELECT * FROM :com.google.cloud.spring.data.spanner.test.domain.Trade:"
+ " WHERE STRUCT(symbol,action) = @pairTag ORDER BY LOWER(action) DESC")
Expand Down