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

Conditional DELETE from a table with a DATE column fails #4466

Closed
O1O1O1O opened this issue Feb 7, 2019 · 1 comment
Closed

Conditional DELETE from a table with a DATE column fails #4466

O1O1O1O opened this issue Feb 7, 2019 · 1 comment
Assignees
Labels
api: spanner Issues related to the Spanner API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@O1O1O1O
Copy link

O1O1O1O commented Feb 7, 2019

Thanks for stopping by to let us know something could be better!

Please include as much information as possible:

Environment details

  • OS: N/A
  • Java version: 1.8.0_162
  • google-cloud-java version(s): google-cloud-spanner 0.57.0-beta

Steps to reproduce

  1. Create table with schema including a DATE column eg.
CREATE TABLE geo_views (
	city STRING(MAX) NOT NULL,
	client_id INT64 NOT NULL,
	date DATE NOT NULL,
	domain STRING(MAX) NOT NULL,
	url STRING(MAX) NOT NULL,
	pageviews INT64 NOT NULL,
) PRIMARY KEY (client_id, domain, date DESC, city, url)
  1. Add some records.
  2. Delete from the table with a WHERE clause eg. DELETE FROM geo_views WHERE client_id > 1000

Stacktrace

Note this stacktrace comes from a delete when using the Olaviate Spanner JDBC driver which includes the latest Google Spanner client code as a shaded lib:

java.lang.AssertionError: Illegal key part: class nl.topicus.jdbc.shaded.com.google.cloud.Date
	at nl.topicus.jdbc.shaded.com.google.cloud.spanner.Key.toProto(Key.java:287)
	at nl.topicus.jdbc.shaded.com.google.cloud.spanner.KeySet.appendToProto(KeySet.java:204)
	at nl.topicus.jdbc.shaded.com.google.cloud.spanner.Mutation.toProto(Mutation.java:381)
	at nl.topicus.jdbc.shaded.com.google.cloud.spanner.SpannerImpl$TransactionContextImpl.commit(SpannerImpl.java:1394)
	at nl.topicus.jdbc.shaded.com.google.cloud.spanner.SpannerImpl$TransactionRunnerImpl.runInternal(SpannerImpl.java:1299)
	at nl.topicus.jdbc.shaded.com.google.cloud.spanner.SpannerImpl$TransactionRunnerImpl.run(SpannerImpl.java:1242)
	at nl.topicus.jdbc.shaded.com.google.cloud.spanner.SessionPool$PooledSession$1.run(SessionPool.java:398)
	at nl.topicus.jdbc.transaction.TransactionThread.run(TransactionThread.java:115)

Code snippet

I believe this error is caused by lack of support for the Date type in the if statement here: https://github.com/googleapis/google-cloud-java/blob/master/google-cloud-clients/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Key.java#L285

  ListValue toProto() {
    ListValue.Builder builder = ListValue.newBuilder();
    for (Object part : parts) {
      if (part == null) {
        builder.addValues(NULL_PROTO);
      } else if (part instanceof Boolean) {
        builder.addValuesBuilder().setBoolValue((Boolean) part);
      } else if (part instanceof Long) {
        builder.addValuesBuilder().setStringValue(part.toString());
      } else if (part instanceof Double) {
        builder.addValuesBuilder().setNumberValue((Double) part);
      } else if (part instanceof String) {
        builder.addValuesBuilder().setStringValue((String) part);
      } else if (part instanceof ByteArray) {
        builder.addValuesBuilder().setStringValue(((ByteArray) part).toBase64());
      } else if (part instanceof Timestamp) {
        builder.addValuesBuilder().setStringValue(((Timestamp) part).toString());
      } else {
        throw new AssertionError("Illegal key part: " + part.getClass());
      }
    }
    return builder.build();
  }

External references such as API reference guides used

See also: olavloite/spanner-jdbc#134

Any additional information below

I looked in the tests for this code but there aren't any because Key.toProto is not public and only used by higher level code in the client package. As best I can tell only an actual delete using a key based condition will trigger its use.

@yoshi-automation yoshi-automation added the triage me I really want to be triaged. label Feb 8, 2019
@sduskis sduskis added api: spanner Issues related to the Spanner API. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. priority: p2 Moderately-important priority. Fix may not be included in next release. and removed triage me I really want to be triaged. labels Feb 8, 2019
ajaaym added a commit to ajaaym/google-cloud-java that referenced this issue Feb 8, 2019
@O1O1O1O
Copy link
Author

O1O1O1O commented Feb 8, 2019

Thanks for the rapid turn around on fixing this @sduskis 🥇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the Spanner API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

3 participants