-
-
Notifications
You must be signed in to change notification settings - Fork 226
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
Retrieve function source description from comments #829
Conversation
f1969c3
to
37cb490
Compare
martin/src/pg/function_source.rs
Outdated
@@ -13,6 +15,14 @@ use crate::pg::pool::PgPool; | |||
use crate::pg::PgError::PostgresError; | |||
use crate::pg::Result; | |||
|
|||
#[derive(Serialize, Deserialize, Debug)] |
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.
use TileJSON
object here - no point in creating a new struct. Simply parse TileJSON
from the comment
@@ -13,3 +13,25 @@ RETURNS TABLE("mVt" bytea, key text) AS $$ | |||
WHERE "Geom" && ST_Transform(ST_TileEnvelope("Z", x, y), 4326) | |||
) as tile WHERE geom IS NOT NULL) src | |||
$$ LANGUAGE SQL IMMUTABLE STRICT PARALLEL SAFE; | |||
|
|||
COMMENT ON FUNCTION "MixedCase"."function_Mixed_Name" (int4,INT4,INT4) IS $tilejson$ |
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.
See if you can modify these somehow to auto-verified with '{...}'::json
approach instead of a unverified string
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.
Weired. PostgreSQL complained syntax error. Need a little bit research on.
COMMENT ON FUNCTION osm_trees(INTEGER,INTEGER,INTEGER) IS ('{"a":1}'::json::TEXT)
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.
Seems it only receive literal value? doc
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.
@sharkAndshark use this method:
DO $do$ BEGIN
EXECUTE 'COMMENT ON FUNCTION public.function_null (INT4,INT4,INT4) IS $tj$' || $$
{
"minzoom": 0,
"maxzoom": 18,
"bounds": [-180, -85, 180, 85],
"vector_layers": []
}
$$::json || '$tj$';
END $do$;
eb929e0
to
e786204
Compare
Hi @nyurik Could you give me some suggestions for fixing the errors in SQL files? I've tried many times. Update: |
usually you don't need to quote any identifiers (namespaces, tables, functions and their arguments, etc) in SQL, as long as they don't use any special characters or reserved keywords. BUT, in some very rare cases, someone may have those weird cases. So in our testing, we must make sure Martin supports it properly. And for that, I have a few tests like Note that the generated SQL automatically always uses quotes identifiers to avoid ambiguity. |
95ed89e
to
7f6fa16
Compare
I reworked your patch in sharkAndshark#50 -- please take a look and merge if agree. Basic idea:
P.S. I don't think you should add tilejson to ALL unit tests. Instead, add it to just a few, with some variation of which fields are added, and possibly even deleted (set them to null). |
Agreed.I realized the tests part and I'm in a conference,merge it later. |
To achieve isolation, it is recommended to have one unit test for each observable behavior. Therefore, it might be necessary to remove some comments from the function. However, there is a concern that this level of granularity might be excessive?(And we can not see them on |
@sharkAndshark lets keep things simple :) I think we need to cover these cases. And I think you can do this with just two function comments. Test 1
Test 2
Just doing these two tests, you should be good enough. |
7665ae7
to
b7c2459
Compare
I hope the doc is not too bad as English is not my first language and I'm still learning it. |
b7c2459
to
99d09a9
Compare
@@ -33,6 +34,18 @@ pub async fn query_available_function(pool: &PgPool) -> Result<SqlFuncInfoMapMap | |||
let output_record_names = jsonb_to_vec(&row.get("output_record_names")); | |||
let input_types = jsonb_to_vec(&row.get("input_types")).expect("Can't get input types"); | |||
let input_names = jsonb_to_vec(&row.get("input_names")).expect("Can't get input names"); | |||
let tilejson = if let Some(text) = row.get("description") { | |||
match serde_json::from_str::<Value>(text) { |
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.
parsing now works because it now uses from_str::<Value>
instead of from_str::<TileJSON>
. Value allows any valid json.
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.
Yeah. hehe. I realized that lol. Cool. ✅
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.
great work, thanks!
Thanks @sharkAndshark , i may do another round of docs cleanup later, but this is good to merge for now. Do you perhaps want to do the same thing for tables? I suspect it is possible to add comments to them too. |
Yeah sure. I'd love to do that. A issue ticket for discussion first maybe? @nyurik |
technically that's the same issue #822 issue - although it is more of an umbrella issue to cover all tilejson modifications by the user. Eventually I think we should just add an extra field to the yaml config, and that field will work the same way as the function comment |
If a PostgreSQL function has an SQL comment, it will try to parse as JSON and use its values to override the auto-generated TileJSON. It is recommended to use this form when creating comments to ensure valid JSON values.
Partially implements #822