Skip to content

fix(connect): support configurable decimal separator in CSV parser - #4878

Open
manish9363 wants to merge 3 commits into
apache:devfrom
manish9363:fix/csv-decimal-separator-530
Open

fix(connect): support configurable decimal separator in CSV parser#4878
manish9363 wants to merge 3 commits into
apache:devfrom
manish9363:fix/csv-decimal-separator-530

Conversation

@manish9363

Copy link
Copy Markdown

Closes #530

CSV values using , as the decimal separator were detected as strings instead of numbers. This adds a "Decimal separator" option to the CSV parser and makes DatatypeUtils normalize the configured separator before numeric detection.

Behavior is additive and backward-compatible: existing DatatypeUtils overloads default to ., and normalization is skipped for ambiguous values (e.g. 1,000,000) to avoid corrupting grouped numbers.

Tested: new unit tests in DatatypeUtilsTest (comma decimals + guard cases) and CsvParserTest (; delimiter with , decimals). mvn test green for both affected modules with 0 checkstyle violations.

Open question for maintainers: I implemented lenient behavior (configuring , still also accepts .-values). Happy to switch to strict locale honoring if preferred.

CsvFormat/CsvParser did not recognize numeric values using ',' as the
decimal separator, so they were treated as strings (issue apache#530).

- Add locale-aware overloads to DatatypeUtils (getTypeClass, getXsdDatatype,
  convertValue) that accept a decimal separator and normalize ',' to '.'
  before parsing. Existing overloads default to '.', so behavior is unchanged
  for current callers.
- Normalization is guarded: it is skipped when the separator occurs more than
  once (e.g. grouping separators like 1,000,000) to avoid corrupting values.
- Expose a 'Decimal separator' option on the CSV parser and thread it through.

Closes apache#530
@github-actions github-actions Bot added java Pull requests that update Java code backend Everything that is related to the StreamPipes backend testing Relates to any kind of test (unit test, integration, or E2E test). labels Sep 4, 2026
@tenthe

tenthe commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Hi @manish9363,

thanks a lot for the PR!

Could you please confirm that you reproduced the issue in a running StreamPipes instance and tested the fix end-to-end locally?

It would also be great if you could add a few screenshots showing the issue before the fix and the working behavior after the fix. This helps us verify that the change was tested in a real running system.

@manish9363

Copy link
Copy Markdown
Author

Hi @manish9363,

thanks a lot for the PR!

Could you please confirm that you reproduced the issue in a running StreamPipes instance and tested the fix end-to-end locally?

It would also be great if you could add a few screenshots showing the issue before the fix and the working behavior after the fix. This helps us verify that the change was tested in a real running system.

Yes, I reproduced the issue and tested the fix end-to-end in a running StreamPipes instance (Docker Compose). Screenshots below.

Setup: I used a CSV with ; as the column delimiter and , as the decimal separator:

sensor;temperature;humidity
sensor-a;3,14;45,5
sensor-b;21,7;60,2

Before (unpatched): In Connect → File Stream → CSV, temperature and humidity are detected as STRING, and the event preview keeps them as text ("temperature": "3,14").

After (with this fix): The CSV parser now exposes a "Decimal separator" option. Setting it to , makes temperature and humidity correctly detected as FLOAT, and the preview shows real numbers ("temperature": 3.14). sensor stays a STRING as expected.
before
after

@manish9363

Copy link
Copy Markdown
Author

@tenthe : Let me know if you need anything else

@SvenO3 SvenO3 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.

@manish9363 Thank you for your contributions. The changes look good to me. Just 2 things that need to be fixed:

  1. The Cypress tests that use the file stream adapter like for example fileStream.spec.ts need to add the new input field to run successfully
  2. Values with a period . like 100.000 should not get parsed as float when a different decimal separator is selected. I think that's the better design because a period could also be used as a grouping separator for large numbers

Values using a separator other than the configured one are now kept as
strings. For example "100.000" is no longer parsed as a float when the
decimal separator is set to ",". Same for ambiguous cases with more than
one separator.

Also updated the Cypress connect tests to fill the new decimal separator
field, since it is required and was blocking the file stream adapter flow.
@github-actions github-actions Bot added the ui Anything that affects the UI label Sep 7, 2026
@manish9363

Copy link
Copy Markdown
Author

@manish9363 Thank you for your contributions. The changes look good to me. Just 2 things that need to be fixed:

  1. The Cypress tests that use the file stream adapter like for example fileStream.spec.ts need to add the new input field to run successfully
  2. Values with a period . like 100.000 should not get parsed as float when a different decimal separator is selected. I think that's the better design because a period could also be used as a grouping separator for large numbers

@SvenO3 Thanks for the review. I have
Screenshot 2026-09-07 at 11 20 49 AM
Fixed both points:

  • Values with a different separator (e.g. 100.000 when "," is selected)
    now stay strings instead of being parsed as float.
  • Updated the Cypress tests that use the file stream adapter to fill the
    new decimal separator field.

Verified locally in a running instance - 100.000 stays a string and 3,14
is parsed as a float.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Everything that is related to the StreamPipes backend java Pull requests that update Java code testing Relates to any kind of test (unit test, integration, or E2E test). ui Anything that affects the UI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CsvFormat Decimal Support

3 participants