Skip to content

FMWK-79 Support native Aerospike Key types (false by default) #660

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

Merged
merged 28 commits into from
Dec 6, 2023

Conversation

roimenashe
Copy link
Member

This PR is still a draft, investigating whether we should support (and test) the following types:
short (primitive)
Short (primitive wrapper)
byte
char

# Conflicts:
#	src/main/java/org/springframework/data/aerospike/config/AerospikeDataSettings.java
…r store as it is if the type is natively supported
@roimenashe roimenashe marked this pull request as ready for review November 23, 2023 13:02
@@ -15,10 +16,31 @@ public static KeyAssert assertThat(Key key) {
}

@SuppressWarnings("UnusedReturnValue")
public KeyAssert consistsOf(String namespace, String setName, Object userKey) {
public KeyAssert consistsOf(AerospikeDataSettings aerospikeDataSettings, String namespace, String setName,
Object expectedUserKey) {
Assertions.assertThat(actual.namespace).isEqualTo(namespace);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace this assertj (shouldn't be used in production code) call with something like:

if (!actual.namespace.equals(namespace)) {
    throw new IllegalArgumentException("Inconsistent namespace name");
}

@@ -15,10 +16,31 @@ public static KeyAssert assertThat(Key key) {
}

@SuppressWarnings("UnusedReturnValue")
public KeyAssert consistsOf(String namespace, String setName, Object userKey) {
public KeyAssert consistsOf(AerospikeDataSettings aerospikeDataSettings, String namespace, String setName,
Object expectedUserKey) {
Assertions.assertThat(actual.namespace).isEqualTo(namespace);
Assertions.assertThat(actual.setName).isEqualTo(setName);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

} else {
// String type is used for unsupported Aerospike key types and previously for all key types in older
// versions of Spring Data Aerospike
Assertions.assertThat(checkIfActualUserKeyTypeIsString()).isTrue();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use

/*org.springframework.util.*/Assert.isTrue(checkIfActualUserKeyTypeIsString(), "Key type is not string");

instead.

return Optional.of(new Key(data.getNamespace(), setName, id));

// Store record key as it is (if Aerospike supports it natively and configured)
if (aerospikeDataSettings.isKeepOriginalKeyTypes() &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take the && operator to the new line

Comment on lines 123 to 128
String setName;
if (data.getSetName() != null) {
setName = data.getSetName();
} else {
setName = entity.getSetName();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can be simplified with

String setName = Optional.ofNullable(data.getSetName()).orElse(entity.getSetName());

return new Key(namespace, set, (byte[]) userKey);
}
// Could not construct a key of native supported Aerospike record key type
return null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not supporting Double/Float?

Copy link
Member Author

@roimenashe roimenashe Nov 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aerospike Record Key doesn't support Double/Float

@@ -32,6 +32,10 @@ public class AerospikeDataSettings {
int indexCacheRefreshFrequencySeconds = 3600;
@Builder.Default
long queryMaxRecords = 10_000L;
// When true, stores key types (record keys and map keys) as original type if supported. False means always store
Copy link

@agrgr agrgr Nov 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Define how @Id fields (primary keys) and Map keys are stored: false - always as String, true - preserve original type if supported

Used this in the documentation, we can have the same comment here. What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it

@roimenashe roimenashe merged commit 41ac7a8 into main Dec 6, 2023
@roimenashe roimenashe deleted the FMWK-79-key-types branch December 6, 2023 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants