Skip to content

Conversation

@Quafadas
Copy link
Owner

No description provided.

Copilot AI review requested due to automatic review settings September 16, 2025 10:03
Copy link
Contributor

Copilot AI left a 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.scala file

Comment on lines +12 to +13
val source = Source.fromFile(absolutePath)
val headerLine = source.getLines().next()
Copy link

Copilot AI Sep 16, 2025

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.

Copilot uses AI. Check for mistakes.
Comment on lines +16 to +19
s"""object CsvSchema:
$headerTypes
"""
os.write.over(os.pwd / "CsvSchema.scala", headerTypes) No newline at end of file
Copy link

Copilot AI Sep 16, 2025

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.

Suggested change
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)

Copilot uses AI. Check for mistakes.
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 ")
Copy link

Copilot AI Sep 16, 2025

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.

Copilot uses AI. Check for mistakes.
@Quafadas Quafadas changed the title . Schema generation in a main method (test running via scala-cli) Sep 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants