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

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

Closed
esheffield opened this issue Nov 10, 2016 · 5 comments
Closed

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

esheffield opened this issue Nov 10, 2016 · 5 comments
Assignees
Labels
api: bigquery Issues related to the BigQuery API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@esheffield
Copy link

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)
        ...
@mziccard mziccard added the api: bigquery Issues related to the BigQuery API. label Nov 10, 2016
@mziccard
Copy link
Contributor

@esheffield you are right. We'll try to provide support for this ASAP.

@omaray omaray added triaged type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. labels Nov 21, 2016
@bluecmd
Copy link

bluecmd commented Dec 7, 2016

Yes please, this is something we need. Is there a workaround for this if we want to use the new API with DATE/DATETIME columns?

@garrettjonesgoogle
Copy link
Member

I rolled this into #1451 .

@garrettjonesgoogle
Copy link
Member

0.8.0 has been released, so I'm going to resolve this now.

github-actions bot pushed a commit that referenced this issue Jun 21, 2022
…13.2 (#1388)

[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [com.google.cloud:google-cloud-bigquery](https://togithub.com/googleapis/java-bigquery) | `2.13.1` -> `2.13.2` | [![age](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-bigquery/2.13.2/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-bigquery/2.13.2/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-bigquery/2.13.2/compatibility-slim/2.13.1)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-bigquery/2.13.2/confidence-slim/2.13.1)](https://docs.renovatebot.com/merge-confidence/) |

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Renovate will not automatically rebase this PR, because other commits have been found.

🔕 **Ignore**: Close this PR and you won't be reminded about these updates again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox. ⚠ **Warning**: custom changes will be lost.

---

This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/java-bigquerydatatransfer).
github-actions bot pushed a commit that referenced this issue Jun 21, 2022
🤖 I have created a release *beep* *boop*
---


## [2.2.4](googleapis/java-bigquerydatatransfer@v2.2.3...v2.2.4) (2022-06-13)


### Dependencies

* update dependency com.google.cloud:google-cloud-bigquery to v2.13.2 ([#1388](googleapis/java-bigquerydatatransfer#1388)) ([5366270](googleapis/java-bigquerydatatransfer@5366270))
* update dependency com.google.cloud:google-cloud-pubsub to v1.119.1 ([#1387](googleapis/java-bigquerydatatransfer#1387)) ([578c028](googleapis/java-bigquerydatatransfer@578c028))

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
@AndySantaCruzAnalytics
Copy link

I am a bigQuery newbie. Not sure if this is a bug or not.

My schema type is 'date'. The FieldValue class does not have a getDate() function. I did some hacking. Looks like you get back a string that I have to parse. the test database table was created by uploading a csv file and using auto detect

I expected a getType() for every schema type big query supports?

    for (FieldValueList row : result.iterateAll()) {
      // String type
      String ownerId = row.get("ownerId").getStringValue();
      FieldValue aedwipWhatIsType = row.get("date");
      Object lastRecordDate = row.get("date").getValue();
      logger.info("hack lastRecordDate " + lastRecordDate.getClass().getCanonicalName()  + " " + lastRecordDate.toString());
      String subscriptionId = row.get("subscriptionId").getStringValue();

      String msg = "BIGQuery test  " + " ownerId: " + ownerId + " subscriptionId" + subscriptionId
          + "lastRecordDate" + lastRecordDate;

      logger.info(msg);
    }
INFO: hack lastRecordDate java.lang.String 2022-04-17
Jun 26, 2022 7:39:20 PM com.stx.webapi.BQTestServlet aedwipBiqQueryTest
INFO: BIGQuery test  ownerId: 7Q7309QG78 subscriptionId: 12yz lastRecord. Date:2022-04-17

my gradle dependencies are

  // Google Cloud Storage Client Library
  // https://cloud.google.com/storage/docs/reference/libraries#client-libraries-install-java
  implementation platform('com.google.cloud:libraries-bom:25.4.0')
  implementation 'com.google.cloud:google-cloud-storage'  
  
  //https://cloud.google.com/bigquery/docs/quickstarts/quickstart-client-libraries#client-libraries-install-java
  implementation 'com.google.cloud:google-cloud-bigquery:2.13.6'

Kind regards

Andy

github-actions bot pushed a commit that referenced this issue Oct 10, 2022
* chore: [java] generation with shared deps 3.0.4

* fix for tests
Source-Link: https://togithub.com/googleapis/synthtool/commit/c3ad3cc9d876a3dd897cc511cf5ef921784851ae
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-java:latest@sha256:5643a4e1b729803e67ddceee450e87052527b37cac394bf900b4f8e3d1bb3e9b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigquery Issues related to the BigQuery API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

6 participants