Skip to content

Commit

Permalink
SNOW-1876614: Fix validity checks in arrow struct vectors (#2022)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-astachowski authored Jan 10, 2025
1 parent 5473bb2 commit dcac111
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ public ThreeFieldStructToTimestampTZConverter(

@Override
public boolean isNull(int index) {
return epochs.isNull(index);
return structVector.isNull(index)
|| epochs.isNull(index)
|| fractions.isNull(index)
|| timeZoneIndices.isNull(index);
}

@Override
Expand All @@ -54,7 +57,7 @@ public String toString(int index) throws SFException {
throw new SFException(ErrorCode.INTERNAL_ERROR, "missing timestamp TZ formatter");
}
try {
Timestamp ts = epochs.isNull(index) ? null : getTimestamp(index, TimeZone.getDefault(), true);
Timestamp ts = isNull(index) ? null : getTimestamp(index, TimeZone.getDefault(), true);
return ts == null
? null
: context.getTimestampTZFormatter().format(ts, timeZone, context.getScale(columnIndex));
Expand All @@ -65,7 +68,7 @@ public String toString(int index) throws SFException {

@Override
public byte[] toBytes(int index) throws SFException {
if (epochs.isNull(index)) {
if (isNull(index)) {
return null;
}
throw new SFException(
Expand All @@ -79,7 +82,7 @@ public Object toObject(int index) throws SFException {

@Override
public Timestamp toTimestamp(int index, TimeZone tz) throws SFException {
return epochs.isNull(index) ? null : getTimestamp(index, tz, false);
return isNull(index) ? null : getTimestamp(index, tz, false);
}

private Timestamp getTimestamp(int index, TimeZone tz, boolean fromToString) throws SFException {
Expand All @@ -98,7 +101,7 @@ private Timestamp getTimestamp(int index, TimeZone tz, boolean fromToString) thr

@Override
public Date toDate(int index, TimeZone tz, boolean dateFormat) throws SFException {
if (epochs.isNull(index)) {
if (isNull(index)) {
return null;
}
Timestamp ts = getTimestamp(index, TimeZone.getDefault(), false);
Expand All @@ -116,7 +119,7 @@ public Time toTime(int index) throws SFException {

@Override
public boolean toBoolean(int index) throws SFException {
if (epochs.isNull(index)) {
if (isNull(index)) {
return false;
}
Timestamp val = toTimestamp(index, TimeZone.getDefault());
Expand All @@ -127,7 +130,7 @@ public boolean toBoolean(int index) throws SFException {

@Override
public short toShort(int rowIndex) throws SFException {
if (epochs.isNull(rowIndex)) {
if (isNull(rowIndex)) {
return 0;
}
throw new SFException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public TwoFieldStructToTimestampLTZConverter(

@Override
public boolean isNull(int index) {
return epochs.isNull(index);
return structVector.isNull(index) || epochs.isNull(index) || fractions.isNull(index);
}

@Override
Expand All @@ -51,7 +51,7 @@ public String toString(int index) throws SFException {
}

try {
Timestamp ts = epochs.isNull(index) ? null : getTimestamp(index, TimeZone.getDefault(), true);
Timestamp ts = isNull(index) ? null : getTimestamp(index, TimeZone.getDefault(), true);

return ts == null
? null
Expand Down Expand Up @@ -82,7 +82,7 @@ private Timestamp getTimestamp(int index, TimeZone tz, boolean fromToString) thr

@Override
public byte[] toBytes(int index) throws SFException {
if (epochs.isNull(index)) {
if (isNull(index)) {
return null;
}
throw new SFException(
Expand Down Expand Up @@ -111,7 +111,7 @@ public Time toTime(int index) throws SFException {

@Override
public boolean toBoolean(int index) throws SFException {
if (epochs.isNull(index)) {
if (isNull(index)) {
return false;
}
Timestamp val = toTimestamp(index, TimeZone.getDefault());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public TwoFieldStructToTimestampNTZConverter(

@Override
public boolean isNull(int index) {
return epochs.isNull(index);
return structVector.isNull(index) || epochs.isNull(index) || fractions.isNull(index);
}

@Override
Expand All @@ -51,7 +51,7 @@ public String toString(int index) throws SFException {
throw new SFException(ErrorCode.INTERNAL_ERROR, "missing timestamp NTZ formatter");
}
try {
Timestamp ts = epochs.isNull(index) ? null : getTimestamp(index, TimeZone.getDefault(), true);
Timestamp ts = isNull(index) ? null : getTimestamp(index, TimeZone.getDefault(), true);

return ts == null
? null
Expand Down Expand Up @@ -92,7 +92,7 @@ private Timestamp getTimestamp(int index, TimeZone tz, boolean fromToString) thr

@Override
public byte[] toBytes(int index) throws SFException {
if (epochs.isNull(index)) {
if (isNull(index)) {
return null;
}
throw new SFException(
Expand All @@ -119,7 +119,7 @@ public Time toTime(int index) throws SFException {

@Override
public boolean toBoolean(int index) throws SFException {
if (epochs.isNull(index)) {
if (isNull(index)) {
return false;
}
Timestamp val = toTimestamp(index, TimeZone.getDefault());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public TwoFieldStructToTimestampTZConverter(

@Override
public boolean isNull(int index) {
return epochs.isNull(index);
return structVector.isNull(index) || epochs.isNull(index) || timeZoneIndices.isNull(index);
}

@Override
Expand All @@ -59,7 +59,7 @@ public Object toObject(int index) throws SFException {

@Override
public Timestamp toTimestamp(int index, TimeZone tz) throws SFException {
return epochs.isNull(index) ? null : getTimestamp(index, tz);
return isNull(index) ? null : getTimestamp(index, tz);
}

private Timestamp getTimestamp(int index, TimeZone tz) throws SFException {
Expand All @@ -76,7 +76,7 @@ private Timestamp getTimestamp(int index, TimeZone tz) throws SFException {

@Override
public Date toDate(int index, TimeZone tz, boolean dateFormat) throws SFException {
if (epochs.isNull(index)) {
if (isNull(index)) {
return null;
}
Timestamp ts = getTimestamp(index, TimeZone.getDefault());
Expand All @@ -94,7 +94,7 @@ public Time toTime(int index) throws SFException {

@Override
public boolean toBoolean(int index) throws SFException {
if (epochs.isNull(index)) {
if (isNull(index)) {
return false;
}
Timestamp val = toTimestamp(index, TimeZone.getDefault());
Expand All @@ -105,7 +105,7 @@ public boolean toBoolean(int index) throws SFException {

@Override
public byte[] toBytes(int index) throws SFException {
if (epochs.isNull(index)) {
if (isNull(index)) {
return null;
}
throw new SFException(
Expand All @@ -114,7 +114,7 @@ public byte[] toBytes(int index) throws SFException {

@Override
public short toShort(int rowIndex) throws SFException {
if (epochs.isNull(rowIndex)) {
if (isNull(rowIndex)) {
return 0;
}
throw new SFException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,11 @@ public void testTimestampTZ(
seconds.setSafe(j, testSecondsInt64[i]);
nanos.setSafe(j, testNanos[i]);
timeZoneIdx.setSafe(j, testTimeZoneIndices[i++]);
structVector.setIndexDefined(j);
}
j++;
}
structVector.setValueCount(j);

ArrowVectorConverter converter =
new ThreeFieldStructToTimestampTZConverter(structVector, 0, this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,11 @@ public void testTimestampLTZ(
} else {
epochs.setSafe(j, testSecondsInt64[i]);
fractions.setSafe(j, testNanoSecs[i++]);
structVector.setIndexDefined(j);
}
j++;
}
structVector.setValueCount(j);

ArrowVectorConverter converter =
new TwoFieldStructToTimestampLTZConverter(structVector, 0, this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,11 @@ public void testTimestampNTZ(
} else {
epochs.setSafe(j, testSecondsInt64[i]);
fractions.setSafe(j, testNanoSecs[i++]);
structVector.setIndexDefined(j);
}
j++;
}
structVector.setValueCount(j);

ArrowVectorConverter converter =
new TwoFieldStructToTimestampNTZConverter(structVector, 0, this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,11 @@ public void testTimestampTZ(String tz) throws SFException {
} else {
epoch.setSafe(j, testEpochesInt64[i]);
timeZoneIdx.setSafe(j, testTimeZoneIndices[i++]);
structVector.setIndexDefined(j);
}
j++;
}
structVector.setValueCount(j);

ArrowVectorConverter converter =
new TwoFieldStructToTimestampTZConverter(structVector, 0, this);
Expand Down

0 comments on commit dcac111

Please sign in to comment.