question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Inserting SpannerParameter.CommitTimestamp into Timestamp column with allow_commit_timestamp fails with exception

See original GitHub issue

Environment details

  • OS: Windows 8.1
  • .NET version: 4.6.2
  • Package name and version: Google.Cloud.Spanner.Data v2.0.0 beta 8

Steps to reproduce

I have the following table: (this is all test code, hence the lame names)

CREATE TABLE TypesTab (
        ID INT64 NOT NULL,
        NAME STRING(40),
        DESCRIPTION STRING(MAX),
        FLOATCOL FLOAT64,
        IS_ACTIVE BOOL,
        BYTESCOL BYTES(40),
        IMAGECOL BYTES(MAX),
        TIMESTAMPCOL_AUTO TIMESTAMP OPTIONS (allow_commit_timestamp = true),
        TIMESTAMPCOL TIMESTAMP,
        DATECOL DATE,
) PRIMARY KEY(ID)

I’m trying to insert the commit timestamp into the TIMESTAMPCOL_AUTO column. For this repro I use this code:


private static void InsertTest()
{
	using(var con = new SpannerConnection(CreateConnectionString()))
	{
		Console.WriteLine("Opening connection");
		con.Open();
		Console.WriteLine("Connection opened");

		var cmd = con.CreateCommand();
		cmd.CommandText = @"INSERT INTO `TypesTab` (`ID`, `TIMESTAMPCOL_AUTO`) VALUES (@p1, @p2)";
		cmd.Parameters.Add(new SpannerParameter("@p1", SpannerDbType.Int64, 1));
		cmd.Parameters.Add(new SpannerParameter("@p2", SpannerDbType.Timestamp, SpannerParameter.CommitTimestamp));
		var result = cmd.ExecuteNonQuery();
		Console.WriteLine("Number of rows affected: {0}", result);
	}
}


private static string CreateConnectionString()
{
	return $"Data Source=projects/{ProjectID}/instances/{InstanceID}/databases/{DatabaseID}";
}

This results in the following output/ exception:

Opening connection
Connection opened

Unhandled Exception: Google.Cloud.Spanner.Data.SpannerException: An invalid argument was sent to Spanner. ---> Grpc.Core.RpcException: Status(StatusCode=InvalidArgument, Detail="Value has type INT64 which cannot be inserted into column TIMESTAMPCOL_AUTO, which
has type TIMESTAMP [at 1:65]\nINSERT INTO `TypesTab` (`ID`, `TIMESTAMPCOL_AUTO`) VALUES (@p1, @p2)\n                                                                ^")
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Grpc.Core.Internal.ClientResponseStream`2.<MoveNext>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Grpc.Gcp.GcpClientResponseStream`2.<MoveNext>d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Google.Cloud.Spanner.V1.Internal.ExecuteHelper.<WithSessionExpiryChecking>d__0`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Google.Cloud.Spanner.V1.SqlResultStream.<ComputeNextAsync>d__21.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Google.Cloud.Spanner.V1.SqlResultStream.<MoveNext>d__20.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Google.Cloud.Spanner.V1.ReliableStreamReader.<MoveNextAsync>d__25.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Google.Cloud.Spanner.V1.ReliableStreamReader.<EnsureInitializedAsync>d__24.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Google.Cloud.Spanner.V1.ReliableStreamReader.<NextAsync>d__23.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Google.Cloud.Spanner.Data.SpannerTransaction.<>c__DisplayClass36_0.<<Google-Cloud-Spanner-Data-ISpannerTransaction-ExecuteDmlAsync>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Google.Cloud.Spanner.Data.ExecuteHelper.<WithErrorTranslationAndProfiling>d__2`1.MoveNext()
   --- End of inner exception stack trace ---
   at Google.Cloud.Spanner.Data.ExecuteHelper.<WithErrorTranslationAndProfiling>d__2`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Google.Cloud.Spanner.Data.EphemeralTransaction.<>c__DisplayClass3_0.<<ExecuteDmlAsync>g__Impl|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Google.Cloud.Spanner.Data.ExecuteHelper.<WithErrorTranslationAndProfiling>d__2`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Google.Cloud.Spanner.Data.SpannerCommand.ExecutableCommand.<ExecuteDmlAsync>d__28.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Google.Api.Gax.TaskExtensions.WaitWithUnwrappedExceptions(Task task)
   at Google.Cloud.Spanner.Data.SpannerCommand.ExecuteNonQuery()
   at SpannerTest.Program.InsertTest() in ************\SpannerTest\Program.cs:line 64
   at SpannerTest.Program.Main(String[] args) in ************\SpannerTest\Program.cs:line 17

Process finished with exit code -532.462.766.

I think I followed everything in the docs. The INT64 remark is weird, I don’t see what’s wrong here.

TIA.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
jskeetcommented, Mar 26, 2019

Right. I can raise the general Cloud Spanner docs internally - but I can change the .NET documentation more directly, so I’ll do that to start with 😃

1reaction
jskeetcommented, Mar 25, 2019

The good news is that I can reproduce it. Now to try to work out why it’s failing…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Commit timestamps in GoogleSQL-dialect databases
This topic describes how to write a commit timestamp for each insert and update operation that you perform with Spanner. To use this...
Read more >
Is it possible to set two column values with one being ` ...
The only exception would be if you intend to read from the commit timestamp column during the same transaction.
Read more >
Cannot insert multiple rows in one transaction with a commit ...
Problem you have encountered. Let's say there is a table with TIMESTAMP column with OPTIONS (allow_commit_timestamp=true) . If we try to execute two...
Read more >
Re: How to get the actual timestamp when the app h...
I have tried to add this in the beginning of the first script running: // Add the current date and time to column...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found