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

Implement backend data field filter for H2 & Postgresql (similar to MongoDB) #3516

Merged

Conversation

gdimitropoulos-sotec
Copy link
Contributor

Hono Issue for PR

Implement backend filter for H2 & Postgresql :

  • field/value filter
  • value filter of type bool/number/string
  • wildcard filter for string values
  • execute the same tests for H2 & Postgres
  • add documentation

Also-by: Matthias Feurer [email protected]
Signed-off-by: g.dimitropoulos [email protected]

- field/value filter
- value filter of type bool/number/string
- enable filter wildcards for string value
- add documentation

Also-by: Matthias Feurer [email protected]
Signed-off-by: g.dimitropoulos <[email protected]>
- run same unittests for all JDBC implementations

Also-by: Matthias Feurer [email protected]
Signed-off-by: g.dimitropoulos <[email protected]>
@sonatype-lift
Copy link

sonatype-lift bot commented Jul 24, 2023

Sonatype Lift is retiring

Sonatype Lift will be retiring on Sep 12, 2023, with its analysis stopping on Aug 12, 2023. We understand that this news may come as a disappointment, and Sonatype is committed to helping you transition off it seamlessly. If you’d like to retain your data, please export your issues from the web console.
We are extremely grateful and thank you for your support over the years.

📖 Read about the impacts and timeline

@sophokles73 sophokles73 added enhancement JDBC Device Registry The JDBC based Device Registry implementation labels Jul 24, 2023
@@ -60,7 +60,7 @@ The tenants in the registry can be managed using the Device Registry Management
The JDBC based registry implementation does not support the following features:

* Tenants can be retrieved using the [search tenants]({{< relref "/api/management#tenants/searchTenants" >}})
operation defined by the Device Registry Management API, but the *filterJson* and *sortJson* query parameters are
operation defined by the Device Registry Management API, but the *sortJson* query parameters are
Copy link
Contributor

Choose a reason for hiding this comment

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

... query parameter is (currently) being ignored.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -1687,10 +1687,11 @@ components:
filterJson:
name: filterJson
in: query
description: |
description: |
Copy link
Contributor

Choose a reason for hiding this comment

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

can you remove the trailing whitespaces?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

REPLACE(data, '"') LIKE CONCAT('%%', :field, ':', REPLACE(:value, '"'))
ORDER BY device_id ASC
LIMIT :page_size
OFFSET :page_offset
Copy link
Contributor

Choose a reason for hiding this comment

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

can you please add an EOL?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

jsonb_extract_path(data,'ext')->>:field LIKE CAST(:value as varchar)
ORDER BY device_id ASC
LIMIT :page_size
OFFSET :page_offset
Copy link
Contributor

Choose a reason for hiding this comment

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

can you please add an EOL?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines 177 to 178
FROM %s
WHERE
Copy link
Contributor

Choose a reason for hiding this comment

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

can you remove the trailing whitespace?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines 281 to 282
* @param key The key of the device.
* @param span The span to contribute to.
Copy link
Contributor

Choose a reason for hiding this comment

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

can you please remove the tabs here and in the other locations?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines 664 to 665
* @param field the field of filter expression
* @param value the value of the filter expression
Copy link
Contributor

Choose a reason for hiding this comment

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

