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

Fix validation when creating time series via API #230

Merged
merged 3 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "PSRClassesInterface"
uuid = "1eab49e5-27d8-4905-b9f6-327b6ea666c4"
version = "0.17.2"
version = "0.17.3"

[deps]
DBInterface = "a10d1c49-ce27-4219-8d33-6db1a4562965"
Expand Down
9 changes: 9 additions & 0 deletions src/PSRDatabaseSQLite/collection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,15 @@ function _get_collection_time_series_files_tables(::SQLite.DB, collection_id::St
return string(collection_id, "_time_series_files")
end

function _dimensions_of_time_series_group(collection::Collection, group_id::String)
time_series = collection.time_series
for (_, time_series_attribute) in time_series
if time_series_attribute.group_id == group_id
return time_series_attribute.dimension_names
end
end
end

function _validate_actions_on_foreign_key(
collection_id::String,
table_name::String,
Expand Down
1 change: 0 additions & 1 deletion src/PSRDatabaseSQLite/create.jl
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ function create_element!(
catch e
@error """
Error creating element in collection \"$collection_id\"
error message: $(e.msg)
"""
rethrow(e)
end
Expand Down
7 changes: 6 additions & 1 deletion src/PSRDatabaseSQLite/validate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -364,16 +364,21 @@ function _throw_if_data_does_not_match_group(
df::DataFrame,
)
collection = _get_collection(db, collection_id)
dimensions_of_group = _dimensions_of_time_series_group(collection, group)
dimensions_in_df = []
attributes_in_df = []

for column in names(df)
if column in keys(collection.time_series)
# should be an attribute
push!(attributes_in_df, column)
else
elseif column in dimensions_of_group
# should be a dimension
push!(dimensions_in_df, column)
else
psr_database_sqlite_error(
"Attribute \"$column\" is not an attribute or dimension of the time series group \"$group\".",
)
end
end

Expand Down
Loading