Skip to content

Commit 8d7c9b2

Browse files
authored
Merge pull request #444 from FgForrest/dev
Hotfix release - regression
2 parents 15b75a9 + fda6075 commit 8d7c9b2

File tree

7 files changed

+94
-7
lines changed

7 files changed

+94
-7
lines changed

documentation/research/en/assignment/model/data_types.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ evitaDB data types are limited to following list:
2525
- [BigDecimal](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/math/BigDecimal.html), formatted as `1.124`
2626
- [OffsetDateTime](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/time/OffsetDateTime.html), formatted as `2021-01-01T00:00:00+01:00` ([offset needs to be maintained](https://spin.atomicobject.com/2016/07/06/time-zones-offsets/))
2727
- [LocalDateTime](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/time/LocalDateTime.html), formatted as `2021-01-01T00:00:00`
28-
- [LocalDate](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/time/LocalDate.html), formatted as `00:00:00`
29-
- [LocalTime](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/time/LocalTime.html), formatted as `2021-01-01`
28+
- [LocalDate](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/time/LocalDate.html), formatted as `2021-01-01`
29+
- [LocalTime](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/time/LocalTime.html), formatted as `00:00:00`
3030
- [DateTimeRange](#datetimerange), formatted as `[2021-01-01T00:00:00+01:00,2022-01-01T00:00:00+01:00]`
3131
- [BigDecimalNumberRange](#numberrange), formatted as `[1.24,78]`
3232
- [LongNumberRange](#numberrange), formatted as `[5,9]`

documentation/user/en/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,4 @@ the first version to the general public.
129129
1. [With product listing](solve/render-referenced-brand.md#product-listing)
130130
2. [With involved categories listing](solve/render-referenced-brand.md#category-listing)
131131
4. [Handle images & binaries](solve/handling-images-binaries.md)
132-
5. [Model price policies](solve/model-price-policies.md)
132+
5. [Model price policies](solve/model-price-policies.md)

documentation/user/en/use/data-types.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ evitaDB data types are limited to following list:
4747
- [LocalDateTime](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/time/LocalDateTime.html),
4848
formatted as `2021-01-01T00:00:00`
4949
- [LocalDate](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/time/LocalDate.html),
50-
formatted as `00:00:00`
51-
- [LocalTime](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/time/LocalTime.html),
5250
formatted as `2021-01-01`
51+
- [LocalTime](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/time/LocalTime.html),
52+
formatted as `00:00:00`
5353
- [DateTimeRange](#datetimerange),
5454
formatted as `[2021-01-01T00:00:00+01:00,2022-01-01T00:00:00+01:00]`
5555
- [BigDecimalNumberRange](#numberrange),

evita_functional_tests/src/test/java/io/evitadb/api/query/filter/AttributeInSetTest.java

+19
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,25 @@ void shouldCreateViaFactoryClassWorkAsExpected() {
4141
assertArrayEquals(new Comparable<?>[] {1, 5}, attributeInSet.getAttributeValues());
4242
}
4343

44+
@Test
45+
void shouldCreateViaFactoryClassWorkAsExpectedNullInArray() {
46+
final AttributeInSet attributeInSet = attributeInSet("refs", 1, null, 5);
47+
assertArrayEquals(new Comparable<?>[] {1, 5}, attributeInSet.getAttributeValues());
48+
}
49+
50+
@Test
51+
void shouldCreateViaFactoryClassWorkAsExpectedForNullVariable() {
52+
final Integer nullInteger = null;
53+
final AttributeInSet attributeInSet = attributeInSet("refs", nullInteger);
54+
assertNull(attributeInSet);
55+
}
56+
57+
@Test
58+
void shouldCreateViaFactoryClassWorkAsExpectedNullValueInArray() {
59+
final AttributeInSet attributeInSet = attributeInSet("refs", new Integer[0]);
60+
assertArrayEquals(new Comparable<?>[0], attributeInSet.getAttributeValues());
61+
}
62+
4463
@Test
4564
void shouldRecognizeApplicability() {
4665
assertFalse(new AttributeInSet(null).isApplicable());

evita_functional_tests/src/test/java/io/evitadb/api/query/filter/EntityPrimaryKeyInSetTest.java

+19
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,25 @@ void shouldCreateViaFactoryClassWorkAsExpected() {
4141
assertArrayEquals(new int[] {1, 5, 7}, entityPrimaryKeyInSet.getPrimaryKeys());
4242
}
4343

44+
@Test
45+
void shouldCreateViaFactoryClassWorkAsExpectedNullInArray() {
46+
final EntityPrimaryKeyInSet entityPrimaryKeyInSet = entityPrimaryKeyInSet(1, null, 7);
47+
assertArrayEquals(new int[] {1, 7}, entityPrimaryKeyInSet.getPrimaryKeys());
48+
}
49+
50+
@Test
51+
void shouldCreateViaFactoryClassWorkAsExpectedForNullVariable() {
52+
final Integer nullInteger = null;
53+
final EntityPrimaryKeyInSet entityPrimaryKeyInSet = entityPrimaryKeyInSet(nullInteger);
54+
assertNull(entityPrimaryKeyInSet);
55+
}
56+
57+
@Test
58+
void shouldCreateViaFactoryClassWorkAsExpectedNullValueInArray() {
59+
final EntityPrimaryKeyInSet entityPrimaryKeyInSet = entityPrimaryKeyInSet(new Integer[0]);
60+
assertArrayEquals(new int[0], entityPrimaryKeyInSet.getPrimaryKeys());
61+
}
62+
4463
@Test
4564
void shouldRecognizeApplicability() {
4665
assertTrue(new EntityPrimaryKeyInSet().isApplicable());

evita_functional_tests/src/test/java/io/evitadb/api/query/filter/PriceInPriceListsTest.java

+19
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,25 @@ void shouldCreateViaFactoryClassWorkAsExpected() {
4141
assertArrayEquals(new String[] {"basic", "reference"}, priceInPriceLists.getPriceLists());
4242
}
4343

44+
@Test
45+
void shouldCreateViaFactoryClassWorkAsExpectedNullInArray() {
46+
final PriceInPriceLists priceInPriceLists = priceInPriceLists("basic", null, "reference");
47+
assertArrayEquals(new String[] {"basic", "reference"}, priceInPriceLists.getPriceLists());
48+
}
49+
50+
@Test
51+
void shouldCreateViaFactoryClassWorkAsExpectedForNullVariable() {
52+
final String nullString = null;
53+
final PriceInPriceLists priceInPriceLists = priceInPriceLists(nullString);
54+
assertNull(priceInPriceLists);
55+
}
56+
57+
@Test
58+
void shouldCreateViaFactoryClassWorkAsExpectedNullValueInArray() {
59+
final PriceInPriceLists priceInPriceLists = priceInPriceLists(new String[0]);
60+
assertArrayEquals(new String[0], priceInPriceLists.getPriceLists());
61+
}
62+
4463
@Test
4564
void shouldRecognizeApplicability() {
4665
assertTrue(new PriceInPriceLists(new String[0]).isApplicable());

evita_query/src/main/java/io/evitadb/api/query/QueryConstraints.java

+32-2
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,19 @@ static PriceInPriceLists priceInPriceLists(@Nullable String... priceList) {
690690
if (priceList == null) {
691691
return null;
692692
}
693-
return new PriceInPriceLists(priceList);
693+
// if the array is empty - it was deliberate action which needs to produce empty result of the query
694+
if (priceList.length == 0) {
695+
return new PriceInPriceLists(priceList);
696+
}
697+
final String[] normalizeNames = Arrays.stream(priceList).filter(Objects::nonNull).filter(it -> !it.isBlank()).toArray(String[]::new);
698+
// the array was not empty, but contains only null values - this may not be deliberate action - for example
699+
// the initalization was like `priceInPriceLists(nullVariable)` and this should exclude the constraint
700+
if (normalizeNames.length == 0) {
701+
return null;
702+
}
703+
// otherwise propagate only non-null values
704+
return normalizeNames.length == priceList.length ?
705+
new PriceInPriceLists(priceList) : new PriceInPriceLists(normalizeNames);
694706
}
695707

696708
/**
@@ -1537,13 +1549,19 @@ static AttributeInRange attributeInRangeNow(@Nullable String attributeName) {
15371549
@SuppressWarnings("unchecked")
15381550
@Nullable
15391551
static <T extends Serializable> AttributeInSet attributeInSet(@Nullable String attributeName, @Nullable T... set) {
1552+
// if the array is empty - it was deliberate action which needs to produce empty result of the query
15401553
if (attributeName == null || set == null) {
15411554
return null;
15421555
}
15431556
final List<T> args = Arrays.stream(set).filter(Objects::nonNull).toList();
15441557
if (args.size() == set.length) {
15451558
return new AttributeInSet(attributeName, set);
1559+
} else if (args.isEmpty()) {
1560+
// the array was not empty, but contains only null values - this may not be deliberate action - for example
1561+
// the initalization was like `attributeInSet("attrName", nullVariable)` and this should exclude the constraint
1562+
return null;
15461563
} else {
1564+
// otherwise propagate only non-null values
15471565
final T[] limitedSet = (T[]) Array.newInstance(set.getClass().getComponentType(), args.size());
15481566
for (int i = 0; i < args.size(); i++) {
15491567
limitedSet[i] = args.get(i);
@@ -1805,7 +1823,19 @@ static EntityPrimaryKeyInSet entityPrimaryKeyInSet(@Nullable Integer... primaryK
18051823
if (primaryKey == null) {
18061824
return null;
18071825
}
1808-
return new EntityPrimaryKeyInSet(primaryKey);
1826+
// if the array is empty - it was deliberate action which needs to produce empty result of the query
1827+
if (primaryKey.length == 0) {
1828+
return new EntityPrimaryKeyInSet(primaryKey);
1829+
}
1830+
final Integer[] normalizedPks = Arrays.stream(primaryKey).filter(Objects::nonNull).toArray(Integer[]::new);
1831+
// the array was not empty, but contains only null values - this may not be deliberate action - for example
1832+
// the initalization was like `entityPrimaryKeyInSet(nullVariable)` and this should exclude the constraint
1833+
if (normalizedPks.length == 0) {
1834+
return null;
1835+
}
1836+
// otherwise propagate only non-null values
1837+
return normalizedPks.length == primaryKey.length ?
1838+
new EntityPrimaryKeyInSet(primaryKey) : new EntityPrimaryKeyInSet(normalizedPks);
18091839
}
18101840

18111841
/**

0 commit comments

Comments
 (0)