3131import java .util .List ;
3232import java .util .Map ;
3333import java .util .Optional ;
34+ import javax .annotation .Nullable ;
3435import lombok .RequiredArgsConstructor ;
3536
3637/**
@@ -183,6 +184,7 @@ private ImportTargetResult importIntoSingleTable(
183184 .tableName (table )
184185 .status (ImportTargetResultStatus .VALIDATION_FAILED )
185186 .errors (Collections .singletonList (DataLoaderError .TABLE_METADATA_MISSING .buildMessage ()))
187+ .importedRecord (getRecordForLogging (mutableSourceRecord ))
186188 .build ();
187189 }
188190
@@ -209,6 +211,7 @@ private ImportTargetResult importIntoSingleTable(
209211 .tableName (table )
210212 .status (ImportTargetResultStatus .VALIDATION_FAILED )
211213 .errors (validationResult .getErrorMessages ())
214+ .importedRecord (getRecordForLogging (mutableSourceRecord ))
212215 .build ();
213216 }
214217
@@ -223,6 +226,7 @@ private ImportTargetResult importIntoSingleTable(
223226 .errors (
224227 Collections .singletonList (
225228 DataLoaderError .COULD_NOT_FIND_PARTITION_KEY .buildMessage ()))
229+ .importedRecord (getRecordForLogging (mutableSourceRecord ))
226230 .build ();
227231 }
228232 Optional <Key > optionalClusteringKey = Optional .empty ();
@@ -238,6 +242,7 @@ private ImportTargetResult importIntoSingleTable(
238242 .errors (
239243 Collections .singletonList (
240244 DataLoaderError .COULD_NOT_FIND_CLUSTERING_KEY .buildMessage ()))
245+ .importedRecord (getRecordForLogging (mutableSourceRecord ))
241246 .build ();
242247 }
243248 }
@@ -254,6 +259,7 @@ private ImportTargetResult importIntoSingleTable(
254259 .tableName (table )
255260 .status (ImportTargetResultStatus .RETRIEVAL_FAILED )
256261 .errors (Collections .singletonList (e .getMessage ()))
262+ .importedRecord (getRecordForLogging (mutableSourceRecord ))
257263 .build ();
258264 }
259265 ImportTaskAction importAction =
@@ -273,6 +279,7 @@ && shouldRevalidateMissingColumns(importOptions, checkForMissingColumns)) {
273279 .errors (
274280 Collections .singletonList (
275281 DataLoaderError .UPSERT_INSERT_MISSING_COLUMNS .buildMessage ()))
282+ .importedRecord (getRecordForLogging (mutableSourceRecord ))
276283 .build ();
277284 }
278285 }
@@ -281,7 +288,7 @@ && shouldRevalidateMissingColumns(importOptions, checkForMissingColumns)) {
281288 return ImportTargetResult .builder ()
282289 .namespace (namespace )
283290 .tableName (table )
284- .importedRecord (mutableSourceRecord )
291+ .importedRecord (getRecordForLogging ( mutableSourceRecord ) )
285292 .importAction (importAction )
286293 .status (ImportTargetResultStatus .DATA_ALREADY_EXISTS )
287294 .errors (Collections .singletonList (DataLoaderError .DATA_ALREADY_EXISTS .buildMessage ()))
@@ -292,7 +299,7 @@ && shouldRevalidateMissingColumns(importOptions, checkForMissingColumns)) {
292299 return ImportTargetResult .builder ()
293300 .namespace (namespace )
294301 .tableName (table )
295- .importedRecord (mutableSourceRecord )
302+ .importedRecord (getRecordForLogging ( mutableSourceRecord ) )
296303 .importAction (importAction )
297304 .status (ImportTargetResultStatus .DATA_NOT_FOUND )
298305 .errors (Collections .singletonList (DataLoaderError .DATA_NOT_FOUND .buildMessage ()))
@@ -314,7 +321,7 @@ && shouldRevalidateMissingColumns(importOptions, checkForMissingColumns)) {
314321 return ImportTargetResult .builder ()
315322 .namespace (namespace )
316323 .tableName (table )
317- .importedRecord (mutableSourceRecord )
324+ .importedRecord (getRecordForLogging ( mutableSourceRecord ) )
318325 .status (ImportTargetResultStatus .VALIDATION_FAILED )
319326 .errors (Collections .singletonList (e .getMessage ()))
320327 .build ();
@@ -333,13 +340,14 @@ && shouldRevalidateMissingColumns(importOptions, checkForMissingColumns)) {
333340 .namespace (namespace )
334341 .tableName (table )
335342 .importAction (importAction )
336- .importedRecord (mutableSourceRecord )
343+ .importedRecord (getRecordForLogging ( mutableSourceRecord ) )
337344 .status (ImportTargetResultStatus .SAVED )
338345 .build ();
339346
340347 } catch (ScalarDbDaoException e ) {
341348 return ImportTargetResult .builder ()
342349 .namespace (namespace )
350+ .importedRecord (getRecordForLogging (mutableSourceRecord ))
343351 .tableName (table )
344352 .importAction (importAction )
345353 .status (ImportTargetResultStatus .SAVE_FAILED )
@@ -423,6 +431,21 @@ private boolean shouldFailForExistingData(
423431 && importOptions .getImportMode () == ImportMode .INSERT ;
424432 }
425433
434+ /**
435+ * Returns the given source record only if raw record logging is enabled in the import options.
436+ *
437+ * <p>This helper method centralizes the logic for conditionally including the raw source record
438+ * in {@code ImportTargetResult}. If {@code logRawRecord} is disabled, {@code null} is returned to
439+ * avoid storing or displaying the raw record.
440+ *
441+ * @param record the source record to include conditionally
442+ * @return the provided record if raw record logging is enabled; otherwise {@code null}
443+ */
444+ @ Nullable
445+ private ObjectNode getRecordForLogging (ObjectNode record ) {
446+ return params .getImportOptions ().isLogRawRecord () ? record : null ;
447+ }
448+
426449 /**
427450 * Determines whether the operation should fail if the expected data is missing.
428451 *
0 commit comments