-
Notifications
You must be signed in to change notification settings - Fork 316
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
Support setting time range in Copy From
statement
#3511
Comments
hi @MichaelScofield ,i want to take this, would you give me some further advice? |
@naosense Sure. The "copy from" statement is parsed in file "copy_parser.rs", you can start from there. First you might want to see how "where" can be parsed in sqlparser. If lucky, the "copy from" statement from sqlparser may already carry the "where" part. Then you need to find how to extract the desired "time range" from the filters in "where". Finally set the time range in the struct |
I think we can add a |
After my initial research, I do not have much idea about solving this issue, probably because I am not familiar with the greptimedb and sqlparser. I hope someone can take over, I'm afraid this issue is beyond my ability😅. |
I spent quite a while trying to solve this problem. There has been a small progress, but since I am a newbie in rust, I find it difficult for me to solve rust syntax problems in a short time, such as error handling, type conversion, and syntax sugar. So I decided to post my progress here, welcome to discuss ideas. First I successfully parsed the where clause and got the expression. As a rookie, it took me a while to get if-else to return the same type of result... let predicate = if self.parser.parse_keyword(Keyword::WHERE) {
Some(self
.parser
.parse_expr()
.context(error::SyntaxSnafu)?;)
} else {
None
}; Then I found that the returned expression did not meet the needs of the issue. What needs to be returned here is timestampRange. So, the next step is to convert the expression in sql-parser into timestampRange. I think what can be done is to:
|
@naosense that's ok, feel free to take another good first issue! |
@okJiang we can make things a lot simpler by restricting the allowed syntax here. The filters in
where |
I am trying to solve this problem. It seems that I need to pass arguments to fn to_copy_table_request and I can
I can't find a elegant way to pass the parsed arugments.
Should I simply pass Expr to the to_copy_table_request function and parse it again, or are there some methods to make the WhereClause more elegant |
@kysshsy For simplicity, what about reusing the time range option? greptimedb/src/operator/src/statement.rs Line 335 in a3a2c8d
Then we use the time range to filter output record batches from files. If we'd like to support |
@kysshsy Since we've marked this issue as GFI, I think we can resort to a simple solution. We don't need to support complex time ranges expressed by greptimedb/src/table/src/requests.rs Line 231 in 090b59e
This will solve 90% use cases. Once we've built a record batch stream via
we can evaluate the batches yielded just like here: greptimedb/src/operator/src/statement/copy_table_to.rs Lines 104 to 135 in 40c5858
|
What type of enhancement is this?
User experience
What does the enhancement do?
As title.
Currently there's
timestamp_range: Option<TimestampRange>
field in thestruct CopyTableRequest
, but it's not set. We can set it from the SQL parser first, then check if it works.The
copy from
in postgresql supports "where condition" (https://www.postgresql.org/docs/current/sql-copy.html), maybe we can do that, too. For this issue, we can extract the time range from the "where condition", and leave more general filtering in the future.Implementation challenges
No response
The text was updated successfully, but these errors were encountered: