PySpark在创建包含现有列名的新列时读取多个文件

时间:2018-11-16 16:30:10

标签: apache-spark pyspark databricks

我想使用pyspark读取 n 个csv文件。 CSV具有相同的架构,但具有不同的列名。

enter image description here

在读取这些文件时,我想创建一个附加的“管道”列,其中包含第一列名称的子字符串。

我该如何实现?

 df = spark.read.format("csv") \
                .option("header", True) \
                .load(path + "*.csv")
                .withColumn("pipeline", 

1 个答案:

答案 0 :(得分:1)

const controller = async (req, res) => {
      const entity = new Entity();
      const validation = await entity.validate();
      console.log(validation)
  };
  
class Entity{
    constructor() {}
    async validate() {
      return "real function";
    }
}
// stub it
let stub = sinon.stub(Entity.prototype, 'validate')
stub.returns('stubbed function')

controller()