diff --git a/.docs/api/data-service.md b/.docs/api/data-service.md index afaa77215d6117afab48b4f19ebb9b1fb4068460..257c68c1957fa697957c9dfc3f6b681693ac3f9d 100644 --- a/.docs/api/data-service.md +++ b/.docs/api/data-service.md @@ -35,9 +35,15 @@ the [Data Database](../data-db) with a wide range of open-source connectors. The embedded processing directly in the service until there exists a [Bitnami Chart](https://artifacthub.io/packages/helm/bitnami/spark) for Spark 4. +Retrieving data from a subset internally generates a view with the 64-character hash of the query. This view is not +automatically deleted currently. + ## Limitations -* Currently only local processing (slow) embedded in the service using a two-thread `local[2]` configuration. +* Views in DBRepo can only have 63-character length (it is assumed only internal views have the maximum length of 64 + characters). +* Local mode of embedded processing of Apache Spark directly in the service using + a [`local[2]`](https://spark.apache.org/docs/latest/#running-the-examples-and-shell) configuration. !!! question "Do you miss functionality? Do these limitations affect you?" diff --git a/dbrepo-data-service/rest-service/src/test/resources/init/weather.sql b/dbrepo-data-service/rest-service/src/test/resources/init/weather.sql index 322e67cc07397105bb7c763efe4d37c905cc1b18..8f7950b13ce8119d601ab809045e48d1cc4b6ac1 100644 --- a/dbrepo-data-service/rest-service/src/test/resources/init/weather.sql +++ b/dbrepo-data-service/rest-service/src/test/resources/init/weather.sql @@ -1,6 +1,8 @@ /* https://www.kaggle.com/jsphyg/weather-dataset-rattle-package */ -CREATE DATABASE weather; -USE weather; +CREATE +DATABASE weather; +USE +weather; CREATE TABLE weather_location ( @@ -12,8 +14,8 @@ CREATE TABLE weather_location CREATE TABLE weather_aus ( id SERIAL PRIMARY KEY, - `date` DATE NOT NULL, - location VARCHAR(255) NULL COMMENT 'Closest city', + `date` DATE NOT NULL, + location VARCHAR(255) NULL COMMENT 'Closest city', mintemp DOUBLE PRECISION NULL, rainfall DOUBLE PRECISION NULL, FOREIGN KEY (location) REFERENCES weather_location (location) ON DELETE SET NULL, @@ -44,7 +46,7 @@ CREATE TABLE sensor CREATE TABLE exotic_boolean ( - `bool_default` BOOLEAN NOT NULL PRIMARY KEY, + `bool_default` BOOLEAN NOT NULL PRIMARY KEY, `bool_tinyint` TINYINT(1) NOT NULL, `bool_tinyint_unsigned` TINYINT(1) UNSIGNED NOT NULL ) WITH SYSTEM VERSIONING; @@ -91,4 +93,10 @@ CREATE VIEW not_in_metadata_db2 AS ( select `date`, `location`, `mintemp` as `MinTemp`, `rainfall` as `Rainfall` from `weather_aus` +where `location` = 'Vienna'); + +CREATE VIEW 5c7ba02f681b889892ee82987aa6c74ce45a30973cfef06b78ce797f25189b9 AS +( +select `date`, `location`, `mintemp` as `MinTemp`, `rainfall` as `Rainfall` +from `weather_aus` where `location` = 'Vienna'); \ No newline at end of file diff --git a/dbrepo-data-service/services/src/main/java/at/tuwien/service/impl/ViewServiceMariaDbImpl.java b/dbrepo-data-service/services/src/main/java/at/tuwien/service/impl/ViewServiceMariaDbImpl.java index b5f61e6c79744e8181f7ab7ab69a162d9d549bde..a4cb031066c90d11c236eddb142e815779412e48 100644 --- a/dbrepo-data-service/services/src/main/java/at/tuwien/service/impl/ViewServiceMariaDbImpl.java +++ b/dbrepo-data-service/services/src/main/java/at/tuwien/service/impl/ViewServiceMariaDbImpl.java @@ -13,6 +13,7 @@ import at.tuwien.exception.ViewNotFoundException; import at.tuwien.mapper.DataMapper; import at.tuwien.mapper.MariaDbMapper; import at.tuwien.mapper.MetadataMapper; +import at.tuwien.service.SchemaService; import at.tuwien.service.ViewService; import com.google.common.hash.Hashing; import com.mchange.v2.c3p0.ComboPooledDataSource; @@ -35,14 +36,16 @@ public class ViewServiceMariaDbImpl extends HibernateConnector implements ViewSe private final DataMapper dataMapper; private final QueryConfig queryConfig; + private final SchemaService schemaService; private final MariaDbMapper mariaDbMapper; private final MetadataMapper metadataMapper; @Autowired - public ViewServiceMariaDbImpl(DataMapper dataMapper, QueryConfig queryConfig, MariaDbMapper mariaDbMapper, - MetadataMapper metadataMapper) { + public ViewServiceMariaDbImpl(DataMapper dataMapper, QueryConfig queryConfig, SchemaService schemaService, + MariaDbMapper mariaDbMapper, MetadataMapper metadataMapper) { this.dataMapper = dataMapper; this.queryConfig = queryConfig; + this.schemaService = schemaService; this.mariaDbMapper = mariaDbMapper; this.metadataMapper = metadataMapper; } @@ -86,11 +89,19 @@ public class ViewServiceMariaDbImpl extends HibernateConnector implements ViewSe log.trace("executed statement in {} ms", System.currentTimeMillis() - start); while (resultSet1.next()) { final String viewName = resultSet1.getString(1); + if (viewName.length() == 64) { + log.trace("view {}.{} seems to be a subset view (name length = 64), skip.", database.getInternalName(), viewName); + continue; + } if (database.getViews().stream().anyMatch(v -> v.getInternalName().equals(viewName))) { log.trace("view {}.{} already known to metadata database, skip.", database.getInternalName(), viewName); continue; } - + final ViewDto view; + view = schemaService.inspectView(database, viewName); + if (database.getTables().stream().noneMatch(t -> t.getInternalName().equals(view.getInternalName()))) { + views.add(view); + } } } catch (SQLException e) { log.error("Failed to get view schemas: {}", e.getMessage()); diff --git a/dbrepo-metadata-service/api/src/main/java/at/tuwien/api/database/ViewCreateDto.java b/dbrepo-metadata-service/api/src/main/java/at/tuwien/api/database/ViewCreateDto.java index 583b5f0d81aab8f8af7ca71efcd743ac8a079b27..4041292b51a34a65183d05391cbad0c52f0b38e8 100644 --- a/dbrepo-metadata-service/api/src/main/java/at/tuwien/api/database/ViewCreateDto.java +++ b/dbrepo-metadata-service/api/src/main/java/at/tuwien/api/database/ViewCreateDto.java @@ -19,7 +19,7 @@ import lombok.extern.jackson.Jacksonized; public class ViewCreateDto { @NotBlank - @Size(min = 1, max = 64) + @Size(min = 1, max = 63) @Schema(example = "Air Quality") private String name; diff --git a/dbrepo-ui/composables/query-service.ts b/dbrepo-ui/composables/query-service.ts index e7bb860f658ab017a7b9f0e38a94b4bf17167631..119915de2785763d549bdf3bf2d97379811f8fed 100644 --- a/dbrepo-ui/composables/query-service.ts +++ b/dbrepo-ui/composables/query-service.ts @@ -84,7 +84,6 @@ export const useQueryService = (): any => { axios.post<QueryResultDto>(`/api/database/${databaseId}/subset`, data, {params: mapFilter(timestamp, page, size), timeout: 600_000}) .then((response) => { console.info('Executed query with id', response.data.id, ' in database with id', databaseId) - console.debug('=======>', response) const result: QueryResultDto = { id: 1, headers: [], diff --git a/dbrepo-upload-service/src/test/resources/application.properties b/dbrepo-upload-service/src/test/resources/application.properties index 088fec498b6cd74aba161d18ec30ad500e18bd4c..4bc77eb246821e8961b7e5ae8cea558bdcd54475 100644 --- a/dbrepo-upload-service/src/test/resources/application.properties +++ b/dbrepo-upload-service/src/test/resources/application.properties @@ -5,7 +5,7 @@ spring.profiles.active=local,junit spring.cloud.discovery.enabled=false # internal datasource -spring.datasource.url=jdbc:h2:mem:testdb;DB_CLOSE_ON_EXIT=FALSE;INIT=CREATE SCHEMA IF NOT EXISTS DBREPO;NON_KEYWORDS=value +spring.datasource.url=jdbc:h2:mem:dbrepo;DB_CLOSE_ON_EXIT=FALSE;INIT=CREATE SCHEMA IF NOT EXISTS dbrepo;NON_KEYWORDS=value spring.datasource.driverClassName=org.h2.Driver spring.datasource.username=sa spring.datasource.password=password