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

Improve error messages for cast errors #23729

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

pratyakshsharma
Copy link
Contributor

@pratyakshsharma pratyakshsharma commented Sep 26, 2024

Description

if some query runs into cannot cast errors, the error message does not include any useful information around column names, problematic projection or the row number in the query from where the error is being thrown. This PR attempts to include column name as well in the error message so that users know which column value is causing issues.

Motivation and Context

While this PR attempts to add column names in the error message, there is a limitation. In cases where multiple columns in the table have the same data type, and multiple ones from them are getting cast to the same data type, then we print all these columns as the probable problematic columns. For example, table tbl has below columns - col1 integer, col2 real, col3 varchar, col4 real, col5 double. col2 has a NaN value in one of the rows. Please see the below queries and their possible errors -

1. select cast(col2 as decimal(10,0)), cast(col4 as decimal(10,0)) from tbl;
This results in below error - Cannot cast REAL 'NaN' to DECIMAL(10,0), error prone columns - [col2, col4] (since both col2 and col4 are being cast to decimal(10,0) and they both are real type)

2. select cast(col2 as decimal(10,0)), cast(col4 as decimal(11,0)) from tbl;
Cannot cast REAL 'NaN' to DECIMAL(10,0), error prone columns - [col2] (since the decimal types are different for col2 and col4).

3. select cast(col2 as decimal(10,0)), cast(col1 as decimal(10,0)) from tbl;
Cannot cast REAL 'NaN' to DECIMAL(10,0), error prone columns - [col2] (since the data types are different for col2 and col1).

Impact

Error messages get more user friendly in case of cannot cast errors

Test Plan

Manual testing

Contributor checklist

  • Please make sure your submission complies with our development, formatting, commit message, and attribution guidelines.
  • PR description addresses the issue accurately and concisely. If the change is non-trivial, a GitHub Issue is referenced.
  • Documented new properties (with its default value), SQL syntax, functions, or other functionality.
  • If release notes are required, they follow the release notes guidelines.
  • Adequate tests were added if applicable.
  • CI passed.

Release Notes

Please follow release notes guidelines and fill in the release notes below.

== NO RELEASE NOTE ==

@tdcmeehan
Copy link
Contributor

Can you add some examples of the before and after?

@pratyakshsharma
Copy link
Contributor Author

pratyakshsharma commented Sep 26, 2024

Previous stack trace -

com.facebook.presto.spi.PrestoException: Cannot cast REAL 'NaN' to DECIMAL(38, 0)
    at com.facebook.presto.type.DecimalCasts.realToLongDecimal(DecimalCasts.java:550)
    at com.facebook.presto.type.DecimalCasts.realToLongDecimal(DecimalCasts.java:543)
    at com.facebook.presto.$gen.PageProjectionWork_20240813_121319_3.evaluate(Unknown Source)
    at com.facebook.presto.$gen.PageProjectionWork_20240813_121319_3.process(Unknown Source)
    at com.facebook.presto.operator.project.DictionaryAwarePageProjection$DictionaryAwarePageProjectionWork.process(DictionaryAwarePageProjection.java:174)
    at com.facebook.presto.operator.project.PageProcessor$ProjectSelectedPositions.processBatch(PageProcessor.java:330)
    at com.facebook.presto.operator.project.PageProcessor$ProjectSelectedPositions.process(PageProcessor.java:201)
    at com.facebook.presto.operator.WorkProcessorUtils$ProcessWorkProcessor.process(WorkProcessorUtils.java:315)
    at com.facebook.presto.operator.WorkProcessorUtils$YieldingIterator.computeNext(WorkProcessorUtils.java:79)
    at com.facebook.presto.operator.WorkProcessorUtils$YieldingIterator.computeNext(WorkProcessorUtils.java:65)
    at com.google.common.collect.AbstractIterator.tryToComputeNext(AbstractIterator.java:141)
    at com.google.common.collect.AbstractIterator.hasNext(AbstractIterator.java:136)
    at com.facebook.presto.operator.project.MergingPageOutput.getOutput(MergingPageOutput.java:128)
    at com.facebook.presto.operator.ScanFilterAndProjectOperator.processPageSource(ScanFilterAndProjectOperator.java:316)
    at com.facebook.presto.operator.ScanFilterAndProjectOperator.getOutput(ScanFilterAndProjectOperator.java:260)
    at com.facebook.presto.operator.Driver.processInternal(Driver.java:441)
    at com.facebook.presto.operator.Driver.lambda$processFor$10(Driver.java:324)
    at com.facebook.presto.operator.Driver.tryWithLock(Driver.java:750)
    at com.facebook.presto.operator.Driver.processFor(Driver.java:317)
    at com.facebook.presto.execution.SqlTaskExecution$DriverSplitRunner.processFor(SqlTaskExecution.java:1079)
    at com.facebook.presto.execution.executor.PrioritizedSplitRunner.process(PrioritizedSplitRunner.java:165)
    at com.facebook.presto.execution.executor.TaskExecutor$TaskRunner.run(TaskExecutor.java:621)
    at com.facebook.presto.$gen.Presto_null__testversion____20240813_121040_1.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:750)

New error message:
Screenshot 2024-09-26 at 9 51 53 PM

Copy link
Contributor

@yingsu00 yingsu00 left a comment

Choose a reason for hiding this comment

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

I think the change on PageProcessor may not be the right way to do it. Also, Instead of just giving the columns that MIGHT cause the cast error, we should be able to get which column and type caused this error. But I can't give the suggestion how to do it now. @tdcmeehan Do you have any better idea?

@@ -68,7 +68,7 @@ private Slice castToIpAddress(Slice slice)
address = InetAddresses.forString(slice.toStringUtf8()).getAddress();
}
catch (IllegalArgumentException e) {
throw new PrestoException(INVALID_CAST_ARGUMENT, "Cannot cast value to IPADDRESS: " + slice.toStringUtf8());
Copy link
Contributor

Choose a reason for hiding this comment

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

A Slice may not necessarily represent a string. Just use value is fine

Copy link
Contributor

Choose a reason for hiding this comment

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

WHy remove the space?

@pratyakshsharma pratyakshsharma force-pushed the non-informative-error-messages branch from 6a41147 to 21e3dde Compare October 22, 2024 07:38
@pratyakshsharma pratyakshsharma requested a review from a team as a code owner October 22, 2024 16:15
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.

3 participants