Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Cannot read properties of undefined (reading 'length') #641

Closed
ozalieg opened this issue Jan 27, 2025 · 6 comments · Fixed by #648
Closed

[BUG] Cannot read properties of undefined (reading 'length') #641

ozalieg opened this issue Jan 27, 2025 · 6 comments · Fixed by #648
Labels
bug Something isn't working

Comments

@ozalieg
Copy link

ozalieg commented Jan 27, 2025

Steps to reproduce

  1. Just run the jv pipeline I added at the end over terminal (jv <filename>).

Description

  • Expected: no problems
  • Actual:
        error: An unknown error occurred: TypeError: Cannot read properties of undefined (reading 'length')
$In /Users/lea/Documents/Uni/WS24_25/Thesis/ws2425-buchner-jayvee-templating/General/TemplateGeneration/JvFiles/BiostatsPipeline.jv:16:11
        16 |     block BiostatsCSVInterpreter oftype CSVInterpreter {
           |    

Example Pipeline where the error occurs

pipeline BiostatsPipeline {

    BiostatsExtractor
    -> BiostatsTextFileInterpreter
    -> BiostatsCSVInterpreter
    -> BiostatsTableInterpreter
    -> BiostatsLoader;

    block BiostatsExtractor oftype HttpExtractor {
        url: "https://people.sc.fsu.edu/~jburkardt/data/csv/biostats.csv";
    }

    block BiostatsTextFileInterpreter oftype TextFileInterpreter {
    }

    block BiostatsCSVInterpreter oftype CSVInterpreter {
        enclosing: "";
    }

    block BiostatsTableInterpreter oftype TableInterpreter {
        header: true;
        columns: [
                "Name" oftype text,
                "Sex" oftype text,
                "Age" oftype integer,
                "Height (in)" oftype integer,
                "Weight (lbs)" oftype integer
        ];
    }

    block BiostatsLoader oftype SQLiteLoader {
        table: "Biostats";
        file: "./Biostats.sqlite";
    }

}
@ozalieg ozalieg added the bug Something isn't working label Jan 27, 2025
@TungstnBallon
Copy link
Contributor

The above TypeError will be fixed by #642.
However, the pipeline still doesn't work as intended, because the "Age" column contains numbers with a leading whitespace.
Jayvee (currently) doesn't consider these values numbers:

const NUMBER_REGEX = /^[+-]?([0-9]*[,.])?[0-9]+([eE][+-]?\d+)?$/;

@joluj What would you say is the intended behavior here?

@joluj
Copy link
Contributor

joluj commented Jan 27, 2025

AFAIK leading whitespaces are part of the cell in CSV. Therefore it's the problem with the CSV.

However, that does not remove the real-world problem of having leading (and also trailing) whitespaces. I'd suggest adding an attribute skipLeadingWhitespaces and skipTrailingWhitespaces to the CSVInterpreter (similar to Python). I wouldn't modify the number definition.

@rhazn @georg-schwarz Opinions?

@rhazn
Copy link
Contributor

rhazn commented Jan 27, 2025

I'd consider parsing ' 5' as the number 5 correct, so I'd just silently strip leading and trailing whitespace from number values honestly.

I think that's pretty intuitive and I'm struggling to come up with edge cases that would make it incorrect.

@joluj
Copy link
Contributor

joluj commented Jan 27, 2025

I think that's pretty intuitive and I'm struggling to come up with edge cases that would make it incorrect.

Me neither, however, I'm not too big of a fan of silently parsing the number. I'd prefer setting skipLeadingWhitespaces to true by default.

@georg-schwarz
Copy link
Member

Or we need a transform function (and a nicer Syntax to apply those) :)

@TungstnBallon
Copy link
Contributor

@ozalieg When using #648, I'm able to execute the following pipeline without crashes/errors.

pipeline BiostatsPipeline {

	BiostatsExtractor
		-> BiostatsTextFileInterpreter
		-> BiostatsCSVInterpreter
		-> BiostatsTableInterpreter
		-> BiostatsLoader;

	block BiostatsExtractor oftype HttpExtractor {
		url: "https://people.sc.fsu.edu/~jburkardt/data/csv/biostats.csv";
	}

	block BiostatsTextFileInterpreter oftype TextFileInterpreter { }

	block BiostatsCSVInterpreter oftype CSVInterpreter {
		enclosing: "";
	}

	block BiostatsTableInterpreter oftype TableInterpreter {
		header: true;
		columns: [
			'"Name"' oftype text,
			'     "Sex"' oftype text,
			' "Age"' oftype integer,
			' "Height (in)"' oftype integer,
			' "Weight (lbs)"' oftype integer
		];
	}

	block BiostatsLoader oftype SQLiteLoader {
		table: "Biostats";
		file: "./Biostats.sqlite";
	}
}

it results in this table:

| "Name" |      "Sex" |  "Age" |  "Height (in)" |  "Weight (lbs)" |
|--------|------------|--------|----------------|-----------------|
| "Alex" |        "M" | 41     | 74             | 170             |
| "Bert" |        "M" | 42     | 68             | 166             |
| "Carl" |        "M" | 32     | 70             | 155             |
| "Dave" |        "M" | 39     | 72             | 167             |
| "Elly" |        "F" | 30     | 66             | 124             |
| "Fran" |        "F" | 33     | 66             | 115             |
| "Gwen" |        "F" | 26     | 64             | 121             |
| "Hank" |        "M" | 30     | 71             | 158             |
| "Ivan" |        "M" | 53     | 72             | 175             |
| "Jake" |        "M" | 32     | 69             | 143             |
| "Kate" |        "F" | 47     | 69             | 139             |
| "Luke" |        "M" | 34     | 72             | 163             |
| "Myra" |        "F" | 23     | 62             | 98              |
| "Neil" |        "M" | 36     | 75             | 160             |
| "Omar" |        "M" | 38     | 70             | 145             |
| "Page" |        "F" | 31     | 67             | 135             |
| "Quin" |        "M" | 29     | 71             | 176             |
| "Ruth" |        "F" | 28     | 65             | 131             |

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants