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

feat(pgwire):support portal description #3397

Merged
merged 7 commits into from
Jun 22, 2022
Merged

feat(pgwire):support portal description #3397

merged 7 commits into from
Jun 22, 2022

Conversation

ZENOTME
Copy link
Contributor

@ZENOTME ZENOTME commented Jun 22, 2022

I hereby agree to the terms of the Singularity Data, Inc. Contributor License Agreement.

What's changed and what's your intention?

Support portal type in describe message. It is required when using JDBC.

PLEASE DO NOT LEAVE THIS EMPTY !!!

Please explain IN DETAIL what the changes are in this PR and why they are needed:

  • Summarize your change (mandatory)
  • How does this PR work? Need a brief introduction for the changed logic (optional)
  • Describe clearly one logical change and avoid lazy messages (optional)
  • Describe any limitations of the current code (optional)
  • Add the 'user-facing changes' label if your PR contains changes that are visible to users (optional)

Checklist

  • I have written necessary docs and comments
  • I have added necessary unit tests and integration tests
  • All checks passed in ./risedev check (or alias, ./risedev c)

Refer to a related PR or issue link (optional)

#3392

@ZENOTME ZENOTME changed the title feature(pgwire):support portal description feat(pgwire):support portal description Jun 22, 2022
@codecov
Copy link

codecov bot commented Jun 22, 2022

Codecov Report

Merging #3397 (001f9c0) into main (aac69d2) will decrease coverage by 0.00%.
The diff coverage is 60.93%.

@@            Coverage Diff             @@
##             main    #3397      +/-   ##
==========================================
- Coverage   73.73%   73.72%   -0.01%     
==========================================
  Files         761      761              
  Lines      104467   104506      +39     
==========================================
+ Hits        77030    77049      +19     
- Misses      27437    27457      +20     
Flag Coverage Δ
rust 73.72% <60.93%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/utils/pgwire/src/pg_message.rs 74.18% <ø> (-0.01%) ⬇️
src/utils/pgwire/src/pg_protocol.rs 73.77% <47.05%> (-2.61%) ⬇️
src/utils/pgwire/src/pg_extended.rs 77.73% <76.66%> (-0.48%) ⬇️
src/frontend/src/expr/utils.rs 98.99% <0.00%> (-0.26%) ⬇️
src/common/src/types/ordered_float.rs 24.70% <0.00%> (-0.20%) ⬇️
src/meta/src/barrier/mod.rs 69.59% <0.00%> (+0.29%) ⬆️

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

let statement = cstr_to_str(&self.query_string).unwrap().to_owned();

if params.is_empty() {
return PgPortal {
let row_description =
if statement.starts_with("select") || statement.starts_with("SELECT") {
Copy link
Contributor

Choose a reason for hiding this comment

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

I' m not sure whether query can be sElEcT

if let Ok(rows) = session.infer_return_type(statement.as_str()).await {
rows
} else {
return Err(());
Copy link
Contributor

Choose a reason for hiding this comment

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

What about use ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What about use ?

infer_return_type -> Result<-, BoxedError>
We can't covert Result<-, BoxedError> to Result<-,()> when using '?'. Or is there another way can process it more concisely?

Copy link
Contributor

Choose a reason for hiding this comment

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

try .map_err?

Comment on lines 176 to 177
let row_description = if instance_query_string.starts_with("select")
|| instance_query_string.starts_with("SELECT")
Copy link
Contributor

Choose a reason for hiding this comment

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

This part of code is very similar to above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can extract a function inside portal?
fn infer_row_description(sql: &str,session: Arc<SM::Session>,) -> Result<Vec<PgFieldDescriptor>, ()>

Comment on lines 313 to 320
// TODO: Error Handle
todo!()
Copy link
Contributor

Choose a reason for hiding this comment

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

Link a TODO issue in code. You can check #2366. Investigate whether we can improve Error in the pgwire-crates

Comment on lines 248 to 250
let session = self.session.clone().unwrap();
let portal = statement
.instance::<SM>(session, portal_name.clone(), &m.params)
Copy link
Contributor

Choose a reason for hiding this comment

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

directly self.session.clone(). No need for a temporal variable here.

// NOTE Error handle need modify later.
named_statements.get(&name).unwrap()
};
if m.kind == b'S' {
Copy link
Contributor

Choose a reason for hiding this comment

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

Add some comments explain what is 'S' or 'P' ?

let statement = cstr_to_str(&self.query_string).unwrap().to_owned();

if params.is_empty() {
return PgPortal {
let row_description =
if statement.starts_with("select") || statement.starts_with("SELECT") {
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess you should take the first 6 characters and case-insensitively compare them with "select", which means you can convert all characters to lower-case. I don't know if "Select" would work?

Copy link
Contributor

@BowenXiao1999 BowenXiao1999 left a comment

Choose a reason for hiding this comment

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

Rest LGTM

Comment on lines 130 to 132
if sql.len() > 6 && sql[0..6].eq_ignore_ascii_case("select") {
session.infer_return_type(sql).await.map_err(|_e| ())
} else {
Ok(vec![])
}
Copy link
Contributor

Choose a reason for hiding this comment

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

     if sql.len() > 6 && sql[0..6].eq_ignore_ascii_case("select") {
         return session.infer_return_type(sql).await.map_err(|_e| ());
     } 

Ok(vec![])
 ```
     Try this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would it be more efficient

Copy link
Contributor

Choose a reason for hiding this comment

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

More clean. We should redcue the if-else pairs. One if is more readable than if-else

@BowenXiao1999 BowenXiao1999 linked an issue Jun 22, 2022 that may be closed by this pull request
@ZENOTME ZENOTME added the mergify/can-merge Indicates that the PR can be added to the merge queue label Jun 22, 2022
@mergify mergify bot merged commit 86e7742 into main Jun 22, 2022
@mergify mergify bot deleted the zj/portal_describe branch June 22, 2022 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mergify/can-merge Indicates that the PR can be added to the merge queue type/feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feature(pgwire):support portal description
3 participants