I'm a developer and happiest when I have code in front of me 👨💻. Databricks Tech Champion. Long term sufferer of imposter syndrome. Always looking to learn something new.
So that looks like you're after the value in the first column of the first row. If that's the case then you could use the following.
spark.sql("SELECT col1, col2 FROM table1 WHERE id=2").first()[0]
That will return the first row as a Row object which you can then access via index. You should find it works better as well as collect will pull all of the data to the driver before you attempt to access a single row
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
So that looks like you're after the value in the first column of the first row. If that's the case then you could use the following.
spark.sql("SELECT col1, col2 FROM table1 WHERE id=2").first()[0]
That will return the first row as a Row object which you can then access via index. You should find it works better as well as collect will pull all of the data to the driver before you attempt to access a single row