You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/11/12 11:42:35 UTC

[GitHub] [arrow-datafusion] Jefffrey opened a new pull request, #4188: Disallow duplicate interval types during parsing

Jefffrey opened a new pull request, #4188:
URL: https://github.com/apache/arrow-datafusion/pull/4188

   # Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   Closes #3183.
   
   # Rationale for this change
   
   <!--
    Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
    Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.  
   -->
   
   # What changes are included in this PR?
   
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   Keep track of interval types found during parsing as bitflag.
   
   Also refactor interval types to use an Enum to better serve above point.
   
   # Are these changes tested?
   
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   2. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
   -->
   
   Added unit test.
   
   # Are there any user-facing changes?
   
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!--
   If there are any breaking changes to public APIs, please add the `api change` label.
   -->


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #4188: Disallow duplicate interval types during parsing

Posted by GitBox <gi...@apache.org>.
alamb commented on code in PR #4188:
URL: https://github.com/apache/arrow-datafusion/pull/4188#discussion_r1022669455


##########
datafusion/common/src/parsers.rs:
##########
@@ -42,56 +82,72 @@ pub fn parse_interval(leading_field: &str, value: &str) -> Result<ScalarValue> {
             (month_part as i32, day_part as i32, milles_part)
         };
 
-    let calculate_from_part =
-        |interval_period_str: &str, interval_type: &str| -> Result<(i32, i32, f32)> {
-            // @todo It's better to use Decimal in order to protect rounding errors
-            // Wait https://github.com/apache/arrow/pull/9232
-            let interval_period = match f32::from_str(interval_period_str) {
-                Ok(n) => n,
-                Err(_) => {
-                    return Err(DataFusionError::NotImplemented(format!(
-                        "Unsupported Interval Expression with value {:?}",
-                        value
-                    )));
-                }
-            };
-
-            if interval_period > (i32::MAX as f32) {
+    let mut used_interval_types = 0;
+
+    let mut calculate_from_part = |interval_period_str: &str,
+                                   interval_type: &str|
+     -> Result<(i32, i32, f32)> {
+        // @todo It's better to use Decimal in order to protect rounding errors
+        // Wait https://github.com/apache/arrow/pull/9232
+        let interval_period = match f32::from_str(interval_period_str) {
+            Ok(n) => n,
+            Err(_) => {
                 return Err(DataFusionError::NotImplemented(format!(
-                    "Interval field value out of range: {:?}",
+                    "Unsupported Interval Expression with value {:?}",
                     value
                 )));
             }
+        };
 
-            match interval_type.to_lowercase().as_str() {
-                "century" | "centuries" => {
-                    Ok(align_interval_parts(interval_period * 1200_f32, 0.0, 0.0))
-                }
-                "decade" | "decades" => {
-                    Ok(align_interval_parts(interval_period * 120_f32, 0.0, 0.0))
-                }
-                "year" | "years" => {
-                    Ok(align_interval_parts(interval_period * 12_f32, 0.0, 0.0))
-                }
-                "month" | "months" => Ok(align_interval_parts(interval_period, 0.0, 0.0)),
-                "week" | "weeks" => {
-                    Ok(align_interval_parts(0.0, interval_period * 7_f32, 0.0))
-                }
-                "day" | "days" => Ok(align_interval_parts(0.0, interval_period, 0.0)),
-                "hour" | "hours" => {
-                    Ok((0, 0, interval_period * SECONDS_PER_HOUR * MILLIS_PER_SECOND))
-                }
-                "minute" | "minutes" => {
-                    Ok((0, 0, interval_period * 60_f32 * MILLIS_PER_SECOND))
-                }
-                "second" | "seconds" => Ok((0, 0, interval_period * MILLIS_PER_SECOND)),
-                "millisecond" | "milliseconds" => Ok((0, 0, interval_period)),
-                _ => Err(DataFusionError::NotImplemented(format!(
-                    "Invalid input syntax for type interval: {:?}",
-                    value
-                ))),
+        if interval_period > (i32::MAX as f32) {
+            return Err(DataFusionError::NotImplemented(format!(
+                "Interval field value out of range: {:?}",
+                value
+            )));
+        }
+
+        let it = IntervalType::from_str(interval_type).map_err(|_| {
+            DataFusionError::NotImplemented(format!(
+                "Invalid input syntax for type interval: {:?}",
+                value
+            ))
+        })?;
+
+        // Disallow duplicate interval types
+        if used_interval_types & (it as u16) != 0 {
+            return Err(DataFusionError::SQL(ParserError::ParserError(format!(
+                "Invalid input syntax for type interval: {:?}",
+                value
+            ))));

Review Comment:
   ```suggestion
           // Disallow duplicate interval types
           if used_interval_types & (it as u16) != 0 {
               return Err(DataFusionError::SQL(ParserError::ParserError(format!(
                   "Invalid input syntax for type interval: {:?}. Repeated type {}",
                   value, interval_type
               ))));
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] alamb commented on pull request #4188: Disallow duplicate interval types during parsing

Posted by GitBox <gi...@apache.org>.
alamb commented on PR #4188:
URL: https://github.com/apache/arrow-datafusion/pull/4188#issuecomment-1317347420

   Thanks again @Jefffrey !


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] ursabot commented on pull request #4188: Disallow duplicate interval types during parsing

Posted by GitBox <gi...@apache.org>.
ursabot commented on PR #4188:
URL: https://github.com/apache/arrow-datafusion/pull/4188#issuecomment-1317359313

   Benchmark runs are scheduled for baseline = b7a33c9897ddf468ea0801fcac5eecb455f8780a and contender = d52234fb9232326da6e69d9cd9dfaa5293808eba. d52234fb9232326da6e69d9cd9dfaa5293808eba is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
   Conbench compare runs links:
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ec2-t3-xlarge-us-east-2] [ec2-t3-xlarge-us-east-2](https://conbench.ursa.dev/compare/runs/8387a0b38b0245e4b449765c30c1f658...0b24c7347e6447f29fadab03351c4e3d/)
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on test-mac-arm] [test-mac-arm](https://conbench.ursa.dev/compare/runs/ef1978059265488484635576ed3bdd86...4a36c8e4cee544d0a04cb2184383d506/)
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ursa-i9-9960x] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/75f4f2c6be17402e884e2f4f61311c44...0faa26f8eaa34a7595eb69c23c2198f1/)
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ursa-thinkcentre-m75q] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/7724970b5fa34b1fbbd1c42aa77a56b5...92ccd700f3be410ebc85bea7fffcc55d/)
   Buildkite builds:
   Supported benchmarks:
   ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
   test-mac-arm: Supported benchmark langs: C++, Python, R
   ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
   ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] alamb merged pull request #4188: Disallow duplicate interval types during parsing

Posted by GitBox <gi...@apache.org>.
alamb merged PR #4188:
URL: https://github.com/apache/arrow-datafusion/pull/4188


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org