Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: sql fn params#366

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
psteinroe merged 17 commits intomainfromfix/fn-params
May 22, 2025
Merged

fix: sql fn params#366

psteinroe merged 17 commits intomainfromfix/fn-params
May 22, 2025

Conversation

psteinroe
Copy link
Collaborator

@psteinroepsteinroe commentedApr 22, 2025
edited
Loading

the idea is to replace the fn params with a default value based on their type:

create or replacefunctionusers.select_no_ref (user_id int4) returns table (    first_nametext) language sql security invokeras $$select    first_nameFROMusers_hidden.userswhere     id= user_id;$$;

will become

create or replacefunctionusers.select_no_ref (user_id int4) returns table (    first_nametext) language sql security invokeras $$select    first_nameFROMusers_hidden.userswhere     id=0;-- <-- here$$;

Todo

  • pass params to typechecker
  • implementapply_identifiers

fixes#353
fixes#352

@psteinroepsteinroe marked this pull request as ready for reviewMay 7, 2025 08:07
Copy link
Contributor

@CopilotCopilotAI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes SQL function parameter substitution by replacing function parameters with type‐based default values while refactoring SQL function signature extraction and integrating these changes into the typecheck flow.

  • Added utility methods to StatementId.
  • Refactored SQL function parsing to utilize SQLFunctionSignature and SQLFunctionArgs.
  • Updated document parsing, typecheck, and identifier application with improved default value resolution.

Reviewed Changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 3 comments.

Show a summary per file
FileDescription
crates/pgt_workspace/src/workspace/server/statement_identifier.rsAdded helper methods (is_root, is_child, parent) for statement hierarchy.
crates/pgt_workspace/src/workspace/server/sql_function.rsIntroduced SQLFunctionSignature and revamped function parameter extraction.
crates/pgt_workspace/src/workspace/server/parsed_document.rsRemoved legacy SQLFunctionBodyStore and integrated new SQL function extraction.
crates/pgt_workspace/src/workspace/server/document.rsAdded statement_content method to get statement SQL content.
crates/pgt_workspace/src/workspace/server.rsUpdated typecheck integration with new schema cache and identifier handling.
crates/pgt_typecheck/src/typed_identifier.rsEnhanced apply_identifiers with default value formatting and support for type-based defaults.
crates/pgt_treesitter_queriesUpdated parameter extraction queries and tests for ParameterMatch.
Other filesMinor adjustments to tests, diagnostics, and schema cache types to support the changes.
Comments suppressed due to low confidence (1)

crates/pgt_workspace/src/workspace/server.rs:376

  • [nitpick] The async block here could be refactored for improved readability and maintainability. A clearer structure may help future developers understand the schema cache and identifier propagation logic.
// sorry for the ugly code :(

psteinroeand others added4 commitsMay 7, 2025 10:12
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Collaborator

@juleswritescodejuleswritescode left a comment

Choose a reason for hiding this comment

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

just details, the concept looks great!

Comment on lines 335 to 338
assert_eq!(
sql_out,
"select 0 + 0 + 0 + 0 + 0 + NULL "
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
assert_eq!(
sql_out,
"select 0 + 0 + 0 + 0 + 0 + NULL "
);
// the numeric parameters are filled with 0; the enum does not have a default, so it's filled with `null`
assert_eq!(
sql_out,
"select 0 + 0 + 0 + 0 + 0 + NULL "
);

db: DashMap<StatementId, Option<Arc<SQLFunctionBody>>>,
#[derive(Debug, Clone)]
pub struct SQLFunctionSignature {
pub name: (Option<String>, String),
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: i think it would be more readable if it had aname and aschema property

pub struct SQLFunctionBody {
pub range: TextRange,
pub body: String,
pub struct SQLFunctionArgs {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is a singleArg right?

Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

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

yes!

//If not cached, try to extract itfromthe AST
letfn_body =get_sql_fn(ast, content).map(Arc::new);
//Extract languagefromfunction options
letlanguage =find_option_value(create_fn, "language")?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

i really like that api

Comment on lines +85 to +86
// If the default value is longer than "NULL", use "NULL" instead
"NULL".to_string()
Copy link
Collaborator

Choose a reason for hiding this comment

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

why are we doing this?

Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

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

because we need to throw away positions when the replacement is longer than its original, andNULL will be shorter than a few default values (e.g. timestamps or custom enums)

@psteinroepsteinroe merged commit7ffbca6 intomainMay 22, 2025
7 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@juleswritescodejuleswritescodejuleswritescode approved these changes

Copilot code reviewCopilotCopilot left review comments

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
2 participants
@psteinroe@juleswritescode

[8]ページ先頭

©2009-2025 Movatter.jp