Skip to content

Commit

Permalink
Merge pull request #444 from FgForrest/dev
Browse files Browse the repository at this point in the history
Hotfix release - regression
  • Loading branch information
novoj authored Jan 30, 2024
2 parents 15b75a9 + fda6075 commit 8d7c9b2
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 7 deletions.
4 changes: 2 additions & 2 deletions documentation/research/en/assignment/model/data_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ evitaDB data types are limited to following list:
- [BigDecimal](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/math/BigDecimal.html), formatted as `1.124`
- [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/))
- [LocalDateTime](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/time/LocalDateTime.html), formatted as `2021-01-01T00:00:00`
- [LocalDate](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/time/LocalDate.html), formatted as `00:00:00`
- [LocalTime](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/time/LocalTime.html), formatted as `2021-01-01`
- [LocalDate](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/time/LocalDate.html), formatted as `2021-01-01`
- [LocalTime](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/time/LocalTime.html), formatted as `00:00:00`
- [DateTimeRange](#datetimerange), formatted as `[2021-01-01T00:00:00+01:00,2022-01-01T00:00:00+01:00]`
- [BigDecimalNumberRange](#numberrange), formatted as `[1.24,78]`
- [LongNumberRange](#numberrange), formatted as `[5,9]`
Expand Down
2 changes: 1 addition & 1 deletion documentation/user/en/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,4 @@ the first version to the general public.
1. [With product listing](solve/render-referenced-brand.md#product-listing)
2. [With involved categories listing](solve/render-referenced-brand.md#category-listing)
4. [Handle images & binaries](solve/handling-images-binaries.md)
5. [Model price policies](solve/model-price-policies.md)
5. [Model price policies](solve/model-price-policies.md)
4 changes: 2 additions & 2 deletions documentation/user/en/use/data-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ evitaDB data types are limited to following list:
- [LocalDateTime](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/time/LocalDateTime.html),
formatted as `2021-01-01T00:00:00`
- [LocalDate](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/time/LocalDate.html),
formatted as `00:00:00`
- [LocalTime](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/time/LocalTime.html),
formatted as `2021-01-01`
- [LocalTime](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/time/LocalTime.html),
formatted as `00:00:00`
- [DateTimeRange](#datetimerange),
formatted as `[2021-01-01T00:00:00+01:00,2022-01-01T00:00:00+01:00]`
- [BigDecimalNumberRange](#numberrange),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,25 @@ void shouldCreateViaFactoryClassWorkAsExpected() {
assertArrayEquals(new Comparable<?>[] {1, 5}, attributeInSet.getAttributeValues());
}

@Test
void shouldCreateViaFactoryClassWorkAsExpectedNullInArray() {
final AttributeInSet attributeInSet = attributeInSet("refs", 1, null, 5);
assertArrayEquals(new Comparable<?>[] {1, 5}, attributeInSet.getAttributeValues());
}

@Test
void shouldCreateViaFactoryClassWorkAsExpectedForNullVariable() {
final Integer nullInteger = null;
final AttributeInSet attributeInSet = attributeInSet("refs", nullInteger);
assertNull(attributeInSet);
}

@Test
void shouldCreateViaFactoryClassWorkAsExpectedNullValueInArray() {
final AttributeInSet attributeInSet = attributeInSet("refs", new Integer[0]);
assertArrayEquals(new Comparable<?>[0], attributeInSet.getAttributeValues());
}

@Test
void shouldRecognizeApplicability() {
assertFalse(new AttributeInSet(null).isApplicable());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,25 @@ void shouldCreateViaFactoryClassWorkAsExpected() {
assertArrayEquals(new int[] {1, 5, 7}, entityPrimaryKeyInSet.getPrimaryKeys());
}

@Test
void shouldCreateViaFactoryClassWorkAsExpectedNullInArray() {
final EntityPrimaryKeyInSet entityPrimaryKeyInSet = entityPrimaryKeyInSet(1, null, 7);
assertArrayEquals(new int[] {1, 7}, entityPrimaryKeyInSet.getPrimaryKeys());
}

@Test
void shouldCreateViaFactoryClassWorkAsExpectedForNullVariable() {
final Integer nullInteger = null;
final EntityPrimaryKeyInSet entityPrimaryKeyInSet = entityPrimaryKeyInSet(nullInteger);
assertNull(entityPrimaryKeyInSet);
}

@Test
void shouldCreateViaFactoryClassWorkAsExpectedNullValueInArray() {
final EntityPrimaryKeyInSet entityPrimaryKeyInSet = entityPrimaryKeyInSet(new Integer[0]);
assertArrayEquals(new int[0], entityPrimaryKeyInSet.getPrimaryKeys());
}

@Test
void shouldRecognizeApplicability() {
assertTrue(new EntityPrimaryKeyInSet().isApplicable());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,25 @@ void shouldCreateViaFactoryClassWorkAsExpected() {
assertArrayEquals(new String[] {"basic", "reference"}, priceInPriceLists.getPriceLists());
}

@Test
void shouldCreateViaFactoryClassWorkAsExpectedNullInArray() {
final PriceInPriceLists priceInPriceLists = priceInPriceLists("basic", null, "reference");
assertArrayEquals(new String[] {"basic", "reference"}, priceInPriceLists.getPriceLists());
}

@Test
void shouldCreateViaFactoryClassWorkAsExpectedForNullVariable() {
final String nullString = null;
final PriceInPriceLists priceInPriceLists = priceInPriceLists(nullString);
assertNull(priceInPriceLists);
}

@Test
void shouldCreateViaFactoryClassWorkAsExpectedNullValueInArray() {
final PriceInPriceLists priceInPriceLists = priceInPriceLists(new String[0]);
assertArrayEquals(new String[0], priceInPriceLists.getPriceLists());
}

@Test
void shouldRecognizeApplicability() {
assertTrue(new PriceInPriceLists(new String[0]).isApplicable());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,19 @@ static PriceInPriceLists priceInPriceLists(@Nullable String... priceList) {
if (priceList == null) {
return null;
}
return new PriceInPriceLists(priceList);
// if the array is empty - it was deliberate action which needs to produce empty result of the query
if (priceList.length == 0) {
return new PriceInPriceLists(priceList);
}
final String[] normalizeNames = Arrays.stream(priceList).filter(Objects::nonNull).filter(it -> !it.isBlank()).toArray(String[]::new);
// the array was not empty, but contains only null values - this may not be deliberate action - for example
// the initalization was like `priceInPriceLists(nullVariable)` and this should exclude the constraint
if (normalizeNames.length == 0) {
return null;
}
// otherwise propagate only non-null values
return normalizeNames.length == priceList.length ?
new PriceInPriceLists(priceList) : new PriceInPriceLists(normalizeNames);
}

/**
Expand Down Expand Up @@ -1537,13 +1549,19 @@ static AttributeInRange attributeInRangeNow(@Nullable String attributeName) {
@SuppressWarnings("unchecked")
@Nullable
static <T extends Serializable> AttributeInSet attributeInSet(@Nullable String attributeName, @Nullable T... set) {
// if the array is empty - it was deliberate action which needs to produce empty result of the query
if (attributeName == null || set == null) {
return null;
}
final List<T> args = Arrays.stream(set).filter(Objects::nonNull).toList();
if (args.size() == set.length) {
return new AttributeInSet(attributeName, set);
} else if (args.isEmpty()) {
// the array was not empty, but contains only null values - this may not be deliberate action - for example
// the initalization was like `attributeInSet("attrName", nullVariable)` and this should exclude the constraint
return null;
} else {
// otherwise propagate only non-null values
final T[] limitedSet = (T[]) Array.newInstance(set.getClass().getComponentType(), args.size());
for (int i = 0; i < args.size(); i++) {
limitedSet[i] = args.get(i);
Expand Down Expand Up @@ -1805,7 +1823,19 @@ static EntityPrimaryKeyInSet entityPrimaryKeyInSet(@Nullable Integer... primaryK
if (primaryKey == null) {
return null;
}
return new EntityPrimaryKeyInSet(primaryKey);
// if the array is empty - it was deliberate action which needs to produce empty result of the query
if (primaryKey.length == 0) {
return new EntityPrimaryKeyInSet(primaryKey);
}
final Integer[] normalizedPks = Arrays.stream(primaryKey).filter(Objects::nonNull).toArray(Integer[]::new);
// the array was not empty, but contains only null values - this may not be deliberate action - for example
// the initalization was like `entityPrimaryKeyInSet(nullVariable)` and this should exclude the constraint
if (normalizedPks.length == 0) {
return null;
}
// otherwise propagate only non-null values
return normalizedPks.length == primaryKey.length ?
new EntityPrimaryKeyInSet(primaryKey) : new EntityPrimaryKeyInSet(normalizedPks);
}

/**
Expand Down

0 comments on commit 8d7c9b2

Please sign in to comment.