-
Couldn't load subscription status.
- Fork 929
SPARKC-516: Add column name to the error message in case of conversion error #1155
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
base: trunk
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -5,8 +5,11 @@ import java.util.UUID | |
|
|
||
| import com.datastax.spark.connector.ColumnRef | ||
| import com.datastax.spark.connector.cql.TableDef | ||
| import com.datastax.spark.connector.types.TypeConversionException | ||
| import org.apache.spark.sql.Row | ||
|
|
||
| import scala.util.{Failure, Success, Try} | ||
|
|
||
|
|
||
| /** A [[RowWriter]] that can write SparkSQL `Row` objects. */ | ||
| class SqlRowWriter(val table: TableDef, val selectedColumns: IndexedSeq[ColumnRef]) | ||
|
|
@@ -23,9 +26,16 @@ class SqlRowWriter(val table: TableDef, val selectedColumns: IndexedSeq[ColumnRe | |
| require(row.size == columnNames.size, s"Invalid row size: ${row.size} instead of ${columnNames.size}.") | ||
| for (i <- 0 until row.size) { | ||
| val colValue = row(i) | ||
| buffer(i) = converters(i).convert(colValue) | ||
| buffer(i) = Try(converters(i).convert(colValue)) match { | ||
| case Success(value) => value | ||
| case Failure(ex: IllegalArgumentException) => | ||
| val columnType = columnTypes(i).scalaTypeName | ||
| throw new TypeConversionException( | ||
| s"Cannot convert value $colValue of column ${columnNames(i)} to type $columnType", ex) | ||
|
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. The message will look like |
||
| case Failure(ex) => throw ex | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
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.
The most exceptions I've seen that were hard to track down were either
IllegalArgumentExceptionor its subclass.