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

fix: add full_match_handler.go to convert the query. #299

Open
wants to merge 23 commits into
base: main
Choose a base branch
from

Conversation

TianyuZhang1214
Copy link
Contributor

@TianyuZhang1214 TianyuZhang1214 commented Dec 19, 2024

This PR resolves issues #297 and #316, addressing compatibility challenges with Npgsql in C#.

Issue 1: Real Data for PostgreSQL System Tables

In PostgresDatabaseInfo.cs, 4 hard-coded queries are executed, with the results accessed via ReadNonNullableString. To ensure compatibility and non-null results, real PostgreSQL system table data are mirrored in MyDuck Server. Additionally, all PostgreSQL system table queries are redirected to their corresponding __sys__.pg_xxx tables in DuckDB.

Issue 2: Discontinuous Data in Batches

As discussed in #316, query results are split into multiple batches and returned discontinuously due to each batch containing a separate RowDescription. This PR introduces a mechanism to ensure that only a single RowDescription is returned per statement execution, providing a continuous result stream for better compatibility with Npgsql.

@TianyuZhang1214 TianyuZhang1214 linked an issue Dec 19, 2024 that may be closed by this pull request
@fanyang01
Copy link
Collaborator

@NoyException Is this issue the final obstacle to making the C# client functional? If so, we should consider enabling the test in this PR.

@TianyuZhang1214
Copy link
Contributor Author

@NoyException Is this issue the final obstacle to making the C# client functional? If so, we should consider enabling the test in this PR.

I'll enable it.

@NoyException
Copy link
Contributor

@NoyException Is this issue the final obstacle to making the C# client functional? If so, we should consider enabling the test in this PR.

This is only the current obstacle, not the last one...

catalog/initial_data.go Outdated Show resolved Hide resolved
catalog/provider.go Outdated Show resolved Hide resolved
docker/Dockerfile Outdated Show resolved Hide resolved
catalog/provider.go Show resolved Hide resolved
@@ -0,0 +1,420 @@
oid,relname,relnamespace,reltype,reloftype,relowner,relam,relfilenode,reltablespace,relpages,reltuples,relallvisible,reltoastrelid,relhasindex,relisshared,relpersistence,relkind,relnatts,relchecks,relhasrules,relhastriggers,relhassubclass,relrowsecurity,relforcerowsecurity,relispopulated,relreplident,relispartition,relrewrite,relfrozenxid,relminmxid,relacl,reloptions,relpartbound
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to add a script for generating these files:

CONTAINER_ID=$(docker run --rm -d -e POSTGRES_PASSWORD=postgres postgres)
docker exec -i $CONTAINER_ID psql -U postgres -c '\COPY pg_class TO STDOUT (FORMAT CSV)' > pg_class.csv
...
docker kill $CONTAINER_ID

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This approach may not work with cloud vendors in China, as the machine might not be able to connect to Docker Hub.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean a script for maintainers to regenerate these files easily.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it.I'll leave a script with README later.


var queryPatterns = map[*regexp.Regexp]string{
regexp.MustCompile(`(?is)^SELECT\s+pg_type\.oid,\s*enumlabel\s+FROM\s+pg_enum\s+JOIN\s+pg_type\s+ON\s+pg_type\.oid=enumtypid\s+ORDER\s+BY\s+oid,\s+enumsortorder$`): "SELECT pg_type.oid, pg_enum.enumlabel FROM pg_enum JOIN pg_type ON pg_type.oid=enumtypid ORDER BY pg_type.oid, pg_enum.enumsortorder;",
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Such long regular expressions are expensive to evaluate. Could we does something like:

if removeSpace(inputQuery) == pattern {
    ...
}

where removeSpace is a faster implementation? https://stackoverflow.com/a/32081891

Copy link
Contributor Author

@TianyuZhang1214 TianyuZhang1214 Dec 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea! Will be fixed in next commit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support seemingly ambiguous reference
3 participants