mathijs-fish
Databricks Partner

@Ayushi_SutharThanks! However, this does not solve the issue; because we have to use shared clusters. In the meantime we found a way of detecting the encoding on shared clusters in the following way:

rawdata = (
        spark.read.format("binaryFile")
        .load(file_path)
        .selectExpr("SUBSTR(content, 0, 500000) AS content")
        .collect()[0]
        .content
    )
    encoding = chardet.detect(rawdata)["encoding"]
    print(encoding)

View solution in original post