Comments (3)
Apart from being simpler, other benefits include:
(a) it is possible to compare results using deep-equal (not possible before because of the function items)
(b) It is possible to serialize array{$result?rows}
nicely as JSON.
from qtspecs.
- Represent each row as a map, rather than as a structure with a data field and an accessor function.
[…]
I like this. If I remember correctly, one incentive for the given structure was the perspective of converting CSV bidirectionally, with $input => parse-csv() => serialize-csv()
giving us the original contents. We have abandoned this idea at some point along the way. It certainly makes life easier, and we should choose a result format that’s easier to process.
- The key for a field in this map should be an integer if (i) column-names is set to false, or (ii) the column in question does not have a unique header name; in other cases it should be the name from the header.
Input with duplicate header names is quite common. I would suggest combining the data to the existing entry.
Here’s approximate input that I was just confronted with. With the proposed solution, …
"key,value,value,value,value
id2342,5,343,1,78
id1342,800"
=> csv:parse(map { 'format': 'xquery' })
…would result in…
map { 'key': id2342, 'value': ('5', '343', '1', '78') },
map { 'key': id1342, 'value': ('800')
We could also offer a duplicate
option, i.e. the one from map:merge
or a modified version.
- Replace the top-level
columns
record with a simple array of field names. It's easy enough to map names to positions using index-of.
A plain sequence would make it even easier.
I also propose changing the name to
csv-to-maps
for consistency withcsv-to-table
andcsv-to-arrays
.
fn:parse-csv
would be my favorite (see #748). On the one hand, we should try to be consistent with the existing function set, which offers fn:parse-xml
, fn:parse-json
and fn:parse-html
. Next…
We should advocate use of csv-to-arrays where data is to be accessed positionally, and csv-to-maps where it is to be accessed by column names, and optimise the design accordingly.
…I believe that we should offer a function that seems like a good default solution for most users. As the name of the other function csv-to-arrays
implies, it gives you a more low-level access to the input in case it’s needed (e..g if you have nested structures, which cannot be addressed easily with regular column names).
Finally, we could this default for fn:csv-doc
.
from qtspecs.
Closed in favour of #1052.
from qtspecs.
Related Issues (20)
- Almost all functions in FO that must process multiple string items, can have as a parameter only a single collation HOT 21
- For symmetry, add functions array:scan-left and array:scan-right HOT 1
- fn:apply argument names
- Dangling else syntax ambiguity HOT 9
- add fn:match-groups() function HOT 7
- Tokenization and element constructors HOT 6
- Productions missing ws:explicit
- Ambiguity in XPath EBNF - Lookup with TypeQualifier vs DynamicFunctionCall HOT 9
- 12 div-3 HOT 5
- XPath: type declarations in quantified expressions
- Record Test Subtype Relationship HOT 3
- Function Coercion: Drop Record Tests? HOT 3
- Specification Documents: Editors and Contributors
- fn:parse-uri: Observations HOT 1
- Leading lone slash
- fn:collation-available (editorial)
- Function parameters names: $uri vs. $href HOT 6
- Executable specifications HOT 1
- Variadic System Functions: Principles? HOT 3
- Misleading summary for concat() - "string value"
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from qtspecs.