-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SNOW-1234214 Add support for maps in native arrow structured types
- Loading branch information
1 parent
baf98e9
commit 73c0f05
Showing
9 changed files
with
170 additions
and
81 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
31 changes: 31 additions & 0 deletions
31
src/main/java/net/snowflake/client/core/arrow/MapConverter.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,31 @@ | ||
package net.snowflake.client.core.arrow; | ||
|
||
import net.snowflake.client.core.DataConversionContext; | ||
import net.snowflake.client.core.SFException; | ||
import net.snowflake.client.jdbc.SnowflakeType; | ||
import org.apache.arrow.vector.complex.MapVector; | ||
import org.apache.arrow.vector.util.JsonStringHashMap; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class MapConverter extends AbstractArrowVectorConverter{ | ||
|
||
private final MapVector vector; | ||
|
||
public MapConverter(MapVector valueVector, int columnIndex, DataConversionContext context) { | ||
super(SnowflakeType.MAP.name(), valueVector, columnIndex, context); | ||
this.vector = valueVector; | ||
} | ||
|
||
@Override | ||
public Object toObject(int index) throws SFException { | ||
List<JsonStringHashMap<String, Object>> entriesList = (List<JsonStringHashMap<String, Object>>) vector.getObject(index); | ||
return entriesList.stream().collect(Collectors.toMap(entry-> entry.get("key").toString(), entry -> entry.get("value"))); | ||
} | ||
|
||
@Override | ||
public String toString(int index) throws SFException { | ||
return vector.getObject(index).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
Oops, something went wrong.