Skip to content
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

SNOW-918949: Add row index information to all exceptions #590

Merged
merged 45 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
eeb56c0
fix issue
sfc-gh-tzhang Dec 7, 2022
911c63f
encryption
sfc-gh-tzhang Feb 17, 2023
b0a33d9
fix format
sfc-gh-tzhang Feb 17, 2023
ff14184
add tests
sfc-gh-tzhang Feb 22, 2023
55fdb59
update
sfc-gh-tzhang Feb 22, 2023
b202a17
Merge branch 'master' into tzhang-si-fixes
sfc-gh-tzhang Mar 10, 2023
47dabfc
Merge branch 'master' into tzhang-si-encryption
sfc-gh-tzhang Mar 28, 2023
b9e8d33
Merge branch 'tzhang-si-encryption' into tzhang-si-fixes
sfc-gh-tzhang Mar 28, 2023
c1e6dae
Merge branch 'master' into tzhang-si-fixes
sfc-gh-tzhang Apr 6, 2023
94d2d05
perf fixes
sfc-gh-tzhang Apr 6, 2023
e8da46b
update example
sfc-gh-tzhang Apr 6, 2023
fdedb23
remove utf8
sfc-gh-tzhang Apr 7, 2023
1190275
Revert "remove utf8"
sfc-gh-tzhang Apr 7, 2023
96db639
fix
sfc-gh-tzhang Apr 7, 2023
bc0db14
Merge branch 'master' into tzhang-si-fixes
sfc-gh-tzhang Apr 7, 2023
e4ef922
fix tests
sfc-gh-tzhang Apr 8, 2023
d267165
Merge branch 'tzhang-si-fixes' of github.com:snowflakedb/snowflake-in…
sfc-gh-tzhang Apr 8, 2023
2160a36
fix tests
sfc-gh-tzhang Apr 8, 2023
4146bfb
use dynamic scaling thread pool
sfc-gh-tzhang Apr 11, 2023
528af31
merge master
sfc-gh-tzhang Apr 11, 2023
0344b70
file format
sfc-gh-tzhang Apr 11, 2023
6abd0d2
Merge branch 'master' into tzhang-si-fixes
sfc-gh-tzhang May 15, 2023
65e16f4
fix
sfc-gh-tzhang May 17, 2023
025958c
update max chunk size
sfc-gh-tzhang May 17, 2023
e43c354
fix schema issue
sfc-gh-tzhang May 18, 2023
4847388
Merge branch 'master' into tzhang-si-fixes
sfc-gh-tzhang May 18, 2023
e016947
fix
sfc-gh-tzhang May 18, 2023
12f9eb2
address comment
sfc-gh-tzhang May 18, 2023
699bb41
Merge branch 'master' into tzhang-si-fixes
sfc-gh-tzhang Jun 2, 2023
ab0620f
save progress
sfc-gh-tzhang Jun 4, 2023
eaa729a
add tests
sfc-gh-tzhang Jun 5, 2023
d5abc25
Merge branch 'master' into tzhang-si-fixes
sfc-gh-tzhang Jun 5, 2023
f17ba1b
fix tests
sfc-gh-tzhang Jun 6, 2023
114a4d3
Merge branch 'master' into tzhang-si-fixes
sfc-gh-tzhang Jun 7, 2023
e925d83
address comments
sfc-gh-tzhang Jun 7, 2023
efec4e9
fix naming
sfc-gh-tzhang Jun 8, 2023
d334b76
merge master
sfc-gh-tzhang Jul 12, 2023
65b75b1
fix
sfc-gh-tzhang Jul 12, 2023
e96688c
fix
sfc-gh-tzhang Jul 12, 2023
4401ed9
Merge branch 'master' into tzhang-si-fixes
sfc-gh-tzhang Sep 20, 2023
efa8e4e
add row index
sfc-gh-tzhang Sep 20, 2023
aea5519
Merge branch 'master' into tzhang-si-fixes
sfc-gh-tzhang Sep 22, 2023
22fe148
update message
sfc-gh-tzhang Sep 27, 2023
f0dd91d
remove star import
sfc-gh-tzhang Sep 27, 2023
b7f23d7
Merge branch 'master' into tzhang-si-fixes
sfc-gh-tzhang Sep 27, 2023
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 @@ -236,10 +236,11 @@ public float getSize() {
*
* @param row the input row
* @param error the insert error that we return to the customer
* @param rowIndex the index of the current row in the input batch
* @return the set of input column names
*/
Set<String> verifyInputColumns(
Map<String, Object> row, InsertValidationResponse.InsertError error) {
Map<String, Object> row, InsertValidationResponse.InsertError error, int rowIndex) {
// Map of unquoted column name -> original column name
Map<String, String> inputColNamesMap =
row.keySet().stream()
Expand All @@ -260,7 +261,8 @@ Set<String> verifyInputColumns(
throw new SFException(
ErrorCode.INVALID_FORMAT_ROW,
"Extra columns: " + extraCols,
"Columns not present in the table shouldn't be specified.");
String.format(
"Columns not present in the table shouldn't be specified, rowIndex:%d", rowIndex));
}

// Check for missing columns in the row
Expand All @@ -278,7 +280,8 @@ Set<String> verifyInputColumns(
throw new SFException(
ErrorCode.INVALID_FORMAT_ROW,
"Missing columns: " + missingCols,
"Values for all non-nullable columns must be specified.");
String.format(
"Values for all non-nullable columns must be specified, rowIndex:%d", rowIndex));
}

