liuyongvs commented on code in PR #3238:
URL: https://github.com/apache/calcite/pull/3238#discussion_r1215554451
##########
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##########
@@ -3917,6 +3918,38 @@ public static List mapValues(Map map) {
return new ArrayList<>(map.values());
}
+ /** Support the MAP_FROM_ARRAYS function. */
+ public static Map mapFromArrays(List keysArray, List valuesArray) {
+ if (keysArray.size() != valuesArray.size()) {
+ throw new IllegalArgumentException(
+ "Invalid function MAP_FROM_ARRAYS call:\n"
+ + "The length of the keys array "
+ + keysArray.size()
+ + " is not equal to the length of the values array "
+ + valuesArray.size());
+ }
+ final Map map = new LinkedHashMap<>();
+ for (int i = 0; i < keysArray.size(); i++) {
+ map.put(keysArray.get(i), valuesArray.get(i));
+ }
+ return map;
+ }
+
+ /** Support the STR_TO_MAP function. */
+ public static Map strToMap(String string, String stringDelimiter, String
keyValueDelimiter) {
+ final Map map = new LinkedHashMap();
+ final String[] keyValues = string.split(stringDelimiter, -1);
Review Comment:
the limit should be -1, which aligns with spark.
what is the difference with limit -1, you can se here
https://stackabuse.com/how-to-split-a-string-in-java/
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]