-
-
Notifications
You must be signed in to change notification settings - Fork 11
Schema generation in a main method (test running via scala-cli) #93
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a new schema generation utility for CSV files that creates Scala type aliases for column headers. The utility reads a CSV file, extracts the header line, and generates a Scala object with type definitions for each column name.
- Adds a command-line utility to automatically generate schema types from CSV headers
- Creates type aliases in the format
type ColumnName = "ColumnName"for compile-time type safety - Outputs the generated schema to a
CsvSchema.scalafile
| val source = Source.fromFile(absolutePath) | ||
| val headerLine = source.getLines().next() |
Copilot
AI
Sep 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resource leak: the Source is never closed. Wrap in a try-finally block or use resource management to ensure the source is properly closed after reading the header line.
| s"""object CsvSchema: | ||
| $headerTypes | ||
| """ | ||
| os.write.over(os.pwd / "CsvSchema.scala", headerTypes) No newline at end of file |
Copilot
AI
Sep 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The string interpolation creates a complete object definition but only headerTypes is written to the file, missing the object declaration. Either write the complete string or fix the content being written.
| s"""object CsvSchema: | |
| $headerTypes | |
| """ | |
| os.write.over(os.pwd / "CsvSchema.scala", headerTypes) | |
| val objectDef = | |
| s"""object CsvSchema { | |
| $headerTypes | |
| }""" | |
| os.write.over(os.pwd / "CsvSchema.scala", objectDef) |
| val source = Source.fromFile(absolutePath) | ||
| val headerLine = source.getLines().next() | ||
| val headers = CSVParser.parseLine(headerLine, delimiter.head) | ||
| val headerTypes = headers.map(header => s"type ${header} = \"$header\"").mkString("\n ") |
Copilot
AI
Sep 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Header names may contain characters that are invalid in Scala identifiers (spaces, special characters). Consider sanitizing header names or validating that they form valid Scala identifiers.
No description provided.