cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

DatabricksSession broken for 15.1

TWib
New Contributor III

This code fails with exception:

[NOT_COLUMN_OR_STR] Argument `col` should be a Column or str, got Column.
File <command-4420517954891674>, line 7  4 spark = DatabricksSession.builder.getOrCreate()  6 df = spark.read.table("samples.nyctaxi.trips") ----> 7 df.select(lit(5).alias('height')).show()

 

 

from databricks.connect import DatabricksSession
from pyspark.sql.functions import lit 

spark = DatabricksSession.builder.getOrCreate()

df = spark.range(1)
df.select(lit(5).alias('height'), df.id).show()

 

 

 Can you confirm this is a bug?

7 REPLIES 7

Kaniz
Community Manager
Community Manager

Hi @TWib, The error message youโ€™re encounteringโ€”[NOT_COLUMN_OR_STR] Argument 'col' should be a Column or str, got Columnโ€”indicates that thereโ€™s an issue with the select operation in your code.

Letโ€™s break it down:

  1. The problem occurs in this line:

    df.select(lit(5).alias('height')).show()
    

    Youโ€™re trying to create a new column named โ€˜heightโ€™ with a constant value of 5 using the lit(5) function. However, the error suggests that the argument passed to select is not a valid column or string.

  2. The issue lies in the use of lit(5).alias('height'). The lit(5) creates a literal value (in this case, the integer 5), but itโ€™s not a valid column expression. The .alias('height') part is an attempt to rename the column, but itโ€™s not working as expected.

  3. To fix this, you can directly create a new column with a constant value using the lit function without the alias:

    df.withColumn('height', lit(5)).show()
    

    This will add a new column named โ€˜heightโ€™ with a value of 5 to all rows in your DataFrame.

If you encounter any other issues or need further assistance, feel free to ask! ๐Ÿ˜Š


 

 

TWib
New Contributor III

I am sorry but this is not helpfull. ChatGPT does not work well for PySpark code

Kaniz
Community Manager
Community Manager

Hi @TWib, References - 

  1. https://docs.databricks.com/en/error-messages/unresolved-column-error-class.html
  2. https://community.databricks.com/t5/data-engineering/nested-struct-type-not-supported-pyspark-error/...
  3. https://community.databricks.com/t5/data-engineering/getting-error-analysis-exception-olumn-is-there...

I apologize if my previous response didnโ€™t meet your expectations. If you have any other questions or need further assistance, feel free to ask. Have a great day! ๐Ÿ˜Š

MM3
New Contributor II

It's an official example from pyspark documentation:

https://spark.apache.org/docs/latest/api/python/reference/pyspark.sql/api/pyspark.sql.functions.lit....

It works on older runtime, it used to work one week ago. Please fix your internal databricks connect on latest runtimes.

TWib
New Contributor III

We dont understand the issue becauuse it suddently appeared but fixed it with migrating to 15.2.

Maybe databricks released some 15.1.XXXX update that broke stuff?

zerodarkzone
New Contributor III

Hi, I'm having the same problem using the 14.3LTS runtime.

The error just appeared yesterday. Before that, everything was working fine.

jcap
New Contributor II

We are also seeing this error in 14.3 LTS from a simple example:

from pyspark.sql.functions import col

df = spark.table('things')
things = df.select(col('thing_id')).collect()

[NOT_COLUMN_OR_STR] Argument `col` should be a Column or str, got Column.

 

 

Join 100K+ Data Experts: Register Now & Grow with Us!

Excited to expand your horizons with us? Click here to Register and begin your journey to success!

Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!