Skip to content

CDA-113 Adding csv support for timeseries#1780

Open
rma-bryson wants to merge 6 commits into
developfrom
feature/CDA-113-support-csv-for-time-series
Open

CDA-113 Adding csv support for timeseries#1780
rma-bryson wants to merge 6 commits into
developfrom
feature/CDA-113-support-csv-for-time-series

Conversation

@rma-bryson

@rma-bryson rma-bryson commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

Summary

Implements csv support for timeseries. This should also streamline other data types supporting our custom csv formatting in the future - including metadata comment headers at top of payload, unit in column header, and optional-column inclusion via DTO annotations in the spirit of Jackson.

This also adds support for specifying date-format. Currently this only works for csv, but could be extended to other formats in the future.

Also noting decision during cda dev meeting to use query parameters for optional column inclusion and date-format. Updated ADR to reflect that.

Related Issue

Closes #1257

Validation

Added unit tests and integration tests

Checklist

  • Junie assisted in getting annotations working correctly.

@rma-bryson rma-bryson force-pushed the feature/CDA-113-support-csv-for-time-series branch 10 times, most recently from 7219b05 to 8465b44 Compare June 18, 2026 16:15
@rma-bryson rma-bryson marked this pull request as ready for review June 18, 2026 16:18
@rma-bryson rma-bryson requested a review from MikeNeilson June 18, 2026 16:18
@rma-bryson rma-bryson force-pushed the feature/CDA-113-support-csv-for-time-series branch from 8465b44 to 76e0901 Compare June 18, 2026 16:26

@MikeNeilson MikeNeilson left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Generally good. Definitely concerned about some critical logic duplication.

Comment thread cwms-data-api/src/main/java/cwms/cda/api/Controllers.java Outdated
Comment thread cwms-data-api/src/main/java/cwms/cda/data/dao/StreamConsumer.java
qualityForNormalization
).as("quality_norm");

Field<Double> convertedValue = CWMS_UTIL_PACKAGE.call_CONVERT_UNITS(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

AV_TSV_DQU where unit_id = 'X' will already provide only units in X, a call to cwms_util.convert_units is redundant.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

removed redundant unit conversion

@rma-bryson rma-bryson Jun 22, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Turns out this was needed to handle bad user-requested units. The test_wrong_units() was failing in the TimeSeriesControllerTestIT. Adding this back in fixes it because the conversion procedure handles validation.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Right, but why are will killing performance or a possible, but not common, failure?

I can see the value in the check, but a single called to the unit conversion itself will inform us if the unit it valid, without an additional context switch for every row.

... yes yes, it might be "common" but not in the various places of automation that will call this endpoint a lot, or from GUIs that may artificially limit the choices in the UI.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Updated validation to a single indexed existence check before the data query, eliminating any per-row conversion overhead while still failing fast on invalid units.

Comment thread cwms-data-api/src/main/java/cwms/cda/data/dao/TimeSeriesDaoImpl.java Outdated
@rma-bryson rma-bryson requested a review from MikeNeilson June 18, 2026 19:58
@rma-bryson

Copy link
Copy Markdown
Collaborator Author
image Was able to get the example csv working

MikeNeilson
MikeNeilson previously approved these changes Jun 22, 2026

@MikeNeilson MikeNeilson left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice trick with the getExample method to fill out that detail.

Seems within that we could also setup our own annotation to retrieve a sample JSON.

Comment thread cwms-data-api/src/main/java/cwms/cda/data/dao/StreamConsumer.java
Comment thread cwms-data-api/src/main/java/cwms/cda/ApiServlet.java
qualityForNormalization
).as("quality_norm");

Field<Double> convertedValue = CWMS_UTIL_PACKAGE.call_CONVERT_UNITS(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Right, but why are will killing performance or a possible, but not common, failure?

I can see the value in the check, but a single called to the unit conversion itself will inform us if the unit it valid, without an additional context switch for every row.

... yes yes, it might be "common" but not in the various places of automation that will call this endpoint a lot, or from GUIs that may artificially limit the choices in the UI.

…Moved CsvOnDemandInputStream into its own file. Removed redundant unit conversion logic. Added csv example generator.
…handle invalid requested units gracefully."

This reverts commit 9f402f6.
…re the data query, eliminating any per-row conversion overhead while still failing fast on invalid units.
@rma-bryson rma-bryson force-pushed the feature/CDA-113-support-csv-for-time-series branch from 9f402f6 to ab100dc Compare June 23, 2026 19:00
);

if (!unitRequestedExists) {
String msg = units + " is not a valid unit for time series " + name;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

User input, needs to go through the sanitizer.

I would've just called the procedure, but wasn't thinking about the unit system level.

@rma-bryson rma-bryson Jun 23, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Updated to sanitize message. Also added a check that a row actually exists to guarantee failure is actually due to bad units

@rma-bryson rma-bryson requested a review from MikeNeilson June 23, 2026 20:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Changing format= Does Not Work with Request Headers

2 participants