please start with a capital letter and end with a period (.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines 737 to 745
// check if we got back a result, if not this will abort early
.compose(result -> extractVersionForUpdate(result, resourceVersion))

// take the version and start processing on
.compose(version -> Future.succeededFuture()

.compose(x -> {
final Promise<CredentialsDto> result = Promise.promise();
final var updatedCredentialsDto = CredentialsDto.forUpdate(
Copy link
Contributor

Choose a reason for hiding this comment

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

is anything being changed here or did you only change the indentation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

only the indentation

* @param tenantId The tenantId to search devices.
* @param pageSize The page size.
* @param pageOffset The page offset.
* @param filters The list of filters.
Copy link
Contributor

Choose a reason for hiding this comment

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

FMPOV we should document that only the first item in the list will be considered.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I change the "The list of filters." to "The list of filters (currently only the first value of the list is used)."

import java.nio.file.Path;


class JdbcPostgresDeviceManagementSearchDevicesTest extends JdbcBasedDeviceManagementSearchDevicesTest {
Copy link
Contributor

Choose a reason for hiding this comment

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

what is this class needed for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This class changes the DEFAULT_DATABASE_TYPE from H2 to POSTGRESQL and runs all the tests from JdbcBasedDeviceManagementSearchDevicesTest. We need this to run the tests against both types of JDBC DBs.

Copy link
Contributor

Choose a reason for hiding this comment

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

The type of database being used when running the tests is determined by the AbstractJdbcRegistryTest.databaseType system property. The tests are being run for both H2 and Postgresql by means of the two configurations of the Maven Surefire plugin in services/device-registry-jdbc/pom.xml. FMPOV there is no need for this class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i remove the class

Also-by: Matthias Feurer [email protected]
Signed-off-by: g.dimitropoulos <[email protected]>
Also-by: Matthias Feurer [email protected]
Signed-off-by: g.dimitropoulos <[email protected]>
Also-by: Matthias Feurer [email protected]
Signed-off-by: g.dimitropoulos <[email protected]>
Also-by: Matthias Feurer [email protected]
Signed-off-by: g.dimitropoulos <[email protected]>
Also-by: Matthias Feurer [email protected]
Signed-off-by: g.dimitropoulos <[email protected]>
Comment on lines 79 to 80
protected static DatabaseType DEFAULT_DATABASE_TYPE = DatabaseType.H2;
protected static DatabaseType DATABASE_TYPE = DatabaseType.valueOf(System.getProperty(AbstractJdbcRegistryTest.class.getSimpleName()
Copy link
Contributor

Choose a reason for hiding this comment

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

looks like these changes can be reverted as well now, can't they?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, i change it back to private final

Comment on lines 300 to 305
* @param key The key of the device to create.
* @param device The device data.
* @param tenant The configuration of the tenant that the device belongs to.
* @param globalDevicesPerTenantLimit The globally defined maximum number of devices per tenant. A value
* &lt;= 0 will be interpreted as no limit being defined.
* @param spanContext The span to contribute to.
* @param spanContext The span to contribute to.
Copy link
Contributor

Choose a reason for hiding this comment

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

can you please remove this indentation?

Comment on lines 421 to 426
* @param key The key of the device to update.
* @param statement The statement to use for the update.
* @param jsonValue The value to set.
* @param resourceVersion The optional resource version.
* @param nextVersion The new version to set.
* @param span The span to contribute to.
* @param nextVersion The new version to set.
* @param span The span to contribute to.
Copy link
Contributor

Choose a reason for hiding this comment

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

remove tabs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines 467 to 470
* @param key The key of the device to update.
* @param device The device data to store.
* @param resourceVersion The optional resource version.
* @param spanContext The span to contribute to.
* @param spanContext The span to contribute to.
Copy link
Contributor

Choose a reason for hiding this comment

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

remove tabs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -477,7 +547,7 @@ public Future<Versioned<Void>> updateDevice(
* If there is exactly one row, it will read the device registration information from the column
* {@code data} and optionally current resource version from the column {@code version}.
*
* @param key The key of the device to read.
* @param key The key of the device to read.
Copy link
Contributor

Choose a reason for hiding this comment

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

remove tabs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines 588 to 590
* @param key The key of the device to delete.
* @param resourceVersion An optional resource version.
* @param spanContext The span to contribute to.
* @param spanContext The span to contribute to.
Copy link
Contributor

Choose a reason for hiding this comment

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

remove tabs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines 661 to 665
* @param tenantId The tenant to count devices for.
* @param spanContext The span to contribute to.
* @param countStatement The count statement to use.
* @param field The field of filter expression.
* @param value The value of the filter expression.
Copy link
Contributor

Choose a reason for hiding this comment

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

remove tabs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines 711 to 714
* @param key The key of the device to update.
* @param credentials The credentials to set.
* @param resourceVersion The optional resource version to update.
* @param spanContext The span to contribute to.
* @param spanContext The span to contribute to.
Copy link
Contributor

Choose a reason for hiding this comment

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

remove tabs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

/**
* Get all credentials for a device.
* <p>
* This gets the credentials of a device. If the device cannot be found, the
* result must be empty. If no credentials could be found for an existing device,
* the result must not be empty, but provide an empty {@link CredentialsReadResult}.
*
* @param key The key of the device.
* @param key The key of the device.
Copy link
Contributor

Choose a reason for hiding this comment

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

remove tabs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines 925 to 928
* @param tenantId The tenantId to search devices.
* @param pageSize The page size.
* @param pageOffset The page offset.
* @param filters The list of filters (currently only the first value of the list is used).
Copy link
Contributor

Choose a reason for hiding this comment

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

remove tabs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Also-by: Matthias Feurer [email protected]
Signed-off-by: g.dimitropoulos <[email protected]>
Also-by: Matthias Feurer [email protected]
Signed-off-by: g.dimitropoulos <[email protected]>
@sophokles73 sophokles73 added this to the 2.4.0 milestone Jul 27, 2023
Copy link
Contributor

@sophokles73 sophokles73 left a comment

Choose a reason for hiding this comment

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

LGTM

@sophokles73 sophokles73 merged commit 3f2eee3 into eclipse-hono:master Jul 27, 2023
5 checks passed
gdimitropoulos-sotec added a commit to sotec-iot/hono that referenced this pull request Jul 28, 2023
… management API

Implement backend filter for H2 & Postgresql:
- field/value filter
- value filter of type bool/number/string
- enable filter wildcards for string value
- add documentation

Also-by: Matthias Feurer <[email protected]>
Signed-off-by: George Dimitropoulos <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement JDBC Device Registry The JDBC based Device Registry implementation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants