-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SNOW-1374896 unify structured types string representation (#1882)
Co-authored-by: sfc-gh-astachowski <[email protected]> Build string representations of Snowflake structured types recursively to reuse existing converters designed for specific logical types (e.g. timestamps/binary) https://snowflakecomputing.atlassian.net/browse/SNOW-1374896
- Loading branch information
1 parent
9597576
commit 9e221ea
Showing
18 changed files
with
459 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...et/snowflake/client/core/arrow/tostringhelpers/ArrowArrayStringRepresentationBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package net.snowflake.client.core.arrow.tostringhelpers; | ||
|
||
import net.snowflake.client.core.SnowflakeJdbcInternalApi; | ||
import net.snowflake.client.jdbc.SnowflakeType; | ||
|
||
@SnowflakeJdbcInternalApi | ||
public class ArrowArrayStringRepresentationBuilder extends ArrowStringRepresentationBuilderBase { | ||
|
||
private final SnowflakeType valueType; | ||
|
||
public ArrowArrayStringRepresentationBuilder(SnowflakeType valueType) { | ||
super(",", "[", "]"); | ||
this.valueType = valueType; | ||
} | ||
|
||
public ArrowStringRepresentationBuilderBase appendValue(String value) { | ||
return add(quoteIfNeeded(value, valueType)); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...t/snowflake/client/core/arrow/tostringhelpers/ArrowObjectStringRepresentationBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package net.snowflake.client.core.arrow.tostringhelpers; | ||
|
||
import java.util.StringJoiner; | ||
import net.snowflake.client.core.SnowflakeJdbcInternalApi; | ||
import net.snowflake.client.jdbc.SnowflakeType; | ||
|
||
@SnowflakeJdbcInternalApi | ||
public class ArrowObjectStringRepresentationBuilder extends ArrowStringRepresentationBuilderBase { | ||
|
||
public ArrowObjectStringRepresentationBuilder() { | ||
super(",", "{", "}"); | ||
} | ||
|
||
public ArrowStringRepresentationBuilderBase appendKeyValue( | ||
String key, String value, SnowflakeType valueType) { | ||
StringJoiner joiner = new StringJoiner(": "); | ||
joiner.add('"' + key + '"'); | ||
joiner.add(quoteIfNeeded(value, valueType)); | ||
return add(joiner.toString()); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...net/snowflake/client/core/arrow/tostringhelpers/ArrowStringRepresentationBuilderBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package net.snowflake.client.core.arrow.tostringhelpers; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
import java.util.StringJoiner; | ||
import net.snowflake.client.core.SnowflakeJdbcInternalApi; | ||
import net.snowflake.client.jdbc.SnowflakeType; | ||
|
||
@SnowflakeJdbcInternalApi | ||
public abstract class ArrowStringRepresentationBuilderBase { | ||
private final StringJoiner joiner; | ||
private static final Set<SnowflakeType> quotableTypes; | ||
|
||
static { | ||
quotableTypes = new HashSet<>(); | ||
quotableTypes.add(SnowflakeType.ANY); | ||
quotableTypes.add(SnowflakeType.CHAR); | ||
quotableTypes.add(SnowflakeType.TEXT); | ||
quotableTypes.add(SnowflakeType.VARIANT); | ||
quotableTypes.add(SnowflakeType.BINARY); | ||
quotableTypes.add(SnowflakeType.DATE); | ||
quotableTypes.add(SnowflakeType.TIME); | ||
quotableTypes.add(SnowflakeType.TIMESTAMP_LTZ); | ||
quotableTypes.add(SnowflakeType.TIMESTAMP_NTZ); | ||
quotableTypes.add(SnowflakeType.TIMESTAMP_TZ); | ||
} | ||
|
||
public ArrowStringRepresentationBuilderBase(String delimiter, String prefix, String suffix) { | ||
joiner = new StringJoiner(delimiter, prefix, suffix); | ||
} | ||
|
||
protected ArrowStringRepresentationBuilderBase add(String string) { | ||
joiner.add(string); | ||
return this; | ||
} | ||
|
||
private boolean shouldQuoteValue(SnowflakeType type) { | ||
return quotableTypes.contains(type); | ||
} | ||
|
||
protected String quoteIfNeeded(String string, SnowflakeType type) { | ||
if (shouldQuoteValue(type)) { | ||
return '"' + string + '"'; | ||
} | ||
|
||
return string; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return joiner.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.