Skip to content

Commit

Permalink
Fix validation when creating time series via API
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhermebodin committed Nov 7, 2024
1 parent 940a09c commit 134572a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
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

0 comments on commit 134572a

Please sign in to comment.