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

[WIP; broken] Use event_parser crate for natural language date parsing #12

Open
wants to merge 3 commits into
base: next
Choose a base branch
from

Conversation

allquixotic
Copy link

Removing our dependency on forking and execing Python to call on the dateparser library, we can use the event_parser Rust crate which provides similar functionality (but not equivalent).

One limitation of event_parser that is immediately obvious vs. python-dateparser is the lack of non-English language support.

At this point, the event_parser code successfully produces an accurate UNIX timestamp and returns it from the time_parser::natural_parser() for a few simple English-language test cases, like in 20 minutes or 20 minutes ago.

What doesn't work is something deep within reminderbot. You can find a panic stack trace here: https://gist.github.com/allquixotic/c908e043dff4ff9219463209756d0618

This stack trace is from /remind time: in 20 minutes content: blah, and I verified through println!() in time_parser::natural_parser() that a valid UNIX timestamp is being returned to the caller.

This PR contains several crate version bumps, so that may have something to do with the crash.

@JellyWX
Copy link
Contributor

JellyWX commented Dec 1, 2022

Error seems to be from this query:

let queried_time = sqlx::query!(

I don't know why I even wrote it to query directly like that. Not sure exactly why it's failing, though. Are you running MySQL 8 on your local?

@@ -25,6 +25,11 @@ rand = "0.8"
levenshtein = "1.0"
sqlx = { version = "0.6", features = ["runtime-tokio-rustls", "macros", "mysql", "bigdecimal", "chrono"]}
base64 = "0.13"
event_parser = { git = "https://github.com/allquixotic/event-parser", branch = "icalendar-bump" }
Copy link
Contributor

Choose a reason for hiding this comment

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

I'll probably create a fork of this branch under this GitHub org, just to keep everything in one place

Copy link
Author

Choose a reason for hiding this comment

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

Sounds good. The icalendar bump was the minimum work needed just to get this to compile, run, and return a reasonable result, but if you intend to (like you hinted in Discord) maintain event_parser longer term and add features, this is a great idea.

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps not fully maintain, but it certainly opens up some more possibilities if tweaks are required :)

pub async fn natural_parser(time: &str, _timezone: &str) -> Option<i64> {
println!("natural_parser of {}", time);
let evt = to_event(time);
println!("to_event: {}", evt.to_string());
Copy link
Contributor

Choose a reason for hiding this comment

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

Worth either removing these or switching to "info!"/"debug!" before merging (I know this is still WIP, just commenting so its not forgotten :))

Copy link
Author

Choose a reason for hiding this comment

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

For sure. I'll update them to debug!.

@allquixotic
Copy link
Author

allquixotic commented Dec 1, 2022

Error seems to be from this query:

let queried_time = sqlx::query!(

I don't know why I even wrote it to query directly like that. Not sure exactly why it's failing, though. Are you running MySQL 8 on your local?

I'm running MariaDB 10.6.x on Ubuntu 22.04. Sorry; the instructions didn't specify MySQL specifically (vs. MariaDB), and there are quite some differences between the two products now. I had to adjust that query for MariaDB support, but I'm not even sure if my fix was correct, or if I should abandon MariaDB support and just install Oracle MySQL.

I used MariaDB because an up-to-date version is available in the Ubuntu package manager without a third-party package; and because of the preferential licensing and support situation for MariaDB vs. MySQL (in my opinion).

@JellyWX
Copy link
Contributor

JellyWX commented Dec 1, 2022

Ah okay, really it'd be good to avoid totally non-standard SQL stuff that will break Maria. I can have a look at modifying the query there maybe, or removing it entirely

@allquixotic
Copy link
Author

I also had issues with the migration queries that are used to create the DB. I might open a separate PR about that.

One issue I recall was RENAME COLUMN only exists in MariaDB >= 10.5, and I was running 10.3 initially. I did an Ubuntu distro version upgrade to get to 10.6, and that problem went away, but MariaDB 10.3 was released in 2017, and is frequently in use with Debian and Ubuntu LTS releases from 2020 and earlier.

There was also an issue with a column being created with a default value of NULL for a timestamp column; I had to add NULL before the keyword TIMESTAMP to fix that. And the list goes on...

@JellyWX
Copy link
Contributor

JellyWX commented Dec 10, 2022

@JellyWX
Copy link
Contributor

JellyWX commented Dec 10, 2022

I also had issues with the migration queries that are used to create the DB. I might open a separate PR about that.

One issue I recall was RENAME COLUMN only exists in MariaDB >= 10.5, and I was running 10.3 initially. I did an Ubuntu distro version upgrade to get to 10.6, and that problem went away, but MariaDB 10.3 was released in 2017, and is frequently in use with Debian and Ubuntu LTS releases from 2020 and earlier.

There was also an issue with a column being created with a default value of NULL for a timestamp column; I had to add NULL before the keyword TIMESTAMP to fix that. And the list goes on...

Sorry, I didn't see this message. MySQL is a bit of a curse: realistically, I'd love to move to Postgres, but the amount of effort that requires is immense. I'd accept a PR to improve SQL compatibility, but it does need to remain compatible with MySQL 8 just because I have other software running on the server, and I don't want to run a third database server.

I don't know the exact compatibility issues really. I can spin up a VM and go through and test some of this stuff

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.

2 participants