In my case, the installed Java was lower than required for version >=3.4.0. As stated in the docs:
Spark runs on Java 8/11/17, Scala 2.12/2.13, Python 3.7+, and R 3.5+. Python 3.7 support is deprecated as of Spark 3.4.0. Java 8 prior to version 8u362 support is deprecated as of Spark 3.4.0. [...]
After updating Java to 11, the error was gone with both pyspark 3.4.1 and 3.5.0.
In my case, the installed Java was lower than required for version >=3.4.0. As stated in the docs:
Spark runs on Java 8/11/17, Scala 2.12/2.13, Python 3.7+, and R 3.5+. Python 3.7 support is deprecated as of Spark 3.4.0. Java 8 prior to version 8u362 support is deprecated as of Spark 3.4.0. [...]
After updating Java to 11, the error was gone with both pyspark 3.4.1 and 3.5.0.
Looks like you might have inconsistencies with your Spark versions installed.
You have your Pyspark code that tries to call the legacyInferArrayTypeFromFirstElement method of the underlying SQLConf object, which has only been introduced since since v3.4.0.
But since your error is
py4j.Py4JException: Method legacyInferArrayTypeFromFirstElement([]) does not exist
I would think that your underlying Spark installation is not on version 3.4.0. This is of course dependent on how you have Spark installed so it's hard to say exactly. Try to verify which version your Pyspark is using (should be 3.4.0) and which version of Spark the executors start up with.
You need to wrap the conditions in parentheses:
when((col("salary") >= 400000) & (col("salary") <= 500000), lit("100"))
Otherwise your condition will be interpreted as below, due to operator precedence - & is higher than >=.
col("salary") >= (400000 & col("salary")) <= 500000
which does not make sense and gives the error you got.
For posterity, you can also get a similar error if you pass non-Column objects in the expression. For example:
column = 'A'
df.select(df[column] == 0) # this is fine
column = ['A'] # whoops, df[['A']] results in a DataFrame, not a Column
df.select(df[column] == 0) # py4j.Py4JException: Method col([class java.lang.Boolean]) does not exist