Skip to content

TO_JSON_STRING with DATE field does not produce valid JSON - quotes missing #428

@pavelfomin

Description

@pavelfomin

What happened?

The following test fails

    def "use Job.getQueryResults with TO_JSON_STRING"() {
        given:
        QueryJobConfiguration queryJobConfiguration = QueryJobConfiguration
            .newBuilder("SELECT TO_JSON_STRING(t,true) from (SELECT * FROM dataset.table) as t")
            .build()

        JobId jobId = JobId.newBuilder().setProject(project).setRandomJob().build()
        Job job = bigQuery.create(JobInfo.newBuilder(queryJobConfiguration)
            .setJobId(jobId)
            .build())

        when:
        TableResult tableResult = job.getQueryResults()
        List<Map> results = tableResult.streamAll().map(f ->
            objectMapper.readValue(f[0].value.toString(), Map)
        ).toList()

        then:
        results.size() == 2
    }

This is because DATE field value is missing quotes:

{"id":1,"name":"alice","dob":1990-01-01}

Note. Date field value is missing quotes. Works as expected in real BQ.

What did you expect to happen?

Date field in the JSON should be quoted.

How can we reproduce it (as minimally and precisely as possible)?

git clone -b feature/TO_JSON_STRING [email protected]:pavelfomin/spring-boot-bq-example.git
./gradlew clean build

Anything else we need to know?

Possibly related to #218, #265, #32

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions