Java 在Spark中向数据帧添加带字符串索引的运行编号?
新的火花。是否可以将索引列添加到现有数据集中,该数据集是字符串和运行编号的组合 现在我正在用单调递增的id函数创建一个动态索引Java 在Spark中向数据帧添加带字符串索引的运行编号?,java,apache-spark,apache-spark-sql,Java,Apache Spark,Apache Spark Sql,新的火花。是否可以将索引列添加到现有数据集中,该数据集是字符串和运行编号的组合 现在我正在用单调递增的id函数创建一个动态索引 List<Employee> columns = Arrays.asList(new Employee("john" ,"Lead"), new Employee("Doe" ,"Master")); dataset = dataset.withColumn("inde
List<Employee> columns = Arrays.asList(new Employee("john" ,"Lead"), new Employee("Doe" ,"Master"));
dataset = dataset.withColumn("index",monotonically_increasing_id());
dataset = dataset.select(col("index"),col("name"),col("desc"));
index|name| desc|
+-----+----+------+
| 0|john| Lead|
| 1| Doe|Master|
您可以使用
concat
在开头添加E
:
dataset = dataset.select(concat(lit("E"), col("index")).alias("index"),col("name"),col("desc"));
dataset = dataset.select(concat(lit("E"), col("index")).alias("index"),col("name"),col("desc"));