Moldova broke our data pipeline

(avraam.dev)

38 points | by almonerthis 2 days ago

16 comments

  • simula67 55 minutes ago
    RFC 4180 [1] Section 2.6 says:

    "Fields containing line breaks (CRLF), double quotes, and commas should be enclosed in double-quotes."

    If the DMS output isn’t quoting fields that contain commas, that’s technically invalid CSV.

    A small normalization step before COPY (or ensuring the writer emits RFC-compliant CSV in the first place) would make the pipeline robust without renaming countries or changing delimiters.

    That way, if/when the DMS output is fixed upstream, nothing downstream needs to change.

    [1] https://www.rfc-editor.org/rfc/rfc4180.html

  • aquafox 1 hour ago
    I really don't understand why people think it's a good idea to use csv. In english settings, the comma can be used as 1000-delimiter in large numbers, e.g. 1,000,000 for on million, in German, the comma is used as decimal place, e.g. 1,50€ for 1 euro and 50 cents. And of course, commas can be used free text fields. Given all that, it is just logical to use tsv instead!
    • Balinares 4 minutes ago
      It's one of those things where people think, it's there, and it works.

      The whole business of software engineering exists in the gap between "it works today on this input" and "it will also work tomorrow and the day after and after we've scaled 10x and rewrote the serialization abstraction and..."

      See also: "Glorp 5.7 Turbo one-shot this for me and it works!"

    • prerok 28 minutes ago
      Funny story: I once bought and started up Galactic Civilizations 3.

      It looked horrible, the textures just wouldn't load no matter what I tried. Finally, on a forum, some other user, presumably also from Europe, noted that you have to use decimal point as a decimal separator (my locale uses a comma). And that solved the problem.

    • nxpnsv 38 minutes ago
      Yes, but tabs also can appear in text fields. If you are free to pick not csv, then perhaps consider feather or parquet?
  • derriz 27 minutes ago
    Unrelated to the fundamental issue (a part of your pipeline generates invalid CSV), I would never store the name of the country like this. The country's name is "The Republic of Moldova" and I would store it like this.

    Sure, the most common collation scheme for country names is to sort ignoring certain prefixes like "The Republic of", "The", "People's Democratic...", etc. but this is purely a presentation layer issue (how to order a list of countries to a user) that should be independent of your underlying data.

    Sure "hacking" the name of the country like this to make the traditional alphabetical ordering match a particular ordering desired to aid human navigation has a lot of history (encyclopedia indexes, library indexes, record stores, etc.) but that was in the age of paper and physical filing systems.

    Store the country name correctly and then provide a custom sort or multiple custom sorts where such functionality belongs - in the presentation layer.

  • franciscop 2 hours ago
    This very clearly seems like a bug either in their DMS script, or in the DMS job that they don't directly control, since CSV clearly allows for escaping commas (by just quoting them). Would love to see a bug report being submitted upstream as well as part of the "fix".
    • zarzavat 2 hours ago
      CSV quoting is dialect dependent. Honestly you should just never use CSV for anything if you can avoid it, it's inferior to TSV (or better yet JSON/JSONL) and has a tendency to appear like it's working but actually be hiding bugs like this one.
      • j16sdiz 2 hours ago
        Most CSV dialects have no problem having double quoted commas.

        The "dialect dependent" part is usually about escaping double quotes, new lines and line continuations.

        Not a portable format, but it is not too bad (for this use) either considering the country list is mostly static

        • jorams 46 minutes ago
          I'd go so far as to say any implementation that doesn't conform to RFC 4180[1] is broken and should be fixed. The vast majority of implementations get this right, it's just that some that don't are so high profile it causes people to throw up their hands and give up.

          [1]: https://datatracker.ietf.org/doc/html/rfc4180

  • rglover 1 hour ago
    Considering the scope, this could be more easily resolved by just stripping ", Republic of" from that specific string (assuming "Moldova" on its own is sufficient).
  • davecahill 1 hour ago
    I was expecting a Markdown-related .md issue. :)
  • alexdns 30 minutes ago
    I dont understand people who dont validate their inputs and outputs - a count of expected values would've prevented such a basic mistake
  • Surac 1 hour ago
    I personaly would shy away from binary formats whenever possible. For my column based files i use TSV or the pipe char as delimiter. even excel allowes this files if you include a "del=|" as first line
  • cyberax 1 hour ago
    "Sanitize at the boundary"

    Ah, but what _is_ the boundary, asks Transnistria?

  • the_origami_fox 45 minutes ago
    That's a cool map.
  • shalmanese 2 hours ago
    Did you really name your breakaway republic Sealand'); DROP TABLE Countries;--?
  • nivertech 2 days ago
    just use TSV instead of CSV by default
  • vasco 1 hour ago
    The majority of countries official names are in this format. We just use the short forms. "Republic of ..." is the most common formal country name: https://en.wikipedia.org/wiki/List_of_sovereign_states
    • Kwpolska 40 minutes ago
      Sure, but why Moldova of all places? I've seen this form usually for places where there's a dispute for the short name, like Nice/Naughty Korea, Taiwan/West Taiwan, or Macedonia/entitled Greek government.
  • inevletter 1 hour ago
    Huge skill issue. Nothing to see here.
  • renewiltord 47 minutes ago
    Come on man. What are we doing here. This is not even anything interesting like Norway being interpreted as False in YAML. This is just a straightforward escaping issue.