Skip to content

infinity value sanitized , input pattern validation and ISO fallback #70

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

MatloaItumeleng
Copy link

@MatloaItumeleng MatloaItumeleng commented Jul 11, 2025

Closes #69 , Adds:

  • Support for ISO pattern as fallback if infinityValue cannot be parsed
  • defers casting to DateTimeParser and NumericParser for origType

protected def field: TypedStructField


private def sanitizeInput(s: String): String = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why you need this function? Why you need to sanitze the strings?

infPlusValue.map { plusValue =>
when(columnWithNegativeInf === lit(plusSymbol).cast(origType), lit(plusValue).cast(origType))
.otherwise(columnWithNegativeInf)
val validatedMinus = if (origType == DateType || origType == TimestampType) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You testing same condition twice after each other.



def replaceInfinitySymbols(column: Column)(implicit spark:SparkSession, defaults: TypeDefaults): Column = {
var resultCol = column.cast(StringType)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var is to be avoided in Scala

to_date(resultCol, "yyyy-MM-dd")
).cast(origType)
case _ =>
resultCol.cast(origType)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indenation

origType match {
case TimestampType =>
val pattern = getPattern(origType).getOrElse(
defaults.defaultTimestampTimeZone.map(_ => "yyyy-MM-dd'T'HH:mm:ss.SSSSSS").getOrElse("yyyy-MM-dd HH:mm:ss")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the point and goal of this expression?

…ult ISO pattern used if no pattern is specified and direct casting to DateType & TimestampType
@benedeki
Copy link
Contributor

I tried to descibe a working solution in the original ticket comment.

… with methods isocast & origcast , and NumericParser compability retained
@MatloaItumeleng
Copy link
Author

Followed algorithm logic and implemented following solution;

  • InfinitySupport trait retained with its structure replacing symbols with values without casting to origType
  • To apply casting functions post replacement extended DateTimeParser (in TypeParser) which uses canParseInfValue to decide A : for pattern compatible values or B: for non-compatible values

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.

Allow infinity values with different pattern than input values
2 participants