From 6e86b10939cc3847f73dae7c566e61df79a3d912 Mon Sep 17 00:00:00 2001 From: Ghislain Fourny Date: Thu, 18 Apr 2024 10:25:06 +0200 Subject: [PATCH] Throw cast error even when in SQL --- .../org/rumbledb/api/SequenceOfItems.java | 16 ++++++++ src/main/java/org/rumbledb/cli/Main.java | 41 +++++++++++-------- 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/rumbledb/api/SequenceOfItems.java b/src/main/java/org/rumbledb/api/SequenceOfItems.java index 4f04cbca2..a48de49e8 100644 --- a/src/main/java/org/rumbledb/api/SequenceOfItems.java +++ b/src/main/java/org/rumbledb/api/SequenceOfItems.java @@ -89,6 +89,14 @@ public boolean hasNext() { RumbleException ex = new CastException(e.getMessage(), ExceptionMetadata.EMPTY_METADATA); ex.initCause(e); throw ex; + } catch (SparkRuntimeException e) { + if (e.getMessage().contains("CAST_INVALID_INPUT")) { + RumbleException ex = new CastException(e.getMessage(), ExceptionMetadata.EMPTY_METADATA); + ex.initCause(e); + throw ex; + } else { + throw e; + } } catch (UnsupportedOperationException e) { RumbleException ex = new CastException(e.getMessage(), ExceptionMetadata.EMPTY_METADATA); ex.initCause(e); @@ -140,6 +148,14 @@ public JavaRDD getAsRDD() { RumbleException ex = new UnexpectedTypeException(e.getMessage(), ExceptionMetadata.EMPTY_METADATA); ex.initCause(e); throw ex; + } catch (SparkRuntimeException e) { + if (e.getMessage().contains("CAST_INVALID_INPUT")) { + RumbleException ex = new CastException(e.getMessage(), ExceptionMetadata.EMPTY_METADATA); + ex.initCause(e); + throw ex; + } else { + throw e; + } } catch (UnsupportedOperationException e) { RumbleException ex = new UnexpectedTypeException(e.getMessage(), ExceptionMetadata.EMPTY_METADATA); ex.initCause(e); diff --git a/src/main/java/org/rumbledb/cli/Main.java b/src/main/java/org/rumbledb/cli/Main.java index 29562892b..2c111a118 100644 --- a/src/main/java/org/rumbledb/cli/Main.java +++ b/src/main/java/org/rumbledb/cli/Main.java @@ -24,7 +24,9 @@ import org.apache.commons.io.IOUtils; import org.apache.spark.SparkException; +import org.apache.spark.SparkRuntimeException; import org.rumbledb.config.RumbleRuntimeConfiguration; +import org.rumbledb.exceptions.CastException; import org.rumbledb.exceptions.ExceptionMetadata; import org.rumbledb.exceptions.OurBadException; import org.rumbledb.exceptions.RumbleException; @@ -149,23 +151,22 @@ private static void handleException(Throwable ex, boolean showErrorInfo) { ex.printStackTrace(); } System.exit(-42); - } else { - System.err.println( - "We are very embarrassed, because an error has occured that we did not anticipate 🙈: " - + ex.getMessage() - ); - System.err.println( - "We would like to investigate this and make sure to fix it. We would be very grateful if you could contact us or file an issue on GitHub with your query." - ); - System.err.println("Link: https://github.com/RumbleDB/rumble/issues"); - System.err.println( - "For more debug info (e.g., so you can communicate it to us), please try again using --show-error-info yes in your command line." - ); - if (showErrorInfo) { - ex.printStackTrace(); - } - System.exit(-42); } + System.err.println( + "We are very embarrassed, because an error has occured that we did not anticipate 🙈: " + + ex.getMessage() + ); + System.err.println( + "We would like to investigate this and make sure to fix it. We would be very grateful if you could contact us or file an issue on GitHub with your query." + ); + System.err.println("Link: https://github.com/RumbleDB/rumble/issues"); + System.err.println( + "For more debug info (e.g., so you can communicate it to us), please try again using --show-error-info yes in your command line." + ); + if (showErrorInfo) { + ex.printStackTrace(); + } + System.exit(-42); } } @@ -187,6 +188,14 @@ public static Throwable unboxException(Throwable ex) { ExceptionMetadata.EMPTY_METADATA ); } + if (ex instanceof SparkRuntimeException) { + if (ex.getMessage().contains("CAST_INVALID_INPUT")) { + RumbleException nex = new CastException(ex.getMessage(), ExceptionMetadata.EMPTY_METADATA); + ex.initCause(ex); + return nex; + } + // general message. + } return ex; } return new OurBadException("A null exception was returned.");