-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
feat:Spanner pg samples #1661
feat:Spanner pg samples #1661
Conversation
d33aa55
to
6ec4e6b
Compare
spanner/api/Spanner.Samples.Tests/UpdatePostgreSqlUsingBatchDmlAsyncTest.cs
Outdated
Show resolved
Hide resolved
9103370
to
cf74af7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Structure and overall looks good. Just a few comments.
@@ -1,11 +1,11 @@ | |||
<Project Sdk="Microsoft.NET.Sdk"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what changed in this line, revert it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still here. Revert the changes on this whole file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reverted the entire file. However, still seeing it. I will seek your help to revert this tomorrow.
spanner/api/Spanner.Samples.Tests/CreateDatabaseAsyncPostgreTest.cs
Outdated
Show resolved
Hide resolved
spanner/api/Spanner.Samples.Tests/CastDataTypesAsyncPostgreTest.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed review comments
@@ -388,6 +433,13 @@ private async Task InitializeBackupAsync() | |||
} | |||
} | |||
|
|||
private async Task InitializePostgreSqlDatabaseAsync() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initialize Database creates a PG database as well as couple of tables namely Singers and Albums. There is another sample which depicts the ordering of NULL (Nulls First, Nulls Last etc.) that creates a different version of Singers table and inserted data is then ordered in different ways. To keep the sample consistent and inline with other languages and to avoid the chances of duplicate data being inserted, I also created a CreateEmptyPostgreSqlDatabase method. I will also share this sample in next batch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few nits but otherwise looks good. Feel free to apply the changes here and create the PR containing the next batch (with relevant changes there as well acording to this PR's comments.)
@@ -1,11 +1,11 @@ | |||
<Project Sdk="Microsoft.NET.Sdk"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still here. Revert the changes on this whole file.
var createOperation = await databaseAdminClient.CreateDatabaseAsync(createDatabaseRequest); | ||
|
||
// Wait until the operation has finished. | ||
Console.WriteLine("Waiting for the operation to finish."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just a nit, but when you run this sample this text will be printed twice, once for creating the db and once for adding the tables. Consider distinguising the two as in "Waiting for the DB to be created" and "Waiting for the tables to be created."
Here and everywhere where there's something like this happening.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Assert.Contains(databases, d => d.DatabaseName.DatabaseId == databaseId); | ||
Assert.Equal(DatabaseDialect.Postgresql, databases.FirstOrDefault(j=> j.DatabaseName.DatabaseId == databaseId).DatabaseDialect); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assert.Contains(databases, d => d.DatabaseName.DatabaseId == databaseId); | |
Assert.Equal(DatabaseDialect.Postgresql, databases.FirstOrDefault(j=> j.DatabaseName.DatabaseId == databaseId).DatabaseDialect); | |
Assert.Contains(databases, d => d.DatabaseName.DatabaseId == databaseId && d.DatabaseDialect == ....); | |
databaseId).DatabaseDialect); |
var result = await command.ExecuteScalarAsync(); | ||
if (result is string statement) | ||
{ | ||
Console.WriteLine(statement); | ||
return statement; | ||
} | ||
|
||
return string.Empty; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var result = await command.ExecuteScalarAsync(); | |
if (result is string statement) | |
{ | |
Console.WriteLine(statement); | |
return statement; | |
} | |
return string.Empty; | |
var result = await command.ExecuteScalarAsync<string>(); | |
Console.WriteLine(result); | |
return result; |
@@ -388,6 +433,13 @@ private async Task InitializeBackupAsync() | |||
} | |||
} | |||
|
|||
private async Task InitializePostgreSqlDatabaseAsync() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, so then CreateEmpty... should be on the PR that uses it if posssible.
ddef70b
to
1a36f4a
Compare
1a36f4a
to
40f08de
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart from the specific change requests I have several PR wide comments.
- There's a lot of information in comments inside the samples that should really be part of documentation sorrounding the sample instead. In that way, it doesn't have to be repeated across languages and it is maintained by TWs. Comments in samples should explain something particular of the language, i.e. something that is just needed for the .NET library for instance; and maybe small notes making reference to documentation, but not the whole explanation.
- A lot of samples do many (related) things and we tend to prefer simpler samples. The current samples are harder to test and possibly harder for users to figure out (for instance the ORDER BY, the name Identifier samples, etc.)
- Some samples create database and tables, some samples create tables and some samples asume everything they need is already created. We need consistency here and also sample simplification. If someone wants to see how to execute a command they probably don't need the whole create database => create table => execute command. If some samples are creating DBs to avoid flakyness, then those should be created in the corresponding tests but not on the samples themselves.
- It's not clear to me that all samples and samples tests that are creating DBs are doing so because of flakyness. We are already blowing Spanner quota ocasionally, if we continut to create DBs without needing them these tests will never pass. Take a look at Spanner: Refactor the test fixture. #1425. In addition consider creating a separate Fixture for PG.
- See if you can reuse samples for the Spanner dialect, all of those that are the same, simply add the PG region tag on the existing one.
I know some of these issues are not because decisions you have made, but we should discus them nonetheless. Let's chat tomorrow.
@@ -1,4 +1,4 @@ | |||
<Project Sdk="Microsoft.NET.Sdk"> | |||
<Project Sdk="Microsoft.NET.Sdk"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, this is weird, maybe a line ending or something. Let's not worry too much about this, but we can take a look later.
spanner/api/Spanner.Samples/UsePgNumericDataTypeAsyncPostgre.cs
Outdated
Show resolved
Hide resolved
spanner/api/Spanner.Samples/UsePgNumericDataTypeAsyncPostgre.cs
Outdated
Show resolved
Hide resolved
spanner/api/Spanner.Samples/UsePgNumericDataTypeAsyncPostgre.cs
Outdated
Show resolved
Hide resolved
spanner/api/Spanner.Samples/UsePgNumericDataTypeAsyncPostgre.cs
Outdated
Show resolved
Hide resolved
// The returned count is the lower bound of the number of records that was deleted. | ||
long rowCount = await cmd.ExecutePartitionedUpdateAsync(); | ||
|
||
Console.WriteLine($"{rowCount} row(s) deleted..."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Console.WriteLine($"{rowCount} row(s) deleted..."); | |
Console.WriteLine($"At least {rowCount} row(s) deleted..."); |
public async Task AddStoringIndexAsyncPostgre(string projectId, string instanceId, string databaseId) | ||
{ | ||
string connectionString = $"Data Source=projects/{projectId}/instances/{instanceId}/databases/{databaseId}"; | ||
string createIndexStatement = "CREATE INDEX SingersBySingerName ON Singers(FirstName) INCLUDE(LastName, SingerInfo)"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this one different to what you would do for normal Spanner. Do we have a sample that does this for normal Spanner already?
If the answer to both questions above is yes, then you can just add the posgre region tag to the existing sample without the need of duplicating the sample and tests code.
And this applies to all other samples where there's no distinction between both dialects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed Amanda, only samples that are different from Standard SQL are chosen for PostgreSQL dialect.
@@ -30,11 +30,12 @@ | |||
|
|||
[CollectionDefinition(nameof(SpannerFixture))] | |||
public class SpannerFixture : IAsyncLifetime, ICollectionFixture<SpannerFixture> | |||
{ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert
public string ProjectId { get; } = Environment.GetEnvironmentVariable("GOOGLE_PROJECT_ID"); | ||
// Allow environment variables to override the default instance and database names. | ||
public string InstanceId { get; } = Environment.GetEnvironmentVariable("TEST_SPANNER_INSTANCE") ?? "my-instance"; | ||
public string DatabaseId { get; } = Environment.GetEnvironmentVariable("TEST_SPANNER_DATABASE") ?? $"my-db-{DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()}"; | ||
public string PostgreSqlDatabaseId { get; } = Environment.GetEnvironmentVariable("TEST_SPANNER_POSTGRESQL_DATABASE") ?? $"my-db-{DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it'd make more sense to add a new fixture for PG. We can do that later though.
697674d
to
66e63e4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed review comments. The following changes are now done:
- Removed comments that should be in documentation. Have kept only short summary now.
- Refactored tests and samples, so that new database is not created. To avoid data insertion conflicts, distinct data specific to the test scenario is inserted in tests as needed.
public async Task AddStoringIndexAsyncPostgre(string projectId, string instanceId, string databaseId) | ||
{ | ||
string connectionString = $"Data Source=projects/{projectId}/instances/{instanceId}/databases/{databaseId}"; | ||
string createIndexStatement = "CREATE INDEX SingersBySingerName ON Singers(FirstName) INCLUDE(LastName, SingerInfo)"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed Amanda, only samples that are different from Standard SQL are chosen for PostgreSQL dialect.
// limitations under the License. | ||
|
||
// [START spanner_postgresql_identifier_case_sensitivity] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
{ | ||
string connectionString = $"Data Source=projects/{projectId}/instances/{instanceId}/databases/{databaseId}"; | ||
|
||
DatabaseAdminClient databaseAdminClient = await DatabaseAdminClient.CreateAsync(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Apart from one sample, none of the samples or tests create database now.
|
||
// This returns the singers in the order NULL, Bruce, Alice. | ||
selectCommand = connection.CreateSelectCommand("SELECT name FROM singers ORDER BY name DESC"); | ||
using var dataReader = await selectCommand.ExecuteReaderAsync(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
@@ -388,6 +433,13 @@ private async Task InitializeBackupAsync() | |||
} | |||
} | |||
|
|||
private async Task InitializePostgreSqlDatabaseAsync() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CreateEmptyPostgreSqlDatabaseAsync
and ListTableNamesAsync
are now removed from fixture.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Rishabh! These look good. LGTM
I'm marking this PR as do not merge
just because we need production changes released first.
@Rishabh-V I think we might need to increase the overall timeout for Spanner samples. You can do that in the |
Is my assumption right that we still need to release some library changes or has everything been released already. |
Thanks Amanda!
Sure Amanda. Timeout is currently set to 7200 seconds. Should I increase it to 9000 seconds?
Right Amanda. I believe PgNumeric is not released yet. |
Let's wait for the timeout until we can actually build the PR, as right now it is failing because it's missing PgNumeric as expected. So, nothing to do for now. Thanks! |
66e63e4
to
4300d7d
Compare
25b5654
to
bdbf49b
Compare
bdbf49b
to
cd54754
Compare
cd54754
to
0c7de74
Compare
First draft of Spanner PostgreSQL dialect samples for feedback. The samples depend on v3.14.0 of C# Spanner client library which were created locally for sample creation and testing.