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

Validation of timestamp with ISO8601 pattern with microseconds fails #68

Open
kevinwallimann opened this issue Jan 8, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@kevinwallimann
Copy link

kevinwallimann commented Jan 8, 2025

Describe the bug

The following timestamp pattern fails to be validated: yyyy-MM-dd'T'HH:mm:ss.SSSXXX. This is a pattern defined by ISO8601. However, it does validate when removing either the 'T' or the fractional second part (see test-cases below)

To Reproduce

Steps to reproduce the behavior OR commands run:

  1. Add the following test to SchemaValidationSuite and execute it
  test("Timestamp with fractional seconds should be validated") {
    val schema = StructType(
      Array(
        StructField("id", LongType),
        StructField("name", StringType),
        StructField("timestamp_without_fraction_ok", TimestampType, nullable = false, Metadata.fromJson(""" { "pattern": "yyyy-MM-dd'T'HH:mm:ssXXX", "default": "2025-01-08T13:07:39+00:00" } """.stripMargin)),
        StructField("timestamp_with_fraction_without_T_ok", TimestampType, nullable = false, Metadata.fromJson(""" { "pattern": "yyyy-MM-dd HH:mm:ss.SSSXXX", "default": "2025-01-08 13:07:39.490+00:00" } """.stripMargin)),
        StructField("timestamp_with_fraction_and_T_nok", TimestampType, nullable = false, Metadata.fromJson(""" { "pattern": "yyyy-MM-dd'T'HH:mm:ss.SSSXXX", "default": "2025-01-08T13:07:39.490+00:00" } """.stripMargin))
      )
    )

    val failures = SchemaValidator.validateSchema(schema)(CommonTypeDefaults)
    if (failures.nonEmpty) {
      logger.error("Validation errors:")
      logger.error(failures.mkString("\n"))
    }

    assert(failures.isEmpty)
  }
  1. See the test failing with Unparseable date: "2025-01-08T13:07:39.490:00

Expected behavior

The pattern with 'T' and fractional seconds should be successfully validated.

Use-case

Only for internal development / testing

@kevinwallimann kevinwallimann added the bug Something isn't working label Jan 8, 2025
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

No branches or pull requests

1 participant