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

chore: do not use pg_settings due to a bug in the emulator #2570

Open
wants to merge 3 commits into
base: postgresql-dialect
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .ci/e2e-expected/backslash-dt.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,12 @@
testdb_e2e_psql_v?? | spanner_sys | table_operations_stats_hour | VIEW | | | | | | | | | | | | |
testdb_e2e_psql_v?? | spanner_sys | table_operations_stats_minute | VIEW | | | | | | | | | | | | |
testdb_e2e_psql_v?? | spanner_sys | table_sizes_stats_1hour | VIEW | | | | | | | | | | | | |
testdb_e2e_psql_v?? | spanner_sys | tasks | VIEW | | | | | | | | | | | | |
testdb_e2e_psql_v?? | spanner_sys | txn_stats_top_10minute | VIEW | | | | | | | | | | | | |
testdb_e2e_psql_v?? | spanner_sys | txn_stats_top_hour | VIEW | | | | | | | | | | | | |
testdb_e2e_psql_v?? | spanner_sys | txn_stats_top_minute | VIEW | | | | | | | | | | | | |
testdb_e2e_psql_v?? | spanner_sys | txn_stats_total_10minute | VIEW | | | | | | | | | | | | |
testdb_e2e_psql_v?? | spanner_sys | txn_stats_total_hour | VIEW | | | | | | | | | | | | |
testdb_e2e_psql_v?? | spanner_sys | txn_stats_total_minute | VIEW | | | | | | | | | | | | |
(77 rows)
(78 rows)

Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,14 @@ public String buildConnectionURL(String database) {
host = environment.get(SPANNER_EMULATOR_HOST_ENV_VAR);
usePlainText = true;
}
if (propertyMap != null
&& Boolean.parseBoolean(propertyMap.getOrDefault("autoConfigEmulator", "false"))) {
usePlainText = true;
}
if (propertyMap != null
&& Boolean.parseBoolean(propertyMap.getOrDefault("usePlainText", "false"))) {
usePlainText = true;
}
String endpoint;
if (host.isEmpty()) {
endpoint = "cloudspanner:/";
Expand All @@ -1041,8 +1049,7 @@ public String buildConnectionURL(String database) {
// Note that Credentials here is the credentials file, not the actual credentials
String url = String.format("%s%s;userAgent=%s", endpoint, databaseName, DEFAULT_USER_AGENT);

if (!shouldAuthenticate()
&& Strings.isNullOrEmpty(environment.get(SPANNER_EMULATOR_HOST_ENV_VAR))) {
if (!shouldAuthenticate() && !usePlainText) {
String credentials = buildCredentialsFile();
if (!Strings.isNullOrEmpty(credentials)) {
url = String.format("%s;credentials=%s", url, credentials);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,19 @@ public String generatePGSettingsCte() {
+ "\n),\n"
+ "pg_settings_names_ as (\n"
+ "select name from pg_settings_inmem_\n"
+ "union\n"
+ "select name from pg_catalog.pg_settings\n"
// TODO: Re-enable when the pg_settings table in the emulator has been fixed.
// + "union\n"
// + "select name from pg_catalog.pg_settings\n"
+ "),\n"
+ "pg_settings as (\n"
+ "select n.name, "
+ generatePgSettingsColumnExpressions()
+ "\n"
+ "from pg_settings_names_ n\n"
+ "left join pg_settings_inmem_ s1 using (name)\n"
+ "left join pg_catalog.pg_settings s2 using (name)\n"
// TODO: Re-enable when the pg_settings table in the emulator has been fixed.
// + "left join pg_catalog.pg_settings s2 using (name)\n"
+ "left join pg_settings_inmem_ s2 using (name)\n"
+ "order by name\n"
+ ")\n";
}
Expand Down
53 changes: 27 additions & 26 deletions src/test/csharp/pgadapter_npgsql_tests/npgsql_tests/NpgsqlTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void TestShowServerVersion()
while (reader.Read())
{
var version = reader.GetString(0);
Console.WriteLine($"{version}");
Console.Write($"{version}\n");
}
}
}
Expand All @@ -88,7 +88,7 @@ public void TestShowApplicationName()
while (reader.Read())
{
var applicationName = reader.GetString(0);
Console.WriteLine($"{applicationName}");
Console.Write($"{applicationName}\n");
}
}
}
Expand All @@ -113,7 +113,7 @@ public void TestSelect1()
return;
}
}
Console.WriteLine("Success");
Console.Write("Success\n");
}

public void TestSelectArray()
Expand All @@ -136,7 +136,7 @@ public void TestSelectArray()
return;
}
}
Console.WriteLine("Success");
Console.Write("Success\n");
}

public void TestQueryWithParameter()
Expand Down Expand Up @@ -165,7 +165,7 @@ public void TestQueryWithParameter()
return;
}
}
Console.WriteLine("Success");
Console.Write("Success\n");
}

public void TestQueryAllDataTypes()
Expand Down Expand Up @@ -245,7 +245,7 @@ public void TestQueryAllDataTypes()
}
}
}
Console.WriteLine("Success");
Console.Write("Success\n");
}

public void TestUpdateAllDataTypes()
Expand Down Expand Up @@ -279,7 +279,7 @@ public void TestUpdateAllDataTypes()
Console.WriteLine($"Update count mismatch. Got: {updateCount}, Want: 1");
return;
}
Console.WriteLine("Success");
Console.Write("Success\n");
}

public void TestInsertAllDataTypes()
Expand Down Expand Up @@ -313,7 +313,7 @@ public void TestInsertAllDataTypes()
Console.WriteLine($"Update count mismatch. Got: {updateCount}, Want: 1");
return;
}
Console.WriteLine("Success");
Console.Write("Success\n");
}

public void TestInsertNullsAllDataTypes()
Expand Down Expand Up @@ -348,7 +348,7 @@ public void TestInsertNullsAllDataTypes()
Console.WriteLine($"Update count mismatch. Got: {updateCount}, Want: 1");
return;
}
Console.WriteLine("Success");
Console.Write("Success\n");
}

public void TestInsertAllDataTypesReturning()
Expand Down Expand Up @@ -446,7 +446,7 @@ public void TestInsertAllDataTypesReturning()
}
}
}
Console.WriteLine("Success");
Console.Write("Success\n");
}

public void TestInsertBatch()
Expand Down Expand Up @@ -486,7 +486,7 @@ public void TestInsertBatch()
Console.WriteLine($"Update count mismatch. Got: {updateCount}, Want: {batchSize}");
return;
}
Console.WriteLine("Success");
Console.Write("Success\n");
}

public void TestMixedBatch()
Expand Down Expand Up @@ -572,7 +572,7 @@ public void TestMixedBatch()
return;
}
}
Console.WriteLine("Success");
Console.Write("Success\n");
}

public void TestBatchExecutionError()
Expand Down Expand Up @@ -609,7 +609,7 @@ public void TestBatchExecutionError()
try
{
var updateCount = batch.ExecuteNonQuery();
Console.WriteLine($"Update count: {updateCount}");
Console.Write($"Update count: {updateCount}\n");
}
catch (Exception exception)
{
Expand Down Expand Up @@ -683,7 +683,7 @@ constraint chk_end_time_after_start_time check (end_time > start_time)
Console.WriteLine($"Batch returned {updateCount} updates, expected -1.");
return;
}
Console.WriteLine("Success");
Console.Write("Success\n");
}

public void TestDdlScript()
Expand Down Expand Up @@ -757,7 +757,7 @@ constraint chk_end_time_after_start_time check (end_time > start_time)
Console.WriteLine($"Batch returned {updateCount} updates, expected -1.");
return;
}
Console.WriteLine("Success");
Console.Write("Success\n");
}

public void TestBinaryCopyIn()
Expand Down Expand Up @@ -799,7 +799,7 @@ public void TestBinaryCopyIn()
writer.Complete();
}

Console.WriteLine("Success");
Console.Write("Success\n");
}

public void TestTextCopyIn()
Expand Down Expand Up @@ -838,7 +838,7 @@ public void TestTextCopyIn()
writer.Write("\\N\n");
}

Console.WriteLine("Success");
Console.Write("Success\n");
}

public void TestBinaryCopyOut()
Expand Down Expand Up @@ -1085,7 +1085,7 @@ public void TestBinaryCopyOut()
Console.Write("\n");
}
}
Console.WriteLine("Success");
Console.Write("Success\n");
}

public void TestTextCopyOut()
Expand All @@ -1104,10 +1104,11 @@ public void TestTextCopyOut()
{
break;
}
Console.WriteLine(line);
Console.Write(line);
Console.Write("\n");
}
}
Console.WriteLine("Success");
Console.Write("Success\n");
}

public void TestSimplePrepare()
Expand All @@ -1118,7 +1119,7 @@ public void TestSimplePrepare()
var cmd = new NpgsqlCommand("SELECT * FROM all_types WHERE col_bigint=$1", connection);
cmd.Parameters.Add("param", NpgsqlDbType.Integer);
cmd.Prepare();
Console.WriteLine("Success");
Console.Write("Success\n");
}

public void TestPrepareAndExecute()
Expand Down Expand Up @@ -1168,7 +1169,7 @@ public void TestPrepareAndExecute()
return;
}
}
Console.WriteLine("Success");
Console.Write("Success\n");
}

public void TestReadWriteTransaction()
Expand All @@ -1185,7 +1186,7 @@ public void TestReadWriteTransaction()
{
while (reader.Read())
{
Console.WriteLine("Row: " + reader.GetInt64(0));
Console.Write("Row: " + reader.GetInt64(0) + "\n");
}
}
var insertSql =
Expand Down Expand Up @@ -1223,7 +1224,7 @@ public void TestReadWriteTransaction()
}
}
transaction.Commit();
Console.WriteLine("Success");
Console.Write("Success\n");
}

public void TestReadOnlyTransaction()
Expand All @@ -1242,12 +1243,12 @@ public void TestReadOnlyTransaction()
using var reader = selectCommand.ExecuteReader();
while (reader.Read())
{
Console.WriteLine("Row: " + reader.GetInt64(0));
Console.Write("Row: " + reader.GetInt64(0) + "\n");
}
}
// We need to either commit or rollback the transaction to release the underlying resources.
transaction.Commit();
Console.WriteLine("Success");
Console.Write("Success\n");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ public void testBuildConnectionUrl() {
// Enable the autoConfigEmulator flag through the options builder.
OptionsMetadata emulatorOptions = OptionsMetadata.newBuilder().autoConfigureEmulator().build();
assertEquals(
"cloudspanner:/projects/my-project/instances/my-instance/databases/my-database;userAgent=pg-adapter;autoConfigEmulator=true;dialect=postgresql",
"cloudspanner:/projects/my-project/instances/my-instance/databases/my-database;userAgent=pg-adapter;usePlainText=true;autoConfigEmulator=true;dialect=postgresql",
buildConnectionURL(
"projects/my-project/instances/my-instance/databases/my-database",
emulatorOptions,
Expand Down
Loading
Loading