Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,17 @@
import org.apache.gluten.runtime.Runtime;
import org.apache.gluten.runtime.RuntimeAware;

import org.apache.spark.QueryContext;
import org.apache.spark.SparkRuntimeException;
import org.apache.spark.sql.execution.datasources.SchemaColumnConvertNotSupportedException;
import org.apache.spark.sql.vectorized.ColumnarBatch;
import org.apache.spark.util.SparkVersionUtil;

import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import scala.collection.immutable.Map;

public class ColumnarBatchOutIterator extends ClosableIterator<ColumnarBatch>
implements RuntimeAware {
Expand Down Expand Up @@ -132,6 +139,10 @@ public void requestBarrier() {
nativeRequestBarrier(iterHandle);
}

// Velox's message when a char or varchar value is longer than its declared length.
private static final Pattern CHAR_VARCHAR_LENGTH_EXCEEDED =
Pattern.compile("Exceeds allowed length limitation: (\\d+)");

/**
* Translates a Velox type conversion error into a SchemaColumnConvertNotSupportedException.
* Returns null if the message does not indicate a type conversion error.
Expand All @@ -143,6 +154,26 @@ private static RuntimeException translateToSchemaException(String msg) {
return null;
}

/**
* Translates a Velox char/varchar length check failure into the exception Spark throws for a
* value longer than its declared length. Returns null if the message does not indicate one.
*/
private static RuntimeException translateToCharVarcharLengthException(String msg, Exception e) {
Matcher matcher = CHAR_VARCHAR_LENGTH_EXCEEDED.matcher(msg);
if (!matcher.find()) {
return null;
}
String limit = matcher.group(1);
if (!SparkVersionUtil.gteSpark35()) {
// Spark 3.4 has no EXCEED_LIMIT_LENGTH error class and throws this plain RuntimeException.
return new RuntimeException("Exceeds char/varchar type length limitation: " + limit, e);
}
// Builds the exception QueryExecutionErrors.exceedMaxLimit builds, with the Velox error as its
// cause. SparkRuntimeException's cause can only be set through its constructor.
return new SparkRuntimeException(
"EXCEED_LIMIT_LENGTH", new Map.Map1<>("limit", limit), e, new QueryContext[0], "");
}

@Override
protected RuntimeException translateException(Exception e) {
String msg = findFirstNonNullMessage(e);
Expand All @@ -152,6 +183,10 @@ protected RuntimeException translateException(Exception e) {
schemaEx.initCause(e);
return schemaEx;
}
RuntimeException lengthEx = translateToCharVarcharLengthException(msg, e);
if (lengthEx != null) {
return lengthEx;
}
}
// A GlutenException raised by native/nested code is already translated; return it
// as-is rather than nesting it in another GlutenException. Keep this after every more
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -649,45 +649,11 @@ class VeloxTestSettings extends BackendTestSettings {
// Rewrite for different cache size.
.exclude("SPARK-36120: Support cache/uncache table with TimestampNTZ type")
enableSuite[GlutenFileSourceCharVarcharTestSuite]
.exclude("length check for input string values: nested in array")
.exclude("length check for input string values: nested in array")
.exclude("length check for input string values: nested in map key")
.exclude("length check for input string values: nested in map value")
.exclude("length check for input string values: nested in both map key and value")
.exclude("length check for input string values: nested in array of struct")
.exclude("length check for input string values: nested in array of array")
// Following tests are excluded as these are overridden in Gluten test suite..
// The overridden tests assert against Velox-specific error messages for char/varchar
// length validation, which differ from the original vanilla Spark tests.
.exclude("length check for input string values: top-level columns")
// Spark expects the length error of these partitioned inserts wrapped in TASK_WRITE_FAILED,
// but Gluten throws it unwrapped. Rewritten in GlutenCharVarcharTestSuite.
.exclude("length check for input string values: partitioned columns")
.exclude("length check for input string values: nested in struct of array")
.exclude("length check for input string values: with implicit cast")
.exclude("char/varchar type values length check: partitioned columns of other types")

enableSuite[GlutenDSV2CharVarcharTestSuite]
// Following tests are excluded as these are overridden in Gluten test suite..
// The overridden tests assert against Velox-specific error messages for char/varchar
// length validation, which differ from the original vanilla Spark tests.
.exclude("SPARK-42611: check char/varchar length in reordered structs within arrays")
.exclude("char/varchar type values length check: partitioned columns of other types")
.exclude("length check for input string values: top-level columns")
.exclude("length check for input string values: nested in array")
.exclude("length check for input string values: nested in struct of array")
.exclude("length check for input string values: nested in array of struct")
.exclude("length check for input string values: nested in array of array")
.exclude("length check for input string values: with implicit cast")
// Overridden.
.exclude("length check for input string values: nested in map key")
// Overridden.
.exclude("length check for input string values: nested in map value")
// Overridden.
.exclude("length check for input string values: nested in both map key and value")
// Overridden.
.exclude("SPARK-42611: check char/varchar length in reordered structs within map keys")
// Overridden.
.exclude("SPARK-42611: check char/varchar length in reordered structs within map values")

enableSuite[GlutenColumnExpressionSuite]
// Velox raise_error('errMsg') throws a velox_user_error exception with the message 'errMsg'.
// The final caught Spark exception's getCause().getMessage() contains 'errMsg' but does not
Expand Down
Loading