-
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.
- Loading branch information
Showing
12 changed files
with
224 additions
and
158 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
38 changes: 20 additions & 18 deletions
38
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 |
---|---|---|
@@ -1,31 +1,33 @@ | ||
package net.snowflake.client.core.arrow; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
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{ | ||
public class MapConverter extends AbstractArrowVectorConverter { | ||
|
||
private final MapVector vector; | ||
private final MapVector vector; | ||
|
||
public MapConverter(MapVector valueVector, int columnIndex, DataConversionContext context) { | ||
super(SnowflakeType.MAP.name(), valueVector, columnIndex, context); | ||
this.vector = valueVector; | ||
} | ||
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 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(); | ||
} | ||
@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
Oops, something went wrong.