Daniel Davies created SPARK-39937: ------------------------------------- Summary: Substring Key: SPARK-39937 URL: https://issues.apache.org/jira/browse/SPARK-39937 Project: Spark Issue Type: New Feature Components: Spark Core Affects Versions: 3.2.2 Reporter: Daniel Davies
Hello, We hit a potential limitation of the substring function today that we think might be useful to contribute back to spark, relating to that fact that [substring |https://github.com/apache/spark/blob/775b5ced70c87d6a8709f44eb4a5de48c286a51d/sql/core/src/main/scala/org/apache/spark/sql/functions.scala#L2952] only takes integers for it's pos and len parameters. Consider the case where you have a list of ID's, and you need to find substrings in these IDs that are dependent on another column (for example, a column expressing the kind of product that the ID represents). e.g. {{Table:}} {{}} {{}} ID | Type +-----------+--------+ ABCD12345 | Water +-----------+--------+ ABCD12 | Soda +-----------+--------+ {{}} Desired: ID | Type +-----------+--------+ 12345 | Water +-----------+--------+ 12 | Soda +-----------+--------+ At the moment, you can only extract substrings of fixed position and length- but if IDs have a variable suffix, it may be desirable to run a substring of different lengths based on the 'Type' column. In this case, it's fairly straightforward to solve with a chain of .when statements; but if there are thousands of types, it may not be as easy. This seems fairly niche, but I'd be happy to give the implementation a go if this is something that the community would find useful/ has been seen before. -- This message was sent by Atlassian Jira (v8.20.10#820010) --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@spark.apache.org For additional commands, e-mail: issues-h...@spark.apache.org