-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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: issue #8969 adding position function #8988
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -514,7 +514,9 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> { | |
SQLExpr::Struct { values, fields } => { | ||
self.parse_struct(values, fields, schema, planner_context) | ||
} | ||
|
||
SQLExpr::Position { expr, r#in } => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
self.sql_position_to_expr(*expr, *r#in, schema, planner_context) | ||
} | ||
_ => not_impl_err!("Unsupported ast node in sqltorel: {sql:?}"), | ||
} | ||
} | ||
|
@@ -704,7 +706,20 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> { | |
}; | ||
Ok(Expr::ScalarFunction(ScalarFunction::new(fun, args))) | ||
} | ||
|
||
fn sql_position_to_expr( | ||
&self, | ||
substr_expr: SQLExpr, | ||
str_expr: SQLExpr, | ||
schema: &DFSchema, | ||
planner_context: &mut PlannerContext, | ||
) -> Result<Expr> { | ||
let fun = BuiltinScalarFunction::InStr; | ||
let substr = | ||
self.sql_expr_to_logical_expr(substr_expr, schema, planner_context)?; | ||
let fullstr = self.sql_expr_to_logical_expr(str_expr, schema, planner_context)?; | ||
let args = vec![fullstr, substr]; | ||
Ok(Expr::ScalarFunction(ScalarFunction::new(fun, args))) | ||
} | ||
fn sql_agg_with_filter_to_expr( | ||
&self, | ||
expr: SQLExpr, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it necessary to create a new file for in test 🤔 ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it is necessary, but I also don't think it hurts either. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
|
||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
# test position in select | ||
query I | ||
select position('world' in 'hello world'); | ||
---- | ||
7 | ||
|
||
|
||
|
||
# test in expression | ||
query I | ||
select 1000 where position('world' in 'hello world') != 100; | ||
---- | ||
1000 | ||
|
||
|
||
# test in expression | ||
query I | ||
select 100000 where position('legend' in 'league of legend') = 11; | ||
---- | ||
100000 | ||
|
||
|
||
# test in expression | ||
query I | ||
select 100000 where position('legend' in 'league of legend') != 11; | ||
---- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