Skip to content

Commit 03e73fa

Browse files
committed
#1187: fix docs for csvMatchingRows templating function and improve scientific notation check
1 parent ae6b759 commit 03e73fa

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

core/util/util.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,9 +421,17 @@ func jsonPath(query, toMatch string) interface{} {
421421
return arrayData
422422
}
423423

424-
// isScientific checks if a string is in scientific notation (e.g., "1.349599e+37")
424+
// containScientificNotation checks if a string is in scientific notation (e.g., "1.349599e+37")
425425
func containScientificNotation(value string) bool {
426-
return strings.Contains(value, "e") || strings.Contains(value, "E")
426+
// Scientific notation pattern:
427+
// - Optional sign at start (+/-)
428+
// - One or more digits (optionally with decimal point)
429+
// - e or E
430+
// - Optional sign (+/-)
431+
// - One or more digits
432+
pattern := `^[+-]?\d*\.?\d+[eE][+-]?\d+$`
433+
match, _ := regexp.MatchString(pattern, value)
434+
return match
427435
}
428436

429437
func convertToPlainNotation(scientific string) (string, bool) {

docs/pages/keyconcepts/templating/templating.rst

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ Reading from a CSV Data Source
182182

183183
You can read data from a CSV data source in a number of ways.
184184

185-
The most basic is to use the ``csv`` function to return the value of one field (selected-column) given a field name to search (column-name) and
185+
The most basic is to use the ``csv`` function to return the value of one field (selected-column) given a field name to search (column-name) and
186186
a value to search for in that field (query-value). Of course the query-value would normally be pulled from the request.
187187

188188
.. code:: handlebars
@@ -245,14 +245,14 @@ To return all the data from the csv as an array of maps, you use the ``csvAsMap`
245245
.. code:: handlebars
246246
247247
{{csvAsMap '(data-source-name)' }}
248-
249248
250-
To return filtered data from the csv as an array of maps, you use the ``csvMatchingRows``function.
249+
250+
To return filtered data from the csv as an array of maps, you use the ``csvMatchingRows``function.
251251
(Note that you would need to wrap this in an #each block. See examples below.):
252252
253253
.. code:: handlebars
254254
255-
{{csvMatchingRows '(data-source-name)' '(column-name)' '(query-value)' '(selected-column)'}}
255+
{{csvMatchingRows '(data-source-name)' '(column-name)' '(query-value)'}}
256256
257257
To return all the data from the csv as an array arrays, you use the ``csvAsArray`` function.
258258
(Note that you would need to wrap this in an #each block. See examples below.):
@@ -261,7 +261,7 @@ To return all the data from the csv as an array arrays, you use the ``csvAsArray
261261
262262
{{csvAsArray '(data-source-name)' }}
263263
264-
To return filtered data from the csv as an array of maps using the SQL like dialect, you use the ``csvSqlCommand`` function.
264+
To return filtered data from the csv as an array of maps using the SQL like dialect, you use the ``csvSqlCommand`` function.
265265
Again this needs to be wrapped in an #each block:
266266

267267
.. code:: handlebars
@@ -401,8 +401,8 @@ To delete all the pets where the category is cats from the pets csv data store:
401401
``{{ csvDeleteRows 'pets' 'category' 'cats' false }}``
402402

403403
Note that the last parameter of "output-result" is a boolean. It is not enclosed in quotes. The function will return the number of rows
404-
affected which can either be suppressed by passing false to this parameter, or passed into another function if you need to make logical
405-
decisions based on the number of rows affected by passing in true as the last parameter. If ``csvDeleteRows`` is not enclosed within another
404+
affected which can either be suppressed by passing false to this parameter, or passed into another function if you need to make logical
405+
decisions based on the number of rows affected by passing in true as the last parameter. If ``csvDeleteRows`` is not enclosed within another
406406
function it will output the number of rows deleted to the template.
407407

408408
``{{#equal (csvDeleteRows 'pets' 'category' 'cats' true) '0'}}
@@ -423,8 +423,8 @@ Deleting data from a CSV Data Source using SQL like syntax
423423
Example:
424424
``{{ csvSqlCommand "DELETE FROM pets WHERE id > '20'" }}``
425425

426-
Calling the csvSqlCommand for Delete and Update commands will execute the statements without outputting anything to the template.
427-
The rows affected will be logged for debugging purposes.
426+
Calling the csvSqlCommand for Delete and Update commands will execute the statements without outputting anything to the template.
427+
The rows affected will be logged for debugging purposes.
428428

429429

430430

@@ -473,7 +473,7 @@ Joins across different data sources are not supported.
473473
Counting the rows in a CSV Data Source
474474
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
475475

476-
You can return the number of rows in a csv dataset using ``csvCountRows``.
476+
You can return the number of rows in a csv dataset using ``csvCountRows``.
477477
This will be 1 less than the number of rows as the first row contains the column names.
478478

479479
.. code:: handlebars

0 commit comments

Comments
 (0)