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-1700248 Revert turning native arrow boolean primitives lowercase #1906

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion src/main/java/net/snowflake/client/core/ResultUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public static String getSFTimeAsString(
* @return boolean in string
*/
public static String getBooleanAsString(boolean bool) {
return bool ? "true" : "false";
return bool ? "TRUE" : "FALSE";
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public Object toObject(int index) {

@Override
public String toString(int index) {
return isNull(index) ? null : toBoolean(index) ? "true" : "false";
return isNull(index) ? null : toBoolean(index) ? "TRUE" : "FALSE";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
import net.snowflake.client.core.SnowflakeJdbcInternalApi;
import net.snowflake.client.jdbc.SnowflakeType;

/**
* StringBuilder like class to aggregate the string representation of snowflake Native ARROW
* structured types as JSON one-liners. Provides some additional snowflake-specific logic in order
* to determine whether the value should be quoted or case should be changed.
*/
@SnowflakeJdbcInternalApi
public abstract class ArrowStringRepresentationBuilderBase {
private final StringJoiner joiner;
Expand Down Expand Up @@ -39,6 +44,13 @@ private boolean shouldQuoteValue(SnowflakeType type) {
}

protected String quoteIfNeeded(String string, SnowflakeType type) {
// Turn Boolean string representations lowercase to make the output JSON-compatible
// this should be changed on the converter level, but it would be a breaking change thus
// for now only structured types will be valid JSONs while in NATIVE ARROW mode
if (type == SnowflakeType.BOOLEAN) {
string = string.toLowerCase();
}

if (shouldQuoteValue(type)) {
return '"' + string + '"';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void testConvertToString() throws SFException {
} else {
assertThat(boolVal, is(expectedValues.get(i)));
assertThat(objectVal, is(expectedValues.get(i)));
assertThat(stringVal, is(expectedValues.get(i).toString()));
assertThat(stringVal, is(expectedValues.get(i).toString().toUpperCase()));
if (boolVal) {
assertThat((byte) 0x1, is(converter.toBytes(i)[0]));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ public void testConvertingString() throws SFException {

@Test
public void testConvertingBoolean() throws SFException {
assertEquals("true", stringConverter.getString(true, Types.BOOLEAN, Types.BOOLEAN, 0));
assertEquals("true", stringConverter.getString("true", Types.BOOLEAN, Types.BOOLEAN, 0));
assertEquals("false", stringConverter.getString(false, Types.BOOLEAN, Types.BOOLEAN, 0));
assertEquals("false", stringConverter.getString("false", Types.BOOLEAN, Types.BOOLEAN, 0));
assertEquals("TRUE", stringConverter.getString(true, Types.BOOLEAN, Types.BOOLEAN, 0));
assertEquals("TRUE", stringConverter.getString("true", Types.BOOLEAN, Types.BOOLEAN, 0));
assertEquals("FALSE", stringConverter.getString(false, Types.BOOLEAN, Types.BOOLEAN, 0));
assertEquals("FALSE", stringConverter.getString("false", Types.BOOLEAN, Types.BOOLEAN, 0));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1501,12 +1501,12 @@ public void testBoolean() throws SQLException {
ResultSet rs = statement.executeQuery("select * from " + table)) {
assertTrue(rs.next());
assertTrue(rs.getBoolean(1));
assertEquals("true", rs.getString(1));
assertEquals("TRUE", rs.getString(1));
assertTrue(rs.next());
assertFalse(rs.getBoolean(1));
assertTrue(rs.next());
assertFalse(rs.getBoolean(1));
assertEquals("false", rs.getString(1));
assertEquals("FALSE", rs.getString(1));
assertFalse(rs.next());
statement.execute("drop table if exists " + table);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1176,7 +1176,7 @@ public void testGetObjectWithType() throws SQLException {
assertResultValueAndType(statement, Double.valueOf("1.1"), "f", Double.class);
assertResultValueAndType(statement, Double.valueOf("2.2"), "d", Double.class);
assertResultValueAndType(statement, BigDecimal.valueOf(3.3), "bd", BigDecimal.class);
assertResultValueAndType(statement, "false", "bool", String.class);
assertResultValueAndType(statement, "FALSE", "bool", String.class);
assertResultValueAndType(statement, Boolean.FALSE, "bool", Boolean.class);
assertResultValueAndType(statement, 0L, "bool", Long.class);
assertResultValueAsString(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ public static Collection<Object[]> data() {
samples.put(
"select [{'a':'a'}, {'b':'b'}]::array(map(string, string))",
"[{\"a\":\"a\"}, {\"b\":\"b\"}]");
samples.put(
"select [{'a':true}, {'b':false}]::array(map(string, boolean))",
"[{\"a\":true}, {\"b\":false}]");
samples.put(
"select [{'string':'a'}, {'string':'b'}]::array(object(string varchar))",
"[{\"string\":\"a\"}, {\"string\":\"b\"}]");
Expand Down
Loading