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: add DataType::Char and add LEN to Describe #174

Merged
merged 8 commits into from
Mar 21, 2024

Conversation

KKould
Copy link
Member

@KKould KKould commented Mar 21, 2024

What problem does this PR solve?

let _ = fnck_sql
    .run("CREATE TABLE TABLE_E021_02_01_05 ( ID INT PRIMARY KEY, A CHAR ( 8 ) )")
    .await?;
let (schema, tuples) = fnck_sql.run("describe TABLE_E021_02_01_05").await?;
println!("{}", create_table(&schema, &tuples));
+-------+---------+-----+-------+---------+---------+
| FIELD | TYPE    | LEN | NULL  | Key     | DEFAULT |
+===================================================+
| id    | INTEGER | 4   | false | PRIMARY | null    |
|-------+---------+-----+-------+---------+---------|
| a     | CHAR    | 8   | true  | EMPTY   | null    |
+-------+---------+-----+-------+---------+---------+

on mysql

mysql> insert into T1 (A) VALUES('      abc   ');
Query OK, 1 row affected (0.00 sec)

mysql> select * from T1;
+-----------+
| A         |
+-----------+
| abc       |
|       abc |
+-----------+
2 rows in set (0.00 sec)

Issue link: #130

Code changes

  • Has Rust code change
  • Has CI related scripts change

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Note for reviewer

@KKould KKould requested a review from crwen March 21, 2024 11:49
@KKould KKould self-assigned this Mar 21, 2024
@KKould KKould added the documentation Improvements or additions to documentation label Mar 21, 2024
@KKould KKould mentioned this pull request Mar 21, 2024
51 tasks
@KKould KKould added enhancement New feature or request and removed documentation Improvements or additions to documentation labels Mar 21, 2024
Copy link
Member

@crwen crwen left a comment

Choose a reason for hiding this comment

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

select * from t;
ERROR:  Unsupported Datatype CHAR

You need add LogicalType::Char to into_pg_type method

src/types/value.rs Outdated Show resolved Hide resolved
Comment on lines +453 to +460
// https://dev.mysql.com/doc/refman/8.0/en/char.html#:~:text=If%20a%20given%20value%20is%20stored%20into%20the%20CHAR(4)%20and%20VARCHAR(4)%20columns%2C%20the%20values%20retrieved%20from%20the%20columns%20are%20not%20always%20the%20same%20because%20trailing%20spaces%20are%20removed%20from%20CHAR%20columns%20upon%20retrieval.%20The%20following%20example%20illustrates%20this%20difference%3A
let value = (!bytes.is_empty()).then(|| {
let last_non_zero_index = match bytes.iter().rposition(|&x| x != b' ') {
Some(index) => index + 1,
None => 0,
};
String::from_utf8(bytes[0..last_non_zero_index].to_owned()).unwrap()
});
Copy link
Member

Choose a reason for hiding this comment

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

maybe use trim_end()

String::from_utf8(bytes.to_owned()).unwrap().trim_end();

and the link is too long 😂

Copy link
Member Author

@KKould KKould Mar 21, 2024

Choose a reason for hiding this comment

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

I tried it and it will make ' foo ' become 'foo', but it should be ' foo' in mysql

Copy link
Member

Choose a reason for hiding this comment

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

trim_end only remove trailing whitespace. You might used trim().

Copy link
Member Author

Choose a reason for hiding this comment

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

trim_end only remove trailing whitespace. You might used trim().

oh, you are right, but I found that trim_end() returns &str, which may cause String to be copied again.

@KKould KKould requested a review from crwen March 21, 2024 16:19
@KKould KKould merged commit 253daa8 into KipData:main Mar 21, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants