Skip to content

Add support for DATE, TIME, and DATETIME schema types #1388

Closed
@esheffield

Description

@esheffield

BigQuery allows creation of tables with fields of type DATE, TIME, and DATETIME. However the Java client does not recognize these types. So for example, executing a load job to import JSON into a table an existing table with one of these field types in the schema will fail.

Schema:

    ItemDate:DATE,Description:STRING

JSON:

{"ItemDate": "2016-11-01", "Description": "Item 1"}
{"ItemDate": "2016-11-02", "Description": "Item 2"}
{"ItemDate": "2016-11-03", "Description": "Item 3"}
{"ItemDate": "2016-11-04", "Description": "Item 4"}

Create job: (Example from Scala repl but using the Java client)

val tableId = TableId.of("instant-bonbon-111304", "TestData", "Date_Test")
val uris = new java.util.ArrayList[String]()
uris.add("gs://ih_test_v1/date_test/date_test.json")

val jobConf = LoadJobConfiguration.newBuilder(tableId, uris).
  setWriteDisposition(JobInfo.WriteDisposition.WRITE_APPEND).
  setFormatOptions(FormatOptions.json).
  build

val jobInfo = JobInfo.of(jobConf)

var job : Job = null

try {
  job = bigquery.create(jobInfo)
} catch {
  case e: BigQueryException => println(e)
}

Error:

java.lang.IllegalArgumentException: No enum constant com.google.cloud.bigquery.Field.Type.Value.DATE
        at java.lang.Enum.valueOf(Enum.java:238)
        at com.google.cloud.bigquery.Field$Type$Value.valueOf(Field.java:75)
        at com.google.cloud.bigquery.Field.fromPb(Field.java:477)
        at com.google.cloud.bigquery.Field$1.apply(Field.java:46)
        at com.google.cloud.bigquery.Field$1.apply(Field.java:43)
        at com.google.common.collect.Lists$TransformingRandomAccessList.get(Lists.java:451)
        at java.util.AbstractList$Itr.next(AbstractList.java:358)
        at java.util.AbstractCollection.toArray(AbstractCollection.java:141)
        at java.util.ArrayList.<init>(ArrayList.java:177)
        at com.google.common.collect.Lists.newArrayList(Lists.java:119)
        at com.google.cloud.bigquery.Schema$Builder.setFields(Schema.java:86)
        at com.google.cloud.bigquery.Schema.of(Schema.java:189)
        at com.google.cloud.bigquery.Schema.fromPb(Schema.java:200)
        at com.google.cloud.bigquery.LoadJobConfiguration$Builder.<init>(LoadJobConfiguration.java:117)
        at com.google.cloud.bigquery.LoadJobConfiguration$Builder.<init>(LoadJobConfiguration.java:48)
        at com.google.cloud.bigquery.LoadJobConfiguration.fromPb(LoadJobConfiguration.java:553)
        at com.google.cloud.bigquery.JobConfiguration.fromPb(JobConfiguration.java:145)
        at com.google.cloud.bigquery.JobInfo$BuilderImpl.<init>(JobInfo.java:182)
        at com.google.cloud.bigquery.Job.fromPb(Job.java:324)
        at com.google.cloud.bigquery.BigQueryImpl.create(BigQueryImpl.java:229)
        ...

Metadata

Metadata

Labels

api: bigqueryIssues related to the BigQuery API.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions