Skip to content

Commit

Permalink
Fix issue with using Null as DateType
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-ext-simba-jf committed Oct 26, 2023
1 parent 4453b41 commit 10bac5d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.sql.Date;
import java.util.TimeZone;

import net.snowflake.client.core.DataConversionContext;
import net.snowflake.client.core.SFException;
import net.snowflake.client.jdbc.ErrorCode;
Expand Down Expand Up @@ -143,4 +146,16 @@ public boolean toBoolean(int index) throws SFException {
SnowflakeUtil.BOOLEAN_STR, str);
}
}

@Override
public Date toDate(int index, TimeZone jvmTz, boolean useDateFormat) throws SFException {
if (isNull(index))
{
return null;
} else {
throw new SFException(
ErrorCode.INVALID_VALUE_CONVERT, logicalTypeStr,
SnowflakeUtil.DATE_STR, "");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,23 @@ public void testGetBoolean() throws SFException {

vector.close();
}

@Test
public void testGetDate() throws SFException {
Map<String, String> customFieldMeta = new HashMap<>();
customFieldMeta.put("logicalType", "FIXED");

FieldType fieldType =
new FieldType(true, Types.MinorType.VARCHAR.getType(), null, customFieldMeta);

VarCharVector vector = new VarCharVector("col_one", fieldType, allocator);
vector.setNull(0);
vector.setSafe(1, "abc".getBytes(StandardCharsets.UTF_8));

ArrowVectorConverter converter = new VarCharConverter(vector, 0, this);
assertThat(null, is(converter.toDate(0, null, false)));
TestUtil.assertSFException(invalidConversionErrorCode, () -> converter.toDate(1, null, false));

vector.close();
}
}

0 comments on commit 10bac5d

Please sign in to comment.