return inputColNamesMap.keySet();
Expand All @@ -304,12 +307,12 @@ public InsertValidationResponse insertRows(
this.channelState.updateInsertStats(System.currentTimeMillis(), this.bufferedRowCount);
if (onErrorOption == OpenChannelRequest.OnErrorOption.CONTINUE) {
// Used to map incoming row(nth row) to InsertError(for nth row) in response
long rowIndex = 0;
int rowIndex = 0;
for (Map<String, Object> row : rows) {
InsertValidationResponse.InsertError error =
new InsertValidationResponse.InsertError(row, rowIndex);
try {
Set<String> inputColumnNames = verifyInputColumns(row, error);
Set<String> inputColumnNames = verifyInputColumns(row, error, rowIndex);
rowsSizeInBytes +=
addRow(row, this.bufferedRowCount, this.statsMap, inputColumnNames, rowIndex);
this.bufferedRowCount++;
Expand All @@ -333,7 +336,7 @@ public InsertValidationResponse insertRows(
float tempRowsSizeInBytes = 0F;
int tempRowCount = 0;
for (Map<String, Object> row : rows) {
Set<String> inputColumnNames = verifyInputColumns(row, null);
Set<String> inputColumnNames = verifyInputColumns(row, null, tempRowCount);
tempRowsSizeInBytes +=
addTempRow(row, tempRowCount, this.tempStatsMap, inputColumnNames, tempRowCount);
checkBatchSizeEnforcedMaximum(tempRowsSizeInBytes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,10 @@ static TimestampWrapper validateAndParseTimestamp(
if (offsetDateTime.getYear() < 1 || offsetDateTime.getYear() > 9999) {
throw new SFException(
ErrorCode.INVALID_VALUE_ROW,
"Timestamp out of representable inclusive range of years between 1 and 9999");
String.format(
"Timestamp out of representable inclusive range of years between 1 and 9999,"
+ " rowIndex:%d",
insertRowIndex));
}
return new TimestampWrapper(offsetDateTime, scale);
}
Expand Down Expand Up @@ -588,7 +591,10 @@ static int validateAndParseDate(String columnName, Object input, long insertRowI
if (offsetDateTime.getYear() < -9999 || offsetDateTime.getYear() > 9999) {
throw new SFException(
ErrorCode.INVALID_VALUE_ROW,
"Date out of representable inclusive range of years between -9999 and 9999");
String.format(
"Date out of representable inclusive range of years between -9999 and 9999,"
+ " rowIndex:%d",
insertRowIndex));
}

return Math.toIntExact(offsetDateTime.toLocalDate().toEpochDay());
Expand Down Expand Up @@ -814,7 +820,7 @@ static void checkValueInRange(
throw new SFException(
ErrorCode.INVALID_FORMAT_ROW,
String.format(
"Number out of representable exclusive range of (-1e%s..1e%s), Row Index:%s",
"Number out of representable exclusive range of (-1e%s..1e%s), rowIndex:%d",
precision - scale, precision - scale, insertRowIndex));
}
}
Expand Down Expand Up @@ -858,8 +864,7 @@ private static SFException typeNotAllowedException(
return new SFException(
ErrorCode.INVALID_FORMAT_ROW,
String.format(
"Object of type %s cannot be ingested into Snowflake column %s of type %s, Row"
+ " Index:%s",
"Object of type %s cannot be ingested into Snowflake column %s of type %s, rowIndex:%d",
javaType.getName(), columnName, snowflakeType, insertRowIndex),
String.format(
String.format("Allowed Java types: %s", String.join(", ", allowedJavaTypes))));
Expand All @@ -882,7 +887,7 @@ private static SFException valueFormatNotAllowedException(
return new SFException(
ErrorCode.INVALID_VALUE_ROW,
String.format(
"Value cannot be ingested into Snowflake column %s of type %s, Row Index: %s, reason:"
"Value cannot be ingested into Snowflake column %s of type %s, rowIndex:%d, reason:"
+ " %s",
columnName, snowflakeType, rowIndex, reason));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ private float addRow(
throw new SFException(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, is it worth having a list of longs that we store in a SFException that can be accessed via something like getRowIndexes? This will reduce the need to parse an error message which is error prone.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already doing that with CONTINUE, this is for ABORT where we thrown an exception directly

ErrorCode.MAX_ROW_SIZE_EXCEEDED,
String.format(
"rowSizeInBytes=%.3f maxAllowedRowSizeInBytes=%d",
size, clientBufferParameters.getMaxAllowedRowSizeInBytes()));
"rowSizeInBytes:%.3f, maxAllowedRowSizeInBytes:%d, rowIndex:%d",
size, clientBufferParameters.getMaxAllowedRowSizeInBytes(), insertRowsCurrIndex));
}

out.accept(Arrays.asList(indexedRow));
Expand Down
Loading