This is an automated email from the ASF dual-hosted git repository.
adarshsanjeev pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/druid.git
The following commit(s) were added to refs/heads/master by this push:
new 767a1633d0a Store cause for invalid field exceptions (#18513)
767a1633d0a is described below
commit 767a1633d0a70c99e9e134484eaf95c05ee1b18a
Author: Adarsh Sanjeev <[email protected]>
AuthorDate: Thu Sep 11 14:14:21 2025 +0530
Store cause for invalid field exceptions (#18513)
An InvalidFieldException only stores the error message string. The
exception should instead also store the exception as the cause to make it
easier to debug.
---
.../druid/msq/querykit/scan/ScanQueryFrameProcessor.java | 1 +
.../apache/druid/frame/write/InvalidFieldException.java | 15 ++++++++++++++-
.../org/apache/druid/frame/write/RowBasedFrameWriter.java | 1 +
.../apache/druid/frame/write/RowBasedFrameWriterTest.java | 5 ++++-
4 files changed, 20 insertions(+), 2 deletions(-)
diff --git
a/multi-stage-query/src/main/java/org/apache/druid/msq/querykit/scan/ScanQueryFrameProcessor.java
b/multi-stage-query/src/main/java/org/apache/druid/msq/querykit/scan/ScanQueryFrameProcessor.java
index a17c38cbf6b..5665bc1432f 100644
---
a/multi-stage-query/src/main/java/org/apache/druid/msq/querykit/scan/ScanQueryFrameProcessor.java
+++
b/multi-stage-query/src/main/java/org/apache/druid/msq/querykit/scan/ScanQueryFrameProcessor.java
@@ -433,6 +433,7 @@ public class ScanQueryFrameProcessor extends
BaseLeafFrameProcessor
throw
builder.source(ParseExceptionUtils.generateReadableInputSourceNameFromMappedSegment(this.segment))
// frame segment
.rowNumber(this.cursorOffset.getOffset() + 1)
+ .cause(ffwe.getCause())
.build();
}
catch (Exception e) {
diff --git
a/processing/src/main/java/org/apache/druid/frame/write/InvalidFieldException.java
b/processing/src/main/java/org/apache/druid/frame/write/InvalidFieldException.java
index a39b70517de..b4350539d5a 100644
---
a/processing/src/main/java/org/apache/druid/frame/write/InvalidFieldException.java
+++
b/processing/src/main/java/org/apache/druid/frame/write/InvalidFieldException.java
@@ -122,6 +122,8 @@ public class InvalidFieldException extends RuntimeException
private String source;
@Nullable
private String errorMsg;
+ @Nullable
+ private Throwable cause;
public Builder()
{
@@ -133,11 +135,16 @@ public class InvalidFieldException extends
RuntimeException
rowNumber = invalidFieldException.rowNumber;
column = invalidFieldException.column;
errorMsg = invalidFieldException.errorMsg;
+ cause = invalidFieldException.getCause();
}
public InvalidFieldException build()
{
- return new InvalidFieldException(source, column, rowNumber, errorMsg);
+ InvalidFieldException invalidFieldException = new
InvalidFieldException(source, column, rowNumber, errorMsg);
+ if (cause != null) {
+ invalidFieldException.initCause(cause);
+ }
+ return invalidFieldException;
}
public Builder column(String val)
@@ -163,5 +170,11 @@ public class InvalidFieldException extends RuntimeException
errorMsg = val;
return this;
}
+
+ public Builder cause(Throwable val)
+ {
+ cause = val;
+ return this;
+ }
}
}
diff --git
a/processing/src/main/java/org/apache/druid/frame/write/RowBasedFrameWriter.java
b/processing/src/main/java/org/apache/druid/frame/write/RowBasedFrameWriter.java
index 6261ee374a1..aeb9beadba0 100644
---
a/processing/src/main/java/org/apache/druid/frame/write/RowBasedFrameWriter.java
+++
b/processing/src/main/java/org/apache/druid/frame/write/RowBasedFrameWriter.java
@@ -310,6 +310,7 @@ public class RowBasedFrameWriter implements FrameWriter
catch (Exception e) {
throw
InvalidFieldException.builder().column(signature.getColumnName(i))
.errorMsg(e.getMessage())
+ .cause(e)
.build();
}
diff --git
a/processing/src/test/java/org/apache/druid/frame/write/RowBasedFrameWriterTest.java
b/processing/src/test/java/org/apache/druid/frame/write/RowBasedFrameWriterTest.java
index 370fa4ae849..481078be8f7 100644
---
a/processing/src/test/java/org/apache/druid/frame/write/RowBasedFrameWriterTest.java
+++
b/processing/src/test/java/org/apache/druid/frame/write/RowBasedFrameWriterTest.java
@@ -98,12 +98,14 @@ public class RowBasedFrameWriterTest extends
InitializedNullHandlingTest
final RowSignature signature = RowSignature.builder().add(colName,
ColumnType.LONG).build();
+ RuntimeException realException = new RuntimeException(errorMsg);
+
LongFieldWriter fieldWriter = EasyMock.mock(LongFieldWriter.class);
EasyMock.expect(fieldWriter.writeTo(
EasyMock.anyObject(),
EasyMock.anyLong(),
EasyMock.anyLong()
- )).andThrow(new RuntimeException(errorMsg));
+ )).andThrow(realException);
EasyMock.replay(fieldWriter);
@@ -128,5 +130,6 @@ public class RowBasedFrameWriterTest extends
InitializedNullHandlingTest
rowBasedFrameWriter::addSelection
);
Assert.assertEquals(expectedException, actualException);
+ Assert.assertEquals(realException, actualException.getCause());
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